Skip to content

Commit

Permalink
better naming to avoid confusion
Browse files Browse the repository at this point in the history
  • Loading branch information
haileyok committed May 18, 2024
1 parent 7da6682 commit f84031b
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/screens/Messages/Conversation/MessagesList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
})
}
Expand All @@ -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 {
Expand All @@ -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,
Expand Down

0 comments on commit f84031b

Please sign in to comment.