Skip to content

Commit ac0d92e

Browse files
committed
fix: freeze message once teleported
1 parent e405be9 commit ac0d92e

File tree

3 files changed

+23
-16
lines changed

3 files changed

+23
-16
lines changed

package/src/components/Message/Message.tsx

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,11 @@ const MessageWithContext = (props: MessagePropsWithContext) => {
684684
showMessageOverlay();
685685
};
686686

687+
const frozenMessage = useRef(message);
688+
const { state, id, closing } = useOverlayController();
689+
690+
const active = id === message.id;
691+
687692
const messageContext = useCreateMessageContext({
688693
actionsEnabled,
689694
alignment,
@@ -703,7 +708,7 @@ const MessageWithContext = (props: MessagePropsWithContext) => {
703708
isMyMessage,
704709
lastGroupMessage: groupStyles?.[0] === 'single' || groupStyles?.[0] === 'bottom',
705710
members,
706-
message,
711+
message: active ? frozenMessage.current : message,
707712
messageContentOrder,
708713
myMessageTheme: messagesContext.myMessageTheme,
709714
onLongPress: (payload) => {
@@ -779,16 +784,21 @@ const MessageWithContext = (props: MessagePropsWithContext) => {
779784
videos: attachments.videos,
780785
});
781786

782-
const { state, id, closing } = useOverlayController();
783-
784-
const active = id === message.id;
787+
const prevActive = useRef<boolean>(active);
785788

786789
useEffect(() => {
787-
if (!active && setNativeScrollability) {
790+
if (!active && prevActive.current && setNativeScrollability) {
788791
setNativeScrollability(true);
789792
}
793+
prevActive.current = active;
790794
}, [setNativeScrollability, active]);
791795

796+
useEffect(() => {
797+
if (!active) {
798+
frozenMessage.current = message;
799+
}
800+
}, [active, message]);
801+
792802
if (!(isMessageTypeDeleted || messageContentOrder.length)) {
793803
return null;
794804
}

package/src/components/Message/MessageSimple/MessageSimple.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { Dimensions, LayoutChangeEvent, StyleSheet, View } from 'react-native';
33

44
import { MessageBubble, SwipableMessageBubble } from './MessageBubble';
55

6-
import { updateOverlayState } from '../../../contexts';
76
import {
87
MessageContextValue,
98
useMessageContext,
@@ -203,6 +202,7 @@ const MessageSimpleWithContext = forwardRef<View, MessageSimplePropsWithContext>
203202
return (
204203
<View ref={ref}>
205204
<View
205+
pointerEvents='box-none'
206206
style={[
207207
styles.container,
208208
messageGroupedSingleOrBottom

package/src/contexts/overlayContext/OverlayProvider.tsx

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ import { BackHandler, Pressable, StyleSheet, useWindowDimensions } from 'react-n
55
import Animated, {
66
cancelAnimation,
77
clamp,
8-
Easing,
9-
FadeIn,
10-
FadeOut,
118
runOnJS,
129
useAnimatedReaction,
1310
useAnimatedStyle,
@@ -244,7 +241,7 @@ const OverlayHostLayer = () => {
244241

245242
const solvedTop = clamp(anchorY, minTop, maxTop);
246243
return solvedTop - anchorY;
247-
});
244+
}, [rect]);
248245

249246
const hostStyle = useAnimatedStyle(() => {
250247
const target = isActive ? (closing ? 0 : shiftY.value) : 0;
@@ -280,6 +277,9 @@ const OverlayHostLayer = () => {
280277
{
281278
translateY: withTiming(target, { duration: 150 }),
282279
},
280+
{
281+
scale: backdrop.value,
282+
},
283283
],
284284
};
285285
});
@@ -303,6 +303,9 @@ const OverlayHostLayer = () => {
303303
{
304304
translateY: withTiming(target, { duration: 150 }),
305305
},
306+
{
307+
scale: backdrop.value,
308+
},
306309
],
307310
};
308311
});
@@ -321,8 +324,6 @@ const OverlayHostLayer = () => {
321324
) : null}
322325

323326
<Animated.View
324-
entering={FadeIn.duration(ANIMATED_DURATION).easing(Easing.in(Easing.cubic))}
325-
exiting={FadeOut.duration(ANIMATED_DURATION).easing(Easing.out(Easing.cubic))}
326327
style={[
327328
isActive && rect
328329
? {
@@ -354,8 +355,6 @@ const OverlayHostLayer = () => {
354355
<PortalHost name='message-overlay' style={StyleSheet.absoluteFillObject} />
355356
</Animated.View>
356357
<Animated.View
357-
entering={FadeIn.duration(ANIMATED_DURATION).easing(Easing.in(Easing.cubic))}
358-
exiting={FadeOut.duration(ANIMATED_DURATION).easing(Easing.out(Easing.cubic))}
359358
style={[
360359
isActive && rect
361360
? {
@@ -374,5 +373,3 @@ const OverlayHostLayer = () => {
374373
};
375374

376375
type Rect = { x: number; y: number; w: number; h: number } | undefined;
377-
378-
const ANIMATED_DURATION = 150;

0 commit comments

Comments
 (0)