software-mansion / react-native-gesture-handler

Declarative API exposing platform native touch and gesture system to React Native.
https://docs.swmansion.com/react-native-gesture-handler/
MIT License
5.83k stars 952 forks source link

Fatal Exception: com.facebook.jni.CppException: Exception in HostFunction: [Reanimated] Attempted to extract from a HostObject that wasn't converted to a Shareable. #2803

Closed ismaelsousa closed 1 month ago

ismaelsousa commented 1 month ago

Description

I am facing this

Fatal Exception: com.facebook.jni.CppException: Exception in HostFunction: [Reanimated] Attempted to extract from a HostObject that wasn't converted to a Shareable.

Error: Exception in HostFunction: [Reanimated] Attempted to extract from a HostObject that wasn't converted to a Shareable.
    at _scheduleOnJS (native)
    at anonymous (JavaScript:1:438)
    at anonymous (JavaScript:1:212)
    at anonymous (JavaScript:1:629)
    at handleAndFlushAnimationFrame (JavaScript:1:148)
       at com.swmansion.reanimated.nativeProxy.EventHandler.receiveEvent(EventHandler.java)
       at com.swmansion.reanimated.nativeProxy.EventHandler.receiveEvent(EventHandler.java:25)
       at com.swmansion.gesturehandler.react.RNGestureHandlerStateChangeEvent.dispatch(RNGestureHandlerStateChangeEvent.kt:42)
       at com.swmansion.reanimated.NodesManager.handleEvent(NodesManager.java:327)
       at com.swmansion.reanimated.NodesManager.onEventDispatch(NodesManager.java:313)
       at com.facebook.react.uimanager.events.EventDispatcherImpl.dispatchEvent(EventDispatcherImpl.java:116)
       at com.swmansion.gesturehandler.ReactContextExtensionsKt.dispatchEvent(ReactContextExtensions.kt:9)
       at com.swmansion.gesturehandler.react.RNGestureHandlerModule.sendEventForDirectEvent(RNGestureHandlerModule.kt:638)
       at com.swmansion.gesturehandler.react.RNGestureHandlerModule.sendEventForReanimated(RNGestureHandlerModule.kt:624)
       at com.swmansion.gesturehandler.react.RNGestureHandlerModule.onStateChange(RNGestureHandlerModule.kt:576)
       at com.swmansion.gesturehandler.react.RNGestureHandlerModule.access$onStateChange(RNGestureHandlerModule.kt:38)
       at com.swmansion.gesturehandler.react.RNGestureHandlerModule$eventListener$1.onStateChange(RNGestureHandlerModule.kt:346)
       at com.swmansion.gesturehandler.core.GestureHandler.dispatchStateChange(GestureHandler.kt:84)
       at com.swmansion.gesturehandler.core.GestureHandlerOrchestrator.onHandlerStateChange(GestureHandlerOrchestrator.kt:155)
       at com.swmansion.gesturehandler.core.GestureHandler.moveToState(GestureHandler.kt:551)
       at com.swmansion.gesturehandler.core.GestureHandler.cancel(GestureHandler.kt:640)
       at com.swmansion.gesturehandler.core.GestureHandlerOrchestrator.cancelAll(GestureHandlerOrchestrator.kt:244)
       at com.swmansion.gesturehandler.core.GestureHandlerOrchestrator.onTouchEvent(GestureHandlerOrchestrator.kt:43)
       at com.swmansion.gesturehandler.react.RNGestureHandlerRootHelper.dispatchTouchEvent(RNGestureHandlerRootHelper.kt:97)
       at com.swmansion.gesturehandler.react.RNGestureHandlerRootView.dispatchTouchEvent(RNGestureHandlerRootView.kt:35)
       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3286)
       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2990)

The gesture is re-throwing the event and the reanimated is listening. I am not able to determine where this is happening

Do you know when this code is executed?

link to code

 if (handler.actionType == GestureHandler.ACTION_TYPE_REANIMATED_WORKLET) {
        // Reanimated worklet
        val event = RNGestureHandlerEvent.obtain(handler, handlerFactory)
        sendEventForReanimated(event)
 }

Steps to reproduce

I can't reproduce it

Snack or a link to a repository

https://github.com/software-mansion/react-native-gesture-handler/blob/ee4f11b4f2373b834bb24a710a1901dd4db3efee/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerModule.kt#L542

Gesture Handler version

2.12.0

React Native version

0.71.15

Platforms

Android, iOS

JavaScript runtime

Hermes

Workflow

React Native (without Expo)

Architecture

Paper (Old Architecture)

Build type

Release mode

Device

Real device

Device model

Galaxy A53 5G

Acknowledgements

Yes

github-actions[bot] commented 1 month ago

Hey! 👋

The issue doesn't seem to contain a minimal reproduction.

Could you provide a snack or a link to a GitHub repository under your username that reproduces the problem?

m-bert commented 1 month ago

Duplicate of #2727

ismaelsousa commented 1 month ago

Hi @m-bert, in my case was an inline declaration of a function to run in the runOnJS

workletContext {
    runOnJS(() => onGestureCancel?.())();
}
stack trace of an app using react native and drawer library

For me was happening in the implementation of the react-native-drawer-layout while using the useAnimatedGestureHandler

For the fix just need to create the function in the JSContext

Check the official fix for this: https://github.com/react-navigation/react-navigation/commit/3cfb3e63949f0aa6f4b14db02161dd88fd10cb12?diff=unified&w=1