I have a card component that the user can move to the side to reveal buttons.
If the user didn't tap any button after 2 seconds, I want to slide the card back to place. I tried to achieve this with setTimeout, but I get an error that says I need to use runOnJS, I tried, but got the same error. This is what I have:
const panGesture = useAnimatedGestureHandler<PanGestureHandlerGestureEvent>({
onEnd: event => {
const shouldStick = translateX.value >= TRANSLATE_X_THRESHOULD;
if (shouldStick) {
translateX.value = withTiming(120);
setTimeout(() => {
translateX.value = withTiming(0);
}, 2000)
} else {
translateX.value = withTiming(0);
}
},
});
I also tried wrapping setTimeout with runOnJS, like this:
runOnJS(() => {
setTimeout(() => {
translateX.value = withTiming(0);
}, 2000);
});
but it also didn't work. is it the right way to achieve what I'm trying to achieve?