Replies: 2 comments
|
If you reference values from the react state in gesture callback functions, it depends how you create the gesture. If you don't memoize the gesture and just call e.g. If you memoize your gesture e.g. with If you mean updating react state once the In general, you should avoid synchronizing worklet callbacks with react state when possible, especially in handlers like You can explain your specific case and I will try to give more suggestions on the valid approach for you. |
|
The important thing is that gesture callbacks run as worklets, so they should not depend on React state being “live” unless you explicitly mirror it. Two patterns work well:
const mode = useSharedValue(selectedMode);
useEffect(() => {
mode.value = selectedMode;
}, [selectedMode]);Then read
If you need to update React state from the gesture, do the opposite direction with .onEnd(() => {
runOnJS(setDragging)(false);
})So the general rule is: UI thread reads shared values, JS thread owns React state. Mirroring state into shared values is usually the cleanest solution. |
Uh oh!
There was an error while loading. Please reload this page.
how can i sync Gesture.Pan() methods (onUpdate, onEnd) with react state
so when these methods are called they have the updated react state value
All reactions