Skip to content

Commit

Permalink
fix: scroll view when message height changed with suggested replies (#…
Browse files Browse the repository at this point in the history
…1087)

- Fix scroll bottom not working properly when last message is updated
with suggested replies

ticket: [AC-2222]
  • Loading branch information
bang9 authored May 4, 2024
1 parent d3eadd5 commit b5f91d5
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/modules/GroupChannel/components/Message/MessageView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -196,18 +196,26 @@ const MessageView = (props: MessageViewProps) => {
);
}, [mentionedUserIds]);

/**
* Move the message list scroll
* when the message's height is changed by `showEdit` OR `message.reactions`
*/
// Side effect: scroll position update when showEdit is toggled or reactions updated
useDidMountEffect(() => {
handleScroll?.();
}, [showEdit, message?.reactions?.length]);

// Side effect: scroll position update when message updated
useDidMountEffect(() => {
handleScroll?.(true);
}, [message?.updatedAt, (message as UserMessage)?.message]);

// Side effect: scroll position update when suggested replies are rendered or hidden
const prevShouldRenderSuggestedReplies = useRef(shouldRenderSuggestedReplies);
useEffect(() => {
if (prevShouldRenderSuggestedReplies.current !== shouldRenderSuggestedReplies) {
handleScroll?.();
} else {
prevShouldRenderSuggestedReplies.current = shouldRenderSuggestedReplies;
}
}, [shouldRenderSuggestedReplies]);

useLayoutEffect(() => {
// Keep the scrollBottom value after fetching new message list (but GroupChannel module is not needed.)
if (usedInLegacy) handleScroll?.(true);
Expand Down

0 comments on commit b5f91d5

Please sign in to comment.