Skip to content

Commit db6a256

Browse files
fix wrong at bottom calculation
1 parent 9106ce2 commit db6a256

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

apps/meteor/client/views/room/MessageList/MessageList.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ type MessageListProps = {
4343
handleDateScroll: (topMessage: IMessage | undefined) => void;
4444
};
4545

46-
let lastViewportSize = 0;
46+
let lastScrollSize = 0;
4747

4848
export const MessageList = function MessageList({
4949
rid,
@@ -84,7 +84,14 @@ export const MessageList = function MessageList({
8484
isPrepend.current = true;
8585
}
8686

87-
isAtBottom.current = offset - (virtualizerRef.current?.scrollSize ?? 0) + (virtualizerRef.current?.viewportSize ?? 0) >= -20;
87+
const scrollSize = virtualizerRef.current?.scrollSize ?? 0;
88+
const viewportSize = virtualizerRef.current?.viewportSize ?? 0;
89+
90+
if (scrollSize >= viewportSize) {
91+
isAtBottom.current = true;
92+
}
93+
94+
isAtBottom.current = offset - scrollSize + viewportSize >= -60;
8895
if (shouldJumpToBottom.current && isAtBottom.current) {
8996
shouldJumpToBottom.current = false;
9097
}
@@ -138,8 +145,8 @@ export const MessageList = function MessageList({
138145
});
139146
}
140147
// If new messages arrive and is at bottom, scroll to keep at bottom
141-
if (isAtBottom.current && lastViewportSize !== handle?.viewportSize) {
142-
lastViewportSize = handle?.viewportSize ?? 0;
148+
if (isAtBottom.current && lastScrollSize !== handle?.scrollSize) {
149+
lastScrollSize = handle?.scrollSize ?? 0;
143150
handle?.scrollToIndex(lastItemIndex + 1, {
144151
align: 'end',
145152
});

0 commit comments

Comments
 (0)