Closed jsindos closed 1 year ago
Gesture Handler will detect and use Reanimated when you have it installed even without explicitly using it. In this case the gesture callbacks are automatically workletized and run on the UI thread. You can use .runOnJS(true)
modifier to prevent it from happening, i.e.:
const panGesture = Gesture.Pan()
.runOnJS(true)
.onUpdate((e) => {
translate.setValue({ x: e.translationX + currentX, y: 0 })
})
.onEnd((e) => {
setCurrentX(e.translationX + currentX)
})
@j-piasecki Thanks for responding. So I take it you can only certain commands in a worklet, and running any code in the context of regular Animated
from react-native
will cause a crash?
I had a similar problem. When i using a gesture detector and runOnJS for state functions the app was freezing, but chaining e.g the gesture.pan() with runOnJS(true) solved my problem.
@jsindos That's correct. Inside a worklet you can only call other worklets, calling another function directly (without runOnJS
) will result in a crash.
Gesture Handler will detect and use Reanimated when you have it installed even without explicitly using it. In this case the gesture callbacks are automatically workletized and run on the UI thread. You can use
.runOnJS(true)
modifier to prevent it from happening, i.e.:const panGesture = Gesture.Pan() .runOnJS(true) .onUpdate((e) => { translate.setValue({ x: e.translationX + currentX, y: 0 }) }) .onEnd((e) => { setCurrentX(e.translationX + currentX) })
You Saved my day...
Description
My React Native app on Android is dying upon first touch with a
Gesture.Pan()
after installingreact-native-reanimated
. It works fine beforehand.I am not explicitly importing
react-native-reanimated
anywhere in the application.I have included
'react-native-reanimated/plugin'
inbabel.config.js
.I cleaned cache before running the project.
I have a
RectButton
fromreact-native-gesture-handler
elsewhere in my project which doesn't crash the app upon interaction.Output from
adb logcat
as the crash occurs:Steps to reproduce
npm i react-native-reanimated@^2.13.0 react-native-gesture-handler@2.8.0
Snack or a link to a repository
https://github.com/jsindos/gesture-pan-bug-snack
Reanimated version
2.13.0
React Native version
0.69.6
Platforms
Android
JavaScript runtime
No response
Workflow
Expo bare workflow
Architecture
No response
Build type
No response
Device
Real device
Device model
Google Pixel 6
Acknowledgements
Yes