Skip to content

Commit a767e07

Browse files
committed
chore: resolve conflicts from V8
2 parents 76f0ed2 + 3893076 commit a767e07

4 files changed

Lines changed: 76 additions & 37 deletions

File tree

package/src/components/Attachment/FileAttachmentGroup.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +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[]>([]);
42+
const [filesToDisplay, setFilesToDisplay] = useState<FilesToDisplayType[]>(() =>
43+
files.map((file) => ({ ...file, duration: file.duration || 0, paused: true, progress: 0 })),
44+
);
4345

4446
useEffect(() => {
4547
setFilesToDisplay(

package/src/components/ChannelList/hooks/usePaginatedChannels.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ export const usePaginatedChannels = ({
282282
// ready. I do not like providing a way to set the ready state, as it should be managed
283283
// in the LLC entirely. Once we move offline support to the LLC, we can remove this check
284284
// too as it'll be redundant.
285-
pagination?.isLoading || (!channelListInitialized && channels.length === 0),
285+
pagination?.isLoading || (!channelListInitialized && channels.length === 0 && !error),
286286
loadingNextPage: pagination?.isLoadingNext,
287287
loadNextPage: channelManager.loadNext,
288288
refreshing: activeQueryType === 'refresh',

package/src/components/Message/Message.tsx

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,12 @@ export type MessagePropsWithContext = Pick<
135135
> &
136136
Pick<KeyboardContextValue, 'dismissKeyboard'> &
137137
Partial<
138-
Omit<MessageContextValue, 'groupStyles' | 'handleReaction' | 'message' | 'isMessageAIGenerated'>
138+
Omit<
139+
MessageContextValue,
140+
'groupStyles' | 'handleReaction' | 'message' | 'isMessageAIGenerated' | 'readBy'
141+
>
139142
> &
140-
Pick<MessageContextValue, 'groupStyles' | 'message' | 'isMessageAIGenerated'> &
143+
Pick<MessageContextValue, 'groupStyles' | 'message' | 'isMessageAIGenerated' | 'readBy'> &
141144
Pick<
142145
MessagesContextValue,
143146
| 'sendReaction'
@@ -260,8 +263,8 @@ const MessageWithContext = (props: MessagePropsWithContext) => {
260263
t,
261264
threadList = false,
262265
updateMessage,
266+
readBy,
263267
} = props;
264-
const { read } = useChannelContext();
265268
const isMessageAIGenerated = messagesContext.isMessageAIGenerated;
266269
const isAIGenerated = useMemo(
267270
() => isMessageAIGenerated(message),
@@ -276,7 +279,6 @@ const MessageWithContext = (props: MessagePropsWithContext) => {
276279
screenPadding,
277280
},
278281
} = useTheme();
279-
const readBy = useMemo(() => getReadState(message, read), [message, read]);
280282

281283
const showMessageOverlay = async (showMessageReactions = false, selectedReaction?: string) => {
282284
await dismissKeyboard();
@@ -755,6 +757,7 @@ const areEqual = (prevProps: MessagePropsWithContext, nextProps: MessagePropsWit
755757
message: prevMessage,
756758
messagesContext: prevMessagesContext,
757759
showUnreadUnderlay: prevShowUnreadUnderlay,
760+
readBy: prevReadBy,
758761
t: prevT,
759762
} = prevProps;
760763
const {
@@ -767,9 +770,15 @@ const areEqual = (prevProps: MessagePropsWithContext, nextProps: MessagePropsWit
767770
message: nextMessage,
768771
messagesContext: nextMessagesContext,
769772
showUnreadUnderlay: nextShowUnreadUnderlay,
773+
readBy: nextReadBy,
770774
t: nextT,
771775
} = nextProps;
772776

777+
const readByEqual = prevReadBy === nextReadBy;
778+
if (!readByEqual) {
779+
return false;
780+
}
781+
773782
const membersEqual = Object.keys(prevMembers).length === Object.keys(nextMembers).length;
774783
if (!membersEqual) {
775784
return false;
@@ -921,12 +930,14 @@ export type MessageProps = Partial<
921930
* @example ./Message.md
922931
*/
923932
export const Message = (props: MessageProps) => {
924-
const { channel, enforceUniqueReaction, members } = useChannelContext();
933+
const { message } = props;
934+
const { channel, enforceUniqueReaction, members, read } = useChannelContext();
925935
const chatContext = useChatContext();
926936
const { dismissKeyboard } = useKeyboardContext();
927937
const messagesContext = useMessagesContext();
928938
const { openThread } = useThreadContext();
929939
const { t } = useTranslationContext();
940+
const readBy = useMemo(() => getReadState(message, read), [message, read]);
930941

931942
return (
932943
<MemoizedMessage
@@ -939,6 +950,7 @@ export const Message = (props: MessageProps) => {
939950
members,
940951
messagesContext,
941952
openThread,
953+
readBy,
942954
t,
943955
}}
944956
{...props}

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

Lines changed: 55 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,16 @@ export type MessageSimplePropsWithContext = Pick<
8989
| 'ReactionListBottom'
9090
| 'reactionListPosition'
9191
| 'ReactionListTop'
92-
>;
92+
> & {
93+
/**
94+
* Will determine whether the swipeable wrapper is always rendered for each
95+
* message. If set to false, the animated wrapper will be rendered only when
96+
* a swiping gesture is active and not otherwise.
97+
* Since stateful components would lose their state if we remount them while
98+
* an animation is happening, this should always be set to true in those instances.
99+
*/
100+
shouldRenderSwipeableWrapper: boolean;
101+
};
93102

94103
const MessageSimpleWithContext = (props: MessageSimplePropsWithContext) => {
95104
const [messageContentWidth, setMessageContentWidth] = useState(0);
@@ -120,6 +129,7 @@ const MessageSimpleWithContext = (props: MessageSimplePropsWithContext) => {
120129
reactionListPosition,
121130
ReactionListTop,
122131
showMessageStatus,
132+
shouldRenderSwipeableWrapper,
123133
} = props;
124134

125135
const {
@@ -200,7 +210,9 @@ const MessageSimpleWithContext = (props: MessageSimplePropsWithContext) => {
200210
const translateX = useSharedValue(0);
201211
const touchStart = useSharedValue<{ x: number; y: number } | null>(null);
202212
const isSwiping = useSharedValue<boolean>(false);
203-
const [isBeingSwiped, setIsBeingSwiped] = useState<boolean>(false);
213+
const [shouldRenderAnimatedWrapper, setShouldRenderAnimatedWrapper] = useState<boolean>(
214+
shouldRenderSwipeableWrapper,
215+
);
204216

205217
const onSwipeToReply = useCallback(() => {
206218
messageComposer.setQuotedMessage(message);
@@ -230,7 +242,9 @@ const MessageSimpleWithContext = (props: MessageSimplePropsWithContext) => {
230242
if (isHorizontalPanning) {
231243
state.activate();
232244
isSwiping.value = true;
233-
runOnJS(setIsBeingSwiped)(true);
245+
if (!shouldRenderSwipeableWrapper) {
246+
runOnJS(setShouldRenderAnimatedWrapper)(isSwiping.value);
247+
}
234248
} else {
235249
state.fail();
236250
}
@@ -250,6 +264,7 @@ const MessageSimpleWithContext = (props: MessageSimplePropsWithContext) => {
250264
runOnJS(triggerHaptic)('impactMedium');
251265
}
252266
}
267+
isSwiping.value = false;
253268
translateX.value = withSpring(
254269
0,
255270
{
@@ -259,41 +274,44 @@ const MessageSimpleWithContext = (props: MessageSimplePropsWithContext) => {
259274
stiffness: 1,
260275
},
261276
() => {
262-
isSwiping.value = false;
263-
runOnJS(setIsBeingSwiped)(false);
277+
if (!shouldRenderSwipeableWrapper) {
278+
runOnJS(setShouldRenderAnimatedWrapper)(isSwiping.value);
279+
}
264280
},
265281
);
266282
}),
267-
[isSwiping, messageSwipeToReplyHitSlop, onSwipeToReply, touchStart, translateX, triggerHaptic],
283+
[
284+
isSwiping,
285+
messageSwipeToReplyHitSlop,
286+
onSwipeToReply,
287+
touchStart,
288+
translateX,
289+
triggerHaptic,
290+
shouldRenderSwipeableWrapper,
291+
],
268292
);
269293

270294
const messageBubbleAnimatedStyle = useAnimatedStyle(
271-
() =>
272-
isSwiping.value
273-
? {
274-
transform: [{ translateX: translateX.value }],
275-
}
276-
: {},
295+
() => ({
296+
transform: [{ translateX: translateX.value }],
297+
}),
277298
[],
278299
);
279300

280301
const swipeContentAnimatedStyle = useAnimatedStyle(
281-
() =>
282-
isSwiping.value
283-
? {
284-
opacity: interpolate(translateX.value, [0, THRESHOLD], [0, 1]),
285-
transform: [
286-
{
287-
translateX: interpolate(
288-
translateX.value,
289-
[0, THRESHOLD],
290-
[-THRESHOLD, 0],
291-
Extrapolation.CLAMP,
292-
),
293-
},
294-
],
295-
}
296-
: {},
302+
() => ({
303+
opacity: interpolate(translateX.value, [0, THRESHOLD], [0, 1]),
304+
transform: [
305+
{
306+
translateX: interpolate(
307+
translateX.value,
308+
[0, THRESHOLD],
309+
[-THRESHOLD, 0],
310+
Extrapolation.CLAMP,
311+
),
312+
},
313+
],
314+
}),
297315
[],
298316
);
299317

@@ -329,7 +347,7 @@ const MessageSimpleWithContext = (props: MessageSimplePropsWithContext) => {
329347
() => (
330348
<GestureDetector gesture={swipeGesture}>
331349
<View hitSlop={messageSwipeToReplyHitSlop} style={[styles.contentWrapper, contentWrapper]}>
332-
{isBeingSwiped ? (
350+
{shouldRenderAnimatedWrapper ? (
333351
<>
334352
<AnimatedWrapper
335353
style={[
@@ -353,7 +371,7 @@ const MessageSimpleWithContext = (props: MessageSimplePropsWithContext) => {
353371
[
354372
MessageSwipeContent,
355373
contentWrapper,
356-
isBeingSwiped,
374+
shouldRenderAnimatedWrapper,
357375
messageBubbleAnimatedStyle,
358376
messageSwipeToReplyHitSlop,
359377
renderMessageBubble,
@@ -589,6 +607,7 @@ export const MessageSimple = (props: MessageSimpleProps) => {
589607
onlyEmojis,
590608
otherAttachments,
591609
showMessageStatus,
610+
isMessageAIGenerated,
592611
} = useMessageContext();
593612
const {
594613
enableMessageGroupingByUser,
@@ -608,6 +627,11 @@ export const MessageSimple = (props: MessageSimpleProps) => {
608627
reactionListPosition,
609628
ReactionListTop,
610629
} = useMessagesContext();
630+
const isAIGenerated = useMemo(
631+
() => isMessageAIGenerated(message),
632+
[message, isMessageAIGenerated],
633+
);
634+
const shouldRenderSwipeableWrapper = (message?.attachments || []).length > 0 || isAIGenerated;
611635

612636
return (
613637
<MemoizedMessageSimple
@@ -638,6 +662,7 @@ export const MessageSimple = (props: MessageSimpleProps) => {
638662
ReactionListBottom,
639663
reactionListPosition,
640664
ReactionListTop,
665+
shouldRenderSwipeableWrapper,
641666
showMessageStatus,
642667
}}
643668
{...props}

0 commit comments

Comments
 (0)