React Native ships a touch system called the Gesture Responder System, and it runs on the JavaScript thread. If that thread is busy - rendering a list, parsing a response - your drag stutters, because the next position cannot be computed until the thread is free.
react-native-gesture-handler moves recognition to the native side. The gesture is tracked by the platform's own machinery, so it stays smooth regardless of what JavaScript is doing, and it understands composition: gestures can be made exclusive, simultaneous, or ordered so one waits for another to fail. That last one is what lets a tap and a long press coexist on the same view without either stealing the other's touches.
The modern API is the Gesture object with Gesture.Pan(), Gesture.Tap(), Gesture.Pinch() and the composers Gesture.Simultaneous, Gesture.Exclusive and Gesture.Race. Wrap your app once in GestureHandlerRootView - forgetting it is the single most common setup mistake, and the symptom is gestures silently doing nothing on Android.
Gesture handler pairs with Reanimated: the callbacks run on the UI thread, so a pan that updates a shared value never touches JavaScript at all.
import { Gesture, GestureDetector, GestureHandlerRootView } from 'react-native-gesture-handler';
import Animated, { useSharedValue, useAnimatedStyle, withSpring } from 'react-native-reanimated';
export function App() {
// Wrap ONCE at the root. Without it, gestures silently do nothing
// on Android - the most common setup mistake there is.
return (
<GestureHandlerRootView style={{ flex: 1 }}>
<DraggableCard />
</GestureHandlerRootView>
);
}
function DraggableCard() {
const x = useSharedValue(0);
const y = useSharedValue(0);
const scale = useSharedValue(1);
// These callbacks run on the UI thread, not in JavaScript.
const pan = Gesture.Pan()
.onChange((event) => {
x.value += event.changeX;
y.value += event.changeY;
})
.onEnd(() => {
x.value = withSpring(0);
y.value = withSpring(0);
});
const pinch = Gesture.Pinch()
.onChange((event) => { scale.value = event.scale; })
.onEnd(() => { scale.value = withSpring(1); });
const doubleTap = Gesture.Tap()
.numberOfTaps(2)
.onEnd(() => { scale.value = withSpring(scale.value > 1 ? 1 : 2); });
// Pan and pinch together; the double tap competes with neither.
const composed = Gesture.Simultaneous(pan, pinch, doubleTap);
const style = useAnimatedStyle(() => ({
transform: [
{ translateX: x.value },
{ translateY: y.value },
{ scale: scale.value },
],
}));
return (
<GestureDetector gesture={composed}>
<Animated.View style={[{ width: 160, height: 160, backgroundColor: '#0c7', borderRadius: 20 }, style]} />
</GestureDetector>
);
}
Open this example in the editor and change it. Nothing you type is saved.