Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions package/src/components/Attachment/FileAttachmentGroup.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from 'react';
import React, { useState } from 'react';
import { StyleProp, StyleSheet, View, ViewStyle } from 'react-native';

import type { Attachment } from 'stream-chat';
Expand Down Expand Up @@ -39,13 +39,9 @@ type FilesToDisplayType = Attachment & {

const FileAttachmentGroupWithContext = (props: FileAttachmentGroupPropsWithContext) => {
const { Attachment, AudioAttachment, files, messageId, styles: stylesProp = {} } = props;
const [filesToDisplay, setFilesToDisplay] = useState<FilesToDisplayType[]>([]);

useEffect(() => {
setFilesToDisplay(
files.map((file) => ({ ...file, duration: file.duration || 0, paused: true, progress: 0 })),
);
}, [files]);
const [filesToDisplay, setFilesToDisplay] = useState<FilesToDisplayType[]>(() =>
files.map((file) => ({ ...file, duration: file.duration || 0, paused: true, progress: 0 })),
);

// 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.
const onLoad = (index: string, duration: number) => {
Expand Down
44 changes: 19 additions & 25 deletions package/src/components/Message/MessageSimple/MessageSimple.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ const MessageSimpleWithContext = (props: MessageSimplePropsWithContext) => {
if (isHorizontalPanning) {
state.activate();
isSwiping.value = true;
runOnJS(setIsBeingSwiped)(true);
runOnJS(setIsBeingSwiped)(isSwiping.value);
} else {
state.fail();
}
Expand All @@ -253,6 +253,7 @@ const MessageSimpleWithContext = (props: MessageSimplePropsWithContext) => {
runOnJS(triggerHaptic)('impactMedium');
}
}
isSwiping.value = false;
translateX.value = withSpring(
0,
{
Expand All @@ -262,41 +263,34 @@ const MessageSimpleWithContext = (props: MessageSimplePropsWithContext) => {
stiffness: 1,
},
() => {
isSwiping.value = false;
runOnJS(setIsBeingSwiped)(false);
runOnJS(setIsBeingSwiped)(isSwiping.value);
},
);
}),
[isSwiping, messageSwipeToReplyHitSlop, onSwipeToReply, touchStart, translateX, triggerHaptic],
);

const messageBubbleAnimatedStyle = useAnimatedStyle(
() =>
isSwiping.value
? {
transform: [{ translateX: translateX.value }],
}
: {},
() => ({
transform: [{ translateX: translateX.value }],
}),
[],
);

const swipeContentAnimatedStyle = useAnimatedStyle(
() =>
isSwiping.value
? {
opacity: interpolate(translateX.value, [0, THRESHOLD], [0, 1]),
transform: [
{
translateX: interpolate(
translateX.value,
[0, THRESHOLD],
[-THRESHOLD, 0],
Extrapolation.CLAMP,
),
},
],
}
: {},
() => ({
opacity: interpolate(translateX.value, [0, THRESHOLD], [0, 1]),
transform: [
{
translateX: interpolate(
translateX.value,
[0, THRESHOLD],
[-THRESHOLD, 0],
Extrapolation.CLAMP,
),
},
],
}),
[],
);

Expand Down