about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorHailey <me@haileyok.com>2024-05-20 12:53:15 -0700
committerGitHub <noreply@github.com>2024-05-20 12:53:15 -0700
commit994af1454f668af8ae051d1bd8395e626f6f19e8 (patch)
tree8e59c1446e0acb0e3f8bbee20fbd7868c13ab995 /src
parent5771ff4b56f235a5f356d55a92dce0b45f7a4679 (diff)
downloadvoidsky-994af1454f668af8ae051d1bd8395e626f6f19e8.tar.zst
[🐴] Adjust content height whenever the emoji picker keyboard is opened or closed (#4120)
* properly resize whenever the emoji keyboard is opened

* properly resize whenever the emoji keyboard is opened
Diffstat (limited to 'src')
-rw-r--r--src/screens/Messages/Conversation/MessagesList.tsx23
1 files changed, 18 insertions, 5 deletions
diff --git a/src/screens/Messages/Conversation/MessagesList.tsx b/src/screens/Messages/Conversation/MessagesList.tsx
index 68e68b8cb..cbe037fec 100644
--- a/src/screens/Messages/Conversation/MessagesList.tsx
+++ b/src/screens/Messages/Conversation/MessagesList.tsx
@@ -226,10 +226,21 @@ export function MessagesList({
   const keyboardHeight = useSharedValue(0)
   const keyboardIsOpening = useSharedValue(false)
 
+  // In some cases - like when the emoji piker opens - we don't want to animate the scroll in the list onLayout event.
+  // We use this value to keep track of when we want to disable the animation.
+  const layoutScrollWithoutAnimation = useSharedValue(false)
+
   useKeyboardHandler({
-    onStart: () => {
+    onStart: e => {
       'worklet'
-      keyboardIsOpening.value = true
+      // Immediate updates - like opening the emoji picker - will have a duration of zero. In those cases, we should
+      // just update the height here instead of having the `onMove` event do it (that event will not fire!)
+      if (e.duration === 0) {
+        layoutScrollWithoutAnimation.value = true
+        keyboardHeight.value = e.height
+      } else {
+        keyboardIsOpening.value = true
+      }
     },
     onMove: e => {
       'worklet'
@@ -277,11 +288,13 @@ export function MessagesList({
 
   // -- List layout changes (opening emoji keyboard, etc.)
   const onListLayout = React.useCallback(() => {
-    if (keyboardIsOpening.value) return
     if (isWeb || !keyboardIsOpening.value) {
-      flatListRef.current?.scrollToEnd({animated: true})
+      flatListRef.current?.scrollToEnd({
+        animated: !layoutScrollWithoutAnimation.value,
+      })
+      layoutScrollWithoutAnimation.value = false
     }
-  }, [flatListRef, keyboardIsOpening.value])
+  }, [flatListRef, keyboardIsOpening.value, layoutScrollWithoutAnimation])
 
   const scrollToEndOnPress = React.useCallback(() => {
     flatListRef.current?.scrollToOffset({