Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: scroll to bottom issue when the message list is empty #2471

Merged
merged 3 commits into from
Apr 2, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export const usePaginatedSearchedMessages = (
{
limit: DEFAULT_PAGINATION_LIMIT,
offset: offset.current,
sort: { updated_at: -1 },
},
);

Expand Down
6 changes: 4 additions & 2 deletions package/src/components/MessageList/MessageList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ const MessageListWithContext = <
if (threadList || hasNoMoreRecentMessagesToLoad) {
scrollToBottomIfNeeded();
} else {
setScrollToBottomButtonVisible(true);
setScrollToBottomButtonVisible(false);
}
Comment on lines 527 to 529
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems like a big change...

have you also tested with jump to message? its in sample-app mention screen

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works fine.


if (
Expand Down Expand Up @@ -805,13 +805,15 @@ const MessageListWithContext = <

const handleScroll: ScrollViewProps['onScroll'] = (event) => {
const offset = event.nativeEvent.contentOffset.y;
const messageListHasMessages = processedMessageList.length > 0;
// Show scrollToBottom button once scroll position goes beyond 150.
const isScrollAtBottom = offset <= 150;

const notLatestSet = channel.state.messages !== channel.state.latestMessages;

const showScrollToBottomButton =
(!threadList && notLatestSet) || !isScrollAtBottom || !hasNoMoreRecentMessagesToLoad;
messageListHasMessages &&
((!threadList && notLatestSet) || !isScrollAtBottom || !hasNoMoreRecentMessagesToLoad);

/**
* 1. If I scroll up -> show scrollToBottom button.
Expand Down
Loading