I have a problem with runOnJS in my swipe function.
All the time Im gets error:
java.lang.RuntimeException: Tried to synchronously call function {w} from a different thread.
Im gets the error in panGesture function when its called finishAnimation.
Code is here:
https://pastebin.com/YaQs4bN6
2
Answers
As you are using Reanimated 2. you can add the
Worklet
directive toonSwipeComplete
then you can run this function in both UI and JavaScript` threads.More about worklet here – https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/worklets
You’re calling "finishAnimation" from the onEnd callback. That could be a problem, since finishAnimation isn’t a worklet.
So you have two options:
Hopefully it’s going to work.