fix: jump to message not working properly (#5235)

This commit is contained in:
Diego Mello 2023-09-28 10:38:54 -03:00 committed by GitHub
parent 987778b737
commit 37c58eb3ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 7 deletions

View File

@ -11,11 +11,14 @@ export const useScroll = ({ listRef, messagesIds }: { listRef: TListRef; message
const viewableItems = useRef<ViewToken[] | null>(null);
const highlightTimeout = useRef<ReturnType<typeof setTimeout> | null>(null);
useEffect(() => () => {
if (highlightTimeout.current) {
clearTimeout(highlightTimeout.current);
}
});
useEffect(
() => () => {
if (highlightTimeout.current) {
clearTimeout(highlightTimeout.current);
}
},
[]
);
const jumpToBottom = () => {
listRef.current?.scrollToOffset({ offset: -100 });
@ -52,10 +55,10 @@ export const useScroll = ({ listRef, messagesIds }: { listRef: TListRef; message
jumping.current = true;
// look for the message on the state
const index = messagesIds.current?.findIndex(item => item === messageId);
const index = messagesIds.current?.findIndex(item => item === messageId) ?? -1;
// if found message, scroll to it
if (index && index > -1) {
if (index !== -1) {
listRef.current?.scrollToIndex({ index, viewPosition: 0.5, viewOffset: 100 });
// wait for scroll animation to finish