Skip to content

Commit 857fb68

Browse files
authored
fix: remounting specific attachments and jittery fast animations (#3086)
1 parent cb7d71a commit 857fb68

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';
@@ -39,13 +39,9 @@ type FilesToDisplayType = Attachment & {
3939

4040
const FileAttachmentGroupWithContext = (props: FileAttachmentGroupPropsWithContext) => {
4141
const { Attachment, AudioAttachment, files, messageId, styles: stylesProp = {} } = props;
42-
const [filesToDisplay, setFilesToDisplay] = useState<FilesToDisplayType[]>([]);
43-
44-
useEffect(() => {
45-
setFilesToDisplay(
46-
files.map((file) => ({ ...file, duration: file.duration || 0, paused: true, progress: 0 })),
47-
);
48-
}, [files]);
42+
const [filesToDisplay, setFilesToDisplay] = useState<FilesToDisplayType[]>(() =>
43+
files.map((file) => ({ ...file, duration: file.duration || 0, paused: true, progress: 0 })),
44+
);
4945

5046
// 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.
5147
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
@@ -233,7 +233,7 @@ const MessageSimpleWithContext = (props: MessageSimplePropsWithContext) => {
233233
if (isHorizontalPanning) {
234234
state.activate();
235235
isSwiping.value = true;
236-
runOnJS(setIsBeingSwiped)(true);
236+
runOnJS(setIsBeingSwiped)(isSwiping.value);
237237
} else {
238238
state.fail();
239239
}
@@ -253,6 +253,7 @@ const MessageSimpleWithContext = (props: MessageSimplePropsWithContext) => {
253253
runOnJS(triggerHaptic)('impactMedium');
254254
}
255255
}
256+
isSwiping.value = false;
256257
translateX.value = withSpring(
257258
0,
258259
{
@@ -262,41 +263,34 @@ const MessageSimpleWithContext = (props: MessageSimplePropsWithContext) => {
262263
stiffness: 1,
263264
},
264265
() => {
265-
isSwiping.value = false;
266-
runOnJS(setIsBeingSwiped)(false);
266+
runOnJS(setIsBeingSwiped)(isSwiping.value);
267267
},
268268
);
269269
}),
270270
[isSwiping, messageSwipeToReplyHitSlop, onSwipeToReply, touchStart, translateX, triggerHaptic],
271271
);
272272

273273
const messageBubbleAnimatedStyle = useAnimatedStyle(
274-
() =>
275-
isSwiping.value
276-
? {
277-
transform: [{ translateX: translateX.value }],
278-
}
279-
: {},
274+
() => ({
275+
transform: [{ translateX: translateX.value }],
276+
}),
280277
[],
281278
);
282279

283280
const swipeContentAnimatedStyle = useAnimatedStyle(
284-
() =>
285-
isSwiping.value
286-
? {
287-
opacity: interpolate(translateX.value, [0, THRESHOLD], [0, 1]),
288-
transform: [
289-
{
290-
translateX: interpolate(
291-
translateX.value,
292-
[0, THRESHOLD],
293-
[-THRESHOLD, 0],
294-
Extrapolation.CLAMP,
295-
),
296-
},
297-
],
298-
}
299-
: {},
281+
() => ({
282+
opacity: interpolate(translateX.value, [0, THRESHOLD], [0, 1]),
283+
transform: [
284+
{
285+
translateX: interpolate(
286+
translateX.value,
287+
[0, THRESHOLD],
288+
[-THRESHOLD, 0],
289+
Extrapolation.CLAMP,
290+
),
291+
},
292+
],
293+
}),
300294
[],
301295
);
302296

0 commit comments

Comments
 (0)