$ git show swipe-reply
Swipe to reply
Drag a chat bubble right; a reply icon grows in and a haptic fires at the threshold.
Inspired by WhatsAppFrom William Candillon’s “Can it be done in React Native?” series. The code here is a simplified rewrite for Reanimated 4 and 3.
import { scheduleOnRN } from 'react-native-worklets';
const x = useSharedValue(0), fired = useSharedValue(false);
const pan = Gesture.Pan()
.activeOffsetX(15).failOffsetY([-10, 10]) // keep vertical list scrolling
.onUpdate(e => {
x.value = clamp(e.translationX * 0.6, 0, 80);
if (x.value >= 70 && !fired.value) {
fired.value = true;
scheduleOnRN(Haptics.impactAsync, Haptics.ImpactFeedbackStyle.Light);
}
})
.onEnd(() => {
if (fired.value) scheduleOnRN(onReply, message);
x.value = withSpring(0); fired.value = false;
});
const bubble = useAnimatedStyle(() => ({ transform: [{ translateX: x.value }] }));
const icon = useAnimatedStyle(() => ({
opacity: x.value / 70,
transform: [{ scale: interpolate(x.value, [0, 70], [0.5, 1], Extrapolation.CLAMP) }],
}));