Gestures
TODO: Expand.
How are hit tests performed?
The
RendererBindingisHitTestable, which implies the presence of ahitTestmethod. The default implementation defers toRenderView, which itself implementshitTestto visit the entire render tree. Each render object is given an opportunity to add itself to a sharedHitTestResult.GestureBinding.dispatchEvent(viaHitTestDispatcher) uses thePointerRouterto pass the original event to all render objects that were hit (RenderObjectimplementsHitTestTarget, and therefore provideshandleEvent). If aGestureRecognizeris utilized, the event’s pointer is passed viaGestureRecognizer.addPointerwhich registers with thePointerRouterto receive future events.Related events are sent to all original
HitTestTargetas well as any routes registered with thePointerRouter.PointerDownEventwill close the gesture area, barring additional entries, whereasPointerUpEventwill sweep it, resolving competing gestures and preventing indecisive gestures from locking up input.
How are gestures captured and propagated?
Window.onPointerDataPacketcaptures pointer updates from the engine and generatesPointerEventsfrom the raw data.PointerEventConverteris utilized to map physical coordinates from the engine to logical coordinates, taking into account the device’s pixel ratio (viaPointerEventConverter.expand).
What does a gesture recognizer do?
A pointer is added to the gesture recognizer by client code on
PointerDownEvent. Gesture recognizers determine whether a pointer is allowed by overridingGestureRecognizer.isPointerAllowed. If so, the recognizer subscribes to future pointer events via thePointerRouterand adds the pointer to the gesture arena viaGestureArenaManager.add.The recognizer will process incoming events, outcomes from the gesture arena (
GestureArenaMember.accept/rejectGesture), spontaneous decisions about the gesture (GestureArenaEntry.resolve), and other externalities. Typically, recognizers watch the stream ofPointerEventsviaHitTestTarget.handleEvent, looking for terminating events likePointerDown, or criteria that will cause acceptance / rejection. If the gesture is accepted, the recognizer will continue to process events to characterize the gesture, invoking user-provided callbacks at key moments.The gesture recognizer must unsubscribe from the pointer when rejecting or done processing, removing itself from the
PointerRouter(OneSequenceGestureRecognizer.stopTrackingPointerdoes this).
What does the gesture arena do?
The arena disambiguates multiple gestures in a way that allows single gestures to resolve immediately if there is no competition. A recognizer “wins” if it declares itself the winner or if it’s the last/sole survivor.
Can gesture recognizers be grouped together?
A
GestureArenaTeamcombines multiple recognizers together into a group.Captained teams cause the captain recognizer to win when all unaffiliated recognizers reject or a constituent accepts.
A non-captained team causes the first added recognizer to win when all unaffiliated recognizers reject. However, if a constituent accepts, that recognizer still takes the win.
What auxiliary classes support gesture handling?
There are two major categories of gesture recognizers, multi-touch recognizers (i.e.,
MultiTapGestureRecognizer) that simultaneously process multiple pointers (i.e., tapping with two fingers will register twice), and single-touch recognizer (i.e.,OneSequenceGestureRecognizer) that will only consider events from a single pointer (i.e., tapping with two fingers will register once).There is a helper “Drag” object that is used to communicate drag-related updates to other parts of the framework (like
DragScrollActivity)There’s a
VelocityTrackerthat generates fairly accurate estimates about drag velocity using curve fitting.There are local and global
PointerRoutesinPointerRouter. Local routes are used as described above; global routes are used to react to any interaction (i.e., to dismiss a tooltip).
Last updated
Was this helpful?