about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorHailey <me@haileyok.com>2024-05-20 18:03:53 -0700
committerGitHub <noreply@github.com>2024-05-20 18:03:53 -0700
commita7c2370680616ee5ca1bc8ce8194829c9f09f603 (patch)
treecf716adb7f8b3ac4039ae49bec3a2a0c703094fd /src
parentcadc33c625949aedea7504bff6aa405aee029f73 (diff)
downloadvoidsky-a7c2370680616ee5ca1bc8ce8194829c9f09f603.tar.zst
[🐴] set layout height in `onLayout` (#4135)
* set layout height in `onLayout`

* keep setting it in `onScroll` too
Diffstat (limited to 'src')
-rw-r--r--src/screens/Messages/Conversation/MessagesList.tsx34
1 files changed, 22 insertions, 12 deletions
diff --git a/src/screens/Messages/Conversation/MessagesList.tsx b/src/screens/Messages/Conversation/MessagesList.tsx
index 167cc72bd..ce466d95e 100644
--- a/src/screens/Messages/Conversation/MessagesList.tsx
+++ b/src/screens/Messages/Conversation/MessagesList.tsx
@@ -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,
@@ -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({
@@ -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} />
           </>
         )}