Skip to content

Commit bf313ba

Browse files
authored
fix: move scroll every time when message height changes (#654)
### Description Of Changes * fix: move scroll every time when message height changes * prev: moving scroll only when the last message height changes [UIKIT-4042](https://sendbird.atlassian.net/browse/UIKIT-4042)
1 parent 493de7f commit bf313ba

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/modules/Channel/components/Message/index.tsx

+5-4
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,12 @@ const Message = ({
136136
}));
137137
}, [mentionedUserIds]);
138138

139-
// Move the messsage list scroll when the last message's height is changed by reactions
139+
/**
140+
* Move the messsage list scroll
141+
* when the message's height is changed by `showEdit` OR `message.reactions`
142+
*/
140143
useDidMountEffect(() => {
141-
if (currentGroupChannel?.lastMessage?.messageId === message?.messageId) {
142-
handleScroll?.();
143-
}
144+
handleScroll?.();
144145
}, [showEdit, message?.reactions?.length]);
145146
useLayoutEffect(() => {
146147
handleMessageListHeightChange?.();

src/modules/Channel/components/MessageList/index.tsx

+6-2
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,16 @@ const MessageList: React.FC<MessageListProps> = ({
119119
}
120120
};
121121

122-
// Move the messsage list scroll when the last message's height is changed by reactions
122+
/**
123+
* Move the messsage list scroll
124+
* when each message's height is changed by `reactions` OR `showEdit`
125+
*/
123126
const handleMessageHeightChange = () => {
124127
const current = scrollRef?.current;
125128
if (current) {
126129
const bottom = current.scrollHeight - current.scrollTop - current.offsetHeight;
127-
if (scrollBottom < bottom && scrollBottom <= SCROLL_BUFFER) {
130+
if (scrollBottom < bottom) {
131+
// Move the scroll as much as the height of the message has changed
128132
current.scrollTop += bottom - scrollBottom;
129133
}
130134
}

0 commit comments

Comments
 (0)