Change useRef value within a worklet #3198
Unanswered
rahulsyal2512
asked this question in
Q&A
Replies: 1 comment
-
Hi, you can use another useSharedValue instead of useRef. There might be a better way to do this though... Here's the part of the documentation:
https://docs.swmansion.com/react-native-reanimated/docs/api/hooks/useSharedValue/ |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
const x = useSharedValue(0);
const offset = useRef(true);
const gestureHandler = useAnimatedGestureHandler({
onStart: (_, ctx) => {
ctx.startX = x.value;
offset.current = false // <- how to use this here
},
onActive: (event, ctx) => {
x.value = ctx.startX + event.translationX;
},
onEnd: _ => {
x.value = withSpring(0);
offset.current = true // <- how to use this here
},
});
useRef value is not getting changed inside worklet.
Version-
react-native-reanimated - 2.4.0
Beta Was this translation helpful? Give feedback.
All reactions