When am I supposed to use runOnJS?? #2292
-
I have an app where I am using the Pan Gesture, and is mapping the user's translateY to camera zoom(similar to how snapchat camera zoom works) I am changing the cameraZoomLevel on onUpdate and that seems to be causing the app to freeze. I have looked into the documentation and have seen a few StackOverflow questions regarding runOnJS and runOnUI but can't find a satisfactory explanation on how exactly they work. Would love to know when I'm supposed to be using runOnJS. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
Reanimated's worklets are executed on the UI thread and not the JS one. You can use As a sidenote, if you don't want the callbacks of a gesture running on the UI thread, you can use const pan = Gesture.Pan().runOnJS(true); |
Beta Was this translation helpful? Give feedback.
Reanimated's worklets are executed on the UI thread and not the JS one. You can use
runOnJS
andrunOnUI
to schedule execution of a function on a different thread than you currently are, i.e. you should userunOnUI
on the JS thread when you want some code to execute on the UI thread and similarly, you should userunOnJS
on the UI thread when you want some code to execute on the JS thread. Keep in mind that only worklets can be executed on the UI thread, that's why you need to userunOnJS
when changing state.As a sidenote, if you don't want the callbacks of a gesture running on the UI thread, you can use
.runOnJS(true)
modifier, i.e.: