Closed ldorigo closed 1 year ago
Hey! 👋
It looks like you've omitted a few important sections from the issue template.
Please complete Snack or a link to a repository section.
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?
Hi @ldorigo 👋
First of all, could You please make a snack from the code, or remove it from <details>
tag? This way it will be easier to read. Also in that code you're using relative paths import, so it is hard to reproduce the behaviour that you get.
However, I've done some tests with onUpdate
in our example app and it seems to work fine, even without "worklet"
. In details you say that you're using Gesture Handler 2.5.0, please update it to newer version (the latest is 2.8.0) and check whether your app still crashes.
Sorry, I didn't see that the <details>
was messing up the formatting. I will try again later with the latest version.
If I understood the problem correctly that's expected behavior. If you have react-native-reanimated
installed, all gesture callbacks will be run on the UI thread, unless .runOnJS(true)
modifier is used.
In order for a function to be run on the UI thread it needs to be marked as worklet
(otherwise the app will crash, because the function will not exist on the Reanimated's JS context on UI thread). Reanimated's babel plugin automatically does it for callbacks in the gesture builder chain, but if you're using another function inside, or defining callbacks out of the chain you need to mark the relevant functions yourself.
Fair enough. I don't think I saw that written anywhere explicitly in the docs, but I may be wrong (then again, the docs don't say that it should work - but it definitely wasn't clear to me that I had to mark that as a worklet :-)
On the other hand, it might be useful to show some kind of error message when this happens- currently the app just crashes with no output whatsoever and it took me ages to figure out what the problem was.
If I understood the problem correctly that's expected behavior. If you have
react-native-reanimated
installed, all gesture callbacks will be run on the UI thread, unless.runOnJS(true)
modifier is used. In order for a function to be run on the UI thread it needs to be marked asworklet
(otherwise the app will crash, because the function will not exist on the Reanimated's JS context on UI thread). Reanimated's babel plugin automatically does it for callbacks in the gesture builder chain, but if you're using another function inside, or defining callbacks out of the chain you need to mark the relevant functions yourself.
@j-piasecki thanks man! .runOnJS(true)
is exactly what i was looking for. 👏🏻
I also received crashes on Andriod but when using the Gesture.LongPress().onStart
function. (It worked just fine without this on iOS). This too was solvable by adding .runOnJs(true)
. Adding the error log here for visibility of this issue thread:
E/libc++abi: terminating with uncaught exception of type facebook::jsi::JSError: Attempting to define property on object that is not extensible.
Description
Not entirely sure whether this issue is with Reanimated or RNGH, but since it happens inside a RNGH method I post it here.
I needed to do some processing in the .onUpdate function and decided to put it in a separate function as it was growing too long. This caused the application to crash exactly as that function gets called. I post the code below, sorry if I don't make a reproducible env but I already spent an enormous amount of time figuring this out. Hopefully this can still be useful to you.
Steps to reproduce
See code above. Sorry I don't have the time to make a reproducible example now, hope this can still help.
Snack or a link to a repository
/
Gesture Handler version
2.5.0
React Native version
0.69.6
Platforms
Android
JavaScript runtime
Hermes
Workflow
Expo managed workflow
Architecture
Paper (Old Architecture)
Build type
Debug mode
Device
Real device
Device model
Blackview bv9900 pro
Acknowledgements
Yes