React Native · Mobile UI at native speed
How does react-native-gesture-handler work?
Short answer
It handles gestures with native recognisers and a declarative API, so gestures can run without waiting on the JS thread. Use GestureDetector with composed gestures and coordinate with scroll views explicitly.
The built-in touch system works for simple taps and pans, but complex interactions such as swipes, pinch and simultaneous gestures need a dedicated recogniser. react-native-gesture-handler provides one and integrates with Reanimated worklets for UI-thread updates.
import { Gesture, GestureDetector } from "react-native-gesture-handler";
import Animated, { useAnimatedStyle, useSharedValue, withSpring } from "react-native-reanimated";
export function Draggable() {
const x = useSharedValue(0);
const pan = Gesture.Pan().onChange((event) => {
x.value += event.changeX;
}).onEnd(() => {
x.value = withSpring(0);
});
const style = useAnimatedStyle(() => ({ transform: [{ translateX: x.value }] }));
return (
<GestureDetector gesture={pan}>
<Animated.View style={[{ width: 80, height: 80 }, style]} />
</GestureDetector>
);
}Composition and conflicts
- Gesture.Race for whichever gesture activates first
- Gesture.Simultaneous for pinch and pan together
- Gesture.Exclusive when one gesture should take priority
- blocksExternalGesture and requireExternalGestureToFail to coordinate with scroll views
- GestureHandlerRootView must wrap the app at the root
Gestures inside a ScrollView are a common source of conflict. A horizontal swipe on a row may be stolen by vertical scrolling, or the list may not scroll at all. Use the composition helpers and test on both platforms, because the native recognisers behave differently.
Follow-ups you should expect
Interviewers use these to check whether the first answer was understanding or memorisation.
- 1How do you combine a pan and a pinch gesture?
- 2How do you stop a swipeable row from blocking vertical scroll?
- 3Why should gesture updates avoid setState?
- 4What is the role of GestureHandlerRootView?
Say it in the interview
Gesture handler uses native recognisers and a declarative composition API, and it pairs naturally with Reanimated so gesture updates stay on the UI thread. I compose gestures with Race, Simultaneous or Exclusive, and use the external gesture helpers when a gesture needs to coordinate with a scroll view. I avoid setState during a gesture because re-rendering on every move is what makes drags feel laggy.
Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.
Related questions
Reading is step one
Now say it out loud.
Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live React Native mock interview and get scored feedback on depth, clarity and confidence.