Skip to content

Commit

Permalink
[🐴] set layout height in onLayout (#4135)
Browse files Browse the repository at this point in the history
* set layout height in `onLayout`

* keep setting it in `onScroll` too
  • Loading branch information
haileyok authored May 21, 2024
1 parent cadc33c commit a7c2370
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions src/screens/Messages/Conversation/MessagesList.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, {useCallback, useRef} from 'react'
import {FlatList, View} from 'react-native'
import {FlatList, LayoutChangeEvent, View} from 'react-native'
import {
KeyboardStickyView,
useKeyboardHandler,
Expand Down Expand Up @@ -292,14 +292,24 @@ export function MessagesList({
)

// -- List layout changes (opening emoji keyboard, etc.)
const onListLayout = React.useCallback(() => {
if (isWeb || !keyboardIsOpening.value) {
flatListRef.current?.scrollToEnd({
animated: !layoutScrollWithoutAnimation.value,
})
layoutScrollWithoutAnimation.value = false
}
}, [flatListRef, keyboardIsOpening.value, layoutScrollWithoutAnimation])
const onListLayout = React.useCallback(
(e: LayoutChangeEvent) => {
layoutHeight.value = e.nativeEvent.layout.height

if (isWeb || !keyboardIsOpening.value) {
flatListRef.current?.scrollToEnd({
animated: !layoutScrollWithoutAnimation.value,
})
layoutScrollWithoutAnimation.value = false
}
},
[
flatListRef,
keyboardIsOpening.value,
layoutScrollWithoutAnimation,
layoutHeight,
],
)

const scrollToEndOnPress = React.useCallback(() => {
flatListRef.current?.scrollToOffset({
Expand Down Expand Up @@ -347,9 +357,9 @@ export function MessagesList({
footer
) : (
<>
{isConvoActive(convoState) && convoState.items.length === 0 && (
<ChatEmptyPill />
)}
{isConvoActive(convoState) &&
!convoState.isFetchingHistory &&
convoState.items.length === 0 && <ChatEmptyPill />}
<MessageInput onSendMessage={onSendMessage} />
</>
)}
Expand Down

0 comments on commit a7c2370

Please sign in to comment.