From f84031b53905ed0f4ad140315d43e1a0b041c343 Mon Sep 17 00:00:00 2001 From: Hailey Date: Fri, 17 May 2024 22:11:19 -0700 Subject: [PATCH] better naming to avoid confusion --- src/screens/Messages/Conversation/MessagesList.tsx | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/screens/Messages/Conversation/MessagesList.tsx b/src/screens/Messages/Conversation/MessagesList.tsx index 77314cd916d..59886932dff 100644 --- a/src/screens/Messages/Conversation/MessagesList.tsx +++ b/src/screens/Messages/Conversation/MessagesList.tsx @@ -92,7 +92,7 @@ export function MessagesList({ // Used to keep track of the current content height. We'll need this in `onScroll` so we know when to start allowing // onStartReached to fire. - const contentHeight = useSharedValue(0) + const prevContentHeight = useRef(0) const prevItemCount = useRef(0) const keyboardIsAnimating = useSharedValue(false) @@ -116,7 +116,7 @@ export function MessagesList({ // previous off whenever we add new content to the previous offset whenever we add new content to the list. if (isWeb && isAtTop.value && hasScrolled) { flatListRef.current?.scrollToOffset({ - offset: height - contentHeight.value, + offset: height - prevContentHeight.current, animated: false, }) } @@ -129,12 +129,12 @@ export function MessagesList({ // message - we ignore this rule if there's only one additional message if ( hasScrolled && - height - contentHeight.value > layoutHeight.value - 50 && + height - prevContentHeight.current > layoutHeight.value - 50 && convoState.items.length - prevItemCount.current > 1 ) { setShowNewMessagesPill(true) flatListRef.current?.scrollToOffset({ - offset: contentHeight.value - 50, + offset: prevContentHeight.current - 50, animated: false, }) } else { @@ -151,16 +151,15 @@ export function MessagesList({ } } - contentHeight.value = height + prevContentHeight.current = height prevItemCount.current = convoState.items.length }, [ - hasScrolled, convoState.items.length, convoState.isFetchingHistory, + hasScrolled, setHasScrolled, // all of these are stable - contentHeight, flatListRef, isAtBottom.value, isAtTop.value,