Skip to content

Commit 0a5bd54

Browse files
committed
fix: remounting specific attachments and jittery fast animations (#3086)
1 parent 274a822 commit 0a5bd54

File tree

2 files changed

+23
-33
lines changed

2 files changed

+23
-33
lines changed

package/src/components/Attachment/FileAttachmentGroup.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect, useState } from 'react';
1+
import React, { useState } from 'react';
22
import { StyleProp, StyleSheet, View, ViewStyle } from 'react-native';
33

44
import type { Attachment } from 'stream-chat';
@@ -47,13 +47,9 @@ const FileAttachmentGroupWithContext = <
4747
props: FileAttachmentGroupPropsWithContext<StreamChatGenerics>,
4848
) => {
4949
const { Attachment, AudioAttachment, files, messageId, styles: stylesProp = {} } = props;
50-
const [filesToDisplay, setFilesToDisplay] = useState<FilesToDisplayType[]>([]);
51-
52-
useEffect(() => {
53-
setFilesToDisplay(
54-
files.map((file) => ({ ...file, duration: file.duration || 0, paused: true, progress: 0 })),
55-
);
56-
}, [files]);
50+
const [filesToDisplay, setFilesToDisplay] = useState<FilesToDisplayType[]>(() =>
51+
files.map((file) => ({ ...file, duration: file.duration || 0, paused: true, progress: 0 })),
52+
);
5753

5854
// Handler triggered when an audio is loaded in the message input. The initial state is defined for the audio here and the duration is set.
5955
const onLoad = (index: string, duration: number) => {

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

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ const MessageSimpleWithContext = <
239239
if (isHorizontalPanning) {
240240
state.activate();
241241
isSwiping.value = true;
242-
runOnJS(setIsBeingSwiped)(true);
242+
runOnJS(setIsBeingSwiped)(isSwiping.value);
243243
} else {
244244
state.fail();
245245
}
@@ -259,6 +259,7 @@ const MessageSimpleWithContext = <
259259
runOnJS(triggerHaptic)('impactMedium');
260260
}
261261
}
262+
isSwiping.value = false;
262263
translateX.value = withSpring(
263264
0,
264265
{
@@ -268,41 +269,34 @@ const MessageSimpleWithContext = <
268269
stiffness: 1,
269270
},
270271
() => {
271-
isSwiping.value = false;
272-
runOnJS(setIsBeingSwiped)(false);
272+
runOnJS(setIsBeingSwiped)(isSwiping.value);
273273
},
274274
);
275275
}),
276276
[isSwiping, messageSwipeToReplyHitSlop, onSwipeToReply, touchStart, translateX, triggerHaptic],
277277
);
278278

279279
const messageBubbleAnimatedStyle = useAnimatedStyle(
280-
() =>
281-
isSwiping.value
282-
? {
283-
transform: [{ translateX: translateX.value }],
284-
}
285-
: {},
280+
() => ({
281+
transform: [{ translateX: translateX.value }],
282+
}),
286283
[],
287284
);
288285

289286
const swipeContentAnimatedStyle = useAnimatedStyle(
290-
() =>
291-
isSwiping.value
292-
? {
293-
opacity: interpolate(translateX.value, [0, THRESHOLD], [0, 1]),
294-
transform: [
295-
{
296-
translateX: interpolate(
297-
translateX.value,
298-
[0, THRESHOLD],
299-
[-THRESHOLD, 0],
300-
Extrapolation.CLAMP,
301-
),
302-
},
303-
],
304-
}
305-
: {},
287+
() => ({
288+
opacity: interpolate(translateX.value, [0, THRESHOLD], [0, 1]),
289+
transform: [
290+
{
291+
translateX: interpolate(
292+
translateX.value,
293+
[0, THRESHOLD],
294+
[-THRESHOLD, 0],
295+
Extrapolation.CLAMP,
296+
),
297+
},
298+
],
299+
}),
306300
[],
307301
);
308302

0 commit comments

Comments
 (0)