Skip to content

[v4] | Keyboard dismiss crashes - Tried to synchronously call a non-worklet function on the Ul thread. #1369

@tsdmrfth

Description

@tsdmrfth

Bug

The app crashes when dismissing keyboard. I'm getting the error below
Simulator Screen Shot - iPhone SE (3rd generation) - 2023-05-12 at 10 01 36

Environment info

Library Version
@gorhom/bottom-sheet 4.6.6
react-native 0.71.6
react-native-reanimated 3.0.2
react-native-gesture-handler 2.9.0

Steps To Reproduce

  1. Create a bottom sheet with BottomSheetTextInput
  2. Swipe down the bottom sheet

Describe what you expected to happen:

  1. Bottom sheet to dismiss keyboard with no crash...

Reproducible sample code

https://snack.expo.dev/UXATlw3L7

Here is the diff that solved my problem:

diff --git a/node_modules/@gorhom/bottom-sheet/src/hooks/useGestureEventsHandlersDefault.tsx b/node_modules/@gorhom/bottom-sheet/src/hooks/useGestureEventsHandlersDefault.tsx
index a0b759c..73eb034 100644
--- a/node_modules/@gorhom/bottom-sheet/src/hooks/useGestureEventsHandlersDefault.tsx
+++ b/node_modules/@gorhom/bottom-sheet/src/hooks/useGestureEventsHandlersDefault.tsx
@@ -21,7 +21,9 @@ type GestureEventContextType = {
   isScrollablePositionLocked: boolean;
 };
 
-const dismissKeyboardOnJs = runOnJS(Keyboard.dismiss);
+const dismissKeyboard = () => {
+    Keyboard.dismiss()
+}
 
 export const useGestureEventsHandlersDefault: GestureEventsHandlersHookType =
   () => {
@@ -298,7 +300,7 @@ export const useGestureEventsHandlersDefault: GestureEventsHandlersHookType =
                 absoluteY > WINDOW_HEIGHT - animatedKeyboardHeight.value
               )
             ) {
-              dismissKeyboardOnJs();
+              runOnJS(dismissKeyboard)();
             }
           }

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions