Skip to content

Commit ba4bff0

Browse files
authored
fix: try to fit message as far as possible (#3466)
## 🎯 Goal This PR fixes an edge case where the teleported message would not properly try to fit as much as it can within the screen if the total sum of the top item height, its own height and the bottom item height would be greater than the screen height. With this, we'll always try to animate the message as far as we can and clamp the animation to its boundaries. The bottom item will still overlap any excess height as it was before. ## 🛠 Implementation details <!-- Provide a description of the implementation --> ## 🎨 UI Changes <!-- Add relevant screenshots --> <details> <summary>iOS</summary> <table> <thead> <tr> <td>Before</td> <td>After</td> </tr> </thead> <tbody> <tr> <td> <!--<img src="" /> --> </td> <td> <!--<img src="" /> --> </td> </tr> </tbody> </table> </details> <details> <summary>Android</summary> <table> <thead> <tr> <td>Before</td> <td>After</td> </tr> </thead> <tbody> <tr> <td> <!--<img src="" /> --> </td> <td> <!--<img src="" /> --> </td> </tr> </tbody> </table> </details> ## 🧪 Testing <!-- Explain how this change can be tested (or why it can't be tested) --> ## ☑️ Checklist - [ ] I have signed the [Stream CLA](https://docs.google.com/forms/d/e/1FAIpQLScFKsKkAJI7mhCr7K9rEIOpqIDThrWxuvxnwUq2XkHyG154vQ/viewform) (required) - [ ] PR targets the `develop` branch - [ ] Documentation is updated - [ ] New code is tested in main example apps, including all possible scenarios - [ ] SampleApp iOS and Android - [ ] Expo iOS and Android
1 parent 77d66cf commit ba4bff0

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

package/src/contexts/overlayContext/MessageOverlayHostLayer.tsx

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,10 @@ export const MessageOverlayHostLayer = ({ BackgroundComponent }: MessageOverlayH
125125
const msgH = messageH.value.h;
126126
const minTop = minY + topH.value.h;
127127
const maxTopWithBottom = maxY - (msgH + bottomH.value.h);
128-
const maxTopWithoutBottom = maxY - msgH;
129-
const maxTop = minTop <= maxTopWithBottom ? maxTopWithBottom : maxTopWithoutBottom;
130-
const solvedTop = clamp(anchorY, minTop, Math.max(minTop, maxTop));
128+
const canFitBottomWithoutOverlap = minTop <= maxTopWithBottom;
129+
const solvedTop = canFitBottomWithoutOverlap
130+
? clamp(anchorY, minTop, Math.max(minTop, maxTopWithBottom))
131+
: minTop;
131132

132133
return solvedTop - anchorY;
133134
});
@@ -139,16 +140,10 @@ export const MessageOverlayHostLayer = ({ BackgroundComponent }: MessageOverlayH
139140
const msgH = messageH.value.h;
140141
const minMessageTop = minY + topH.value.h;
141142
const maxMessageTopWithBottom = maxY - (msgH + bottomH.value.h);
142-
const maxMessageTopWithoutBottom = maxY - msgH;
143-
const maxMessageTop =
144-
minMessageTop <= maxMessageTopWithBottom
145-
? maxMessageTopWithBottom
146-
: maxMessageTopWithoutBottom;
147-
const solvedMessageTop = clamp(
148-
anchorMessageTop,
149-
minMessageTop,
150-
Math.max(minMessageTop, maxMessageTop),
151-
);
143+
const canFitBottomWithoutOverlap = minMessageTop <= maxMessageTopWithBottom;
144+
const solvedMessageTop = canFitBottomWithoutOverlap
145+
? clamp(anchorMessageTop, minMessageTop, Math.max(minMessageTop, maxMessageTopWithBottom))
146+
: minMessageTop;
152147

153148
const solvedBottomTop = Math.min(solvedMessageTop + msgH, maxY - bottomH.value.h);
154149
return solvedBottomTop - bottomH.value.y;

0 commit comments

Comments
 (0)