Skip to content

Commit 86d2acc

Browse files
committed
perf: prevent unmounting MessageBubble when STR happens
1 parent 77c7c95 commit 86d2acc

File tree

1 file changed

+21
-38
lines changed

1 file changed

+21
-38
lines changed

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

Lines changed: 21 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { StyleSheet, View } from 'react-native';
33
import { Gesture, GestureDetector } from 'react-native-gesture-handler';
44

55
import Animated, {
6-
Extrapolation,
76
interpolate,
87
runOnJS,
98
useAnimatedStyle,
@@ -138,7 +137,7 @@ export const SwipableMessageBubble = React.memo(
138137
.onStart(() => {
139138
translateX.value = 0;
140139
})
141-
.onChange(({ translationX }) => {
140+
.onUpdate(({ translationX }) => {
142141
if (translationX > 0) {
143142
translateX.value = translationX;
144143
}
@@ -177,51 +176,32 @@ export const SwipableMessageBubble = React.memo(
177176
],
178177
);
179178

180-
const messageBubbleAnimatedStyle = useAnimatedStyle(
181-
() => ({
182-
transform: [{ translateX: translateX.value }],
183-
}),
184-
[],
185-
);
186-
187179
const swipeContentAnimatedStyle = useAnimatedStyle(
188180
() => ({
189181
opacity: interpolate(translateX.value, [0, SWIPABLE_THRESHOLD], [0, 1]),
190-
transform: [
191-
{
192-
translateX: interpolate(
193-
translateX.value,
194-
[0, SWIPABLE_THRESHOLD],
195-
[-SWIPABLE_THRESHOLD, 0],
196-
Extrapolation.CLAMP,
197-
),
198-
},
199-
],
182+
width: translateX.value,
200183
}),
201184
[],
202185
);
203186

204187
return (
205188
<GestureDetector gesture={swipeGesture}>
206-
<View hitSlop={messageSwipeToReplyHitSlop} style={[styles.contentWrapper, contentWrapper]}>
189+
<View
190+
hitSlop={messageSwipeToReplyHitSlop}
191+
style={[styles.contentWrapper, contentWrapper, { width: props.messageContentWidth }]}
192+
>
207193
{shouldRenderAnimatedWrapper ? (
208-
<>
209-
<AnimatedWrapper
210-
style={[
211-
styles.swipeContentContainer,
212-
swipeContentAnimatedStyle,
213-
swipeContentContainer,
214-
]}
215-
>
216-
{MessageSwipeContent ? <MessageSwipeContent /> : null}
217-
</AnimatedWrapper>
218-
<AnimatedWrapper pointerEvents='box-none' style={messageBubbleAnimatedStyle}>
219-
<MessageBubble {...messageBubbleProps} />
220-
</AnimatedWrapper>
221-
</>
222-
) : (
223-
<MessageBubble {...messageBubbleProps} />
224-
)}
194+
<AnimatedWrapper
195+
style={[
196+
styles.swipeContentContainer,
197+
swipeContentAnimatedStyle,
198+
swipeContentContainer,
199+
]}
200+
>
201+
{MessageSwipeContent ? <MessageSwipeContent /> : null}
202+
</AnimatedWrapper>
203+
) : null}
204+
<MessageBubble {...messageBubbleProps} />
225205
</View>
226206
</GestureDetector>
227207
);
@@ -232,8 +212,11 @@ const styles = StyleSheet.create({
232212
contentWrapper: {
233213
alignItems: 'center',
234214
flexDirection: 'row',
215+
width: 200,
235216
},
236217
swipeContentContainer: {
237-
position: 'absolute',
218+
flexShrink: 0,
219+
overflow: 'hidden',
220+
position: 'relative',
238221
},
239222
});

0 commit comments

Comments
 (0)