The React Native Gesture Handler State Machine

Think of a gesture handler as a state machine with six states. This lets you react to specific moments in a gesture's lifecycle—like BEGAN or ACTIVE—not just a single event. The footgun: ignoring the CANCELLED state, which can leave your UI broken.
Why it exists
Simple event listeners don't capture the full lifecycle of a continuous gesture like dragging or pinching. To build fluid, interruptible interactions, you need more than a single 'tap' event; you need to know when a gesture starts, is active, and ends or gets cancelled.
The mental model
A gesture handler is a state machine. At any moment, it's in one of six states: UNDETERMINED, BEGAN, ACTIVE, END, FAILED, or CANCELLED. Your code doesn't just react to a gesture; it reacts to the handler's transition between these states as it processes touch events over time.
How it works
Every handler starts in the UNDETERMINED state. On first touch, it moves to BEGAN. If it receives enough touch data to recognize its gesture (e.g., a long press duration is met), it becomes ACTIVE. It stays ACTIVE as long as the gesture continues. When the user finishes (e.g., lifts their finger), it moves to END, then resets to UNDETERMINED. If the gesture is interrupted by the system, it moves from ACTIVE to CANCELLED. If the initial touches don't match the gesture's rules, it moves from BEGAN to FAILED. You monitor these changes using the onHandlerStateChange callback.
When to use it
Use the state machine model for any continuous gesture (pans, pinches, rotations) or complex interaction. This allows you to manage UI that changes during the gesture itself, like highlighting a button when a press BEGANs, dragging an element while the gesture is ACTIVE, and snapping it to a final position on END.
When not to use it
For the simplest discrete actions, like a basic button tap that only triggers one action, you might not need to manually inspect every state. The library often provides simpler callbacks for these cases, but the state machine is always operating underneath.
One canonical example
Consider a draggable card. When its pan gesture state becomes ACTIVE, you start updating the card's position from the event's translation values. While it remains ACTIVE, you continue updating its position on every frame. When the state becomes END, you might run a 'snap-back' animation. Crucially, if a parent ScrollView takes over and the state becomes CANCELLED, you must reset the card to its original position to avoid it getting stuck mid-drag.
Interview question
What is the primary reason to explicitly handle the CANCELLED state in a React Native Gesture Handler?
- a.To reset the UI to a stable state when the gesture is interrupted by another system event.Correct
- b.To prevent the gesture from activating if initial touch criteria are not met.
- c.To stop gesture processing and free up resources when the user completes the interaction.
- d.To confirm the gesture has successfully finished and trigger a final action.
Why? this is the answer
The CANCELLED state is crucial for handling interruptions, such as a parent ScrollView taking over, and ensures the UI reverts to a consistent state. Options A and D describe the purpose of the END state, while option B describes the FAILED state.
Just read this? Test yourself on what you have been reading.
Read the original → docs.swmansion.com
- #react-native
- #gestures
- #state-machine
- #ui
You just looked this up. Could you explain it out loud?
That is the part interviews actually test. Tezvyn takes questions like this one and gives you what the interviewer is really checking, the answer that lands, and the mistake that ends the conversation, in the four minutes before your next meeting.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Open roles that interview on react-native — each one lists the topics its interview covers.
See open roles