I'm trying to change the state of a variable using the set function of useState inside onEnd event of useAnimatedGestureHandler hook, but the application crashes everytime I try to do that. Does anybody know why and how to fix it?
I have the following code:
const [canTouch, setCanTouch] = useState(true);
const unlockGestureSwipeUp = useAnimatedGestureHandler({
onStart: () => {},
onActive: (event) => {
yUp.value = event.absoluteY;
},
onEnd: (event) => {
if (opacity1.value === 1 && (yUp.value < 600 || event.velocityY < -500)) {
setCanTouch(false);
opacity1.value = withDelay(0 * 500, withTiming(0, { duration: 1000 }));
opacity2.value = withDelay(0 * 500, withTiming(1, { duration: 1000 }));
...
Every time it gets to that setCanTouch(false)
, the app crashes.