From 37c58eb3bac8831846a6b817de0fba28207ec65a Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Thu, 28 Sep 2023 10:38:54 -0300 Subject: [PATCH] fix: jump to message not working properly (#5235) --- app/views/RoomView/List/hooks/useScroll.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/app/views/RoomView/List/hooks/useScroll.ts b/app/views/RoomView/List/hooks/useScroll.ts index 68a24446a..5f6551b5a 100644 --- a/app/views/RoomView/List/hooks/useScroll.ts +++ b/app/views/RoomView/List/hooks/useScroll.ts @@ -11,11 +11,14 @@ export const useScroll = ({ listRef, messagesIds }: { listRef: TListRef; message const viewableItems = useRef(null); const highlightTimeout = useRef | 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