$ git show swipe-stack
Swipe card stack
Tinder-style cards: drag past a threshold to fling off screen, otherwise snap back.
import { scheduleOnRN } from 'react-native-worklets';
const x = useSharedValue(0);
const pan = Gesture.Pan()
.onUpdate(e => { x.value = e.translationX; })
.onEnd(e => {
if (Math.abs(x.value) > 120 || Math.abs(e.velocityX) > 800) {
x.value = withTiming(Math.sign(x.value) * 500, {}, () => scheduleOnRN(onSwiped));
} else {
x.value = withSpring(0);
}
});
const style = useAnimatedStyle(() => ({
transform: [
{ translateX: x.value },
{ rotate: interpolate(x.value, [-200, 200], [-15, 15]) + 'deg' },
],
}));