Skip to content
tezvyn:
Menu

Gesture Responder System lifecycle

Source: interviewMediumHow cards are made

Summary

how RN assigns touch ownership.

Key points

a single view becomes the responder for a touch; onStartShouldSetResponder claims it at touch start, onMoveShouldSetResponder claims it on movement, then grant, move, and release callbacks fire.

WHAT THIS TESTS This probes understanding of the lower-level touch system that underlies touchables, and the negotiation that decides which single view owns a gesture.

A GOOD ANSWER COVERS The Gesture Responder System designates exactly one view as the responder for a given active touch, so touches do not fire on many views at once. A view declares interest by returning true from onStartShouldSetResponder, evaluated when a touch begins, or from onMoveShouldSetResponder, evaluated as the finger moves. The distinction is timing and intent: onStartShouldSetResponder is for views that want the touch immediately on contact, like a button; onMoveShouldSetResponder lets a view wait and claim the gesture only once movement occurs, which is how you distinguish a scroll or drag from a simple tap so a child can take a tap while a parent takes a drag. There is also a capture variant, onStartShouldSetResponderCapture and onMoveShouldSetResponderCapture, letting an ancestor intercept before children. Once a view wins, onResponderGrant fires, then onResponderMove during movement, and onResponderRelease when the touch ends, with onResponderTerminate if the responder is taken away, for example by a scroll.

COMMON WRONG ANSWERS Believing multiple views simultaneously handle one touch. Confusing the should-set negotiation with the grant and release lifecycle. Forgetting the capture phase that lets parents intercept.

LIKELY FOLLOW-UPS What is the capture phase for? How does this relate to react-native-gesture-handler? What causes onResponderTerminate?

ONE CONCRETE EXAMPLE In a draggable card inside a scroll area, the card returns false from onStartShouldSetResponder so a quick tap is not stolen, but returns true from onMoveShouldSetResponder once the finger moves enough, claiming the drag. It then receives onResponderMove updates to follow the finger and onResponderRelease to settle, while the parent scroll yields ownership.

Interview question

What is the practical difference between onStartShouldSetResponder and onMoveShouldSetResponder?

  • a.Start handles taps and Move handles keyboard events
  • b.They are aliases and behave identically
  • c.Move fires before Start to give children priority over parents
  • d.Start claims the touch immediately on contact, while Move lets a view claim it only after the finger moves, distinguishing taps from dragsCorrect
Why?

onStartShouldSetResponder negotiates ownership at touch down, while onMoveShouldSetResponder lets a view wait and claim the gesture once movement begins, which is how a drag is separated from a tap. They are not aliases and Move does not precede Start.

Just read this? Test yourself on what you have been reading.

Read the original → reactnative.dev

Put your scrolling time to good use

Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.

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.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Open roles that interview on react-native — each one lists the topics its interview covers.

See open roles