Gesture types
The six gesture classes, their options, the callbacks each supports and the event each passes. import { PanGesture, TapGesture } from '@blotch/angular-lynx';
Usage
Create a gesture with new, chain its options and callbacks, then bind it with [lynxGesture]. Every option and callback returns the gesture.
Common to every gesture
- When each one fires is on Lifecycle.
- A
—default below means AngularLynx doesn't send the option, so Lynx uses its own default. - You never need an empty
onBegin. Lynx's fling handler, and its pan handler before Lynx 3.9, skiponStartandonEndunless anonBeginis registered. So AngularLynx registers one on every pan, fling, pinch and rotation that has none.
Positions: x and absoluteX
x,y: the finger's position from the top-left corner of the element that has the gesture.absoluteX,absoluteY: the finger's position from the top-left corner of thepage, the root of your app.translationX,translationY(pan only): how far the finger has moved since it touched down. AngularLynx works it out fromabsoluteXandabsoluteY, because Lynx reports only positions.
TapGesture
Recognizes a quick touch and release.
Callbacks: onBegin, onStart, onEnd, onTouchesDown, onTouchesUp. onEnd fires only when the tap succeeded. With numberOfTaps, onStart and onEnd fire on the last tap only.
The taps of a double tap must each succeed and land within maxDistance of the first. Each touch must begin within 500 ms of the last one lifting. No Lynx platform counts taps, so AngularLynx does, from the single taps Lynx recognizes.
So a single tap on the same element can't wait for a double tap to fail: Gesture.Exclusive(doubleTap, singleTap) doesn't work. Gestures on one element race, so only one of the two ever runs. To handle both, put them in Gesture.Simultaneous, and let the single tap's action also suit the first tap of a double one.
PanGesture
Tracks a finger dragging across the element. onUpdate fires on every move.
A pointer is one finger touching the screen. minPointers(2) means the gesture needs two fingers.
An offset is a range of movement from where the finger touched down, in pixels, as in react-native-gesture-handler:
- A pair is the range itself.
activeOffsetX([-20, 20])starts the pan after 20 pixels left or right. - A positive number is open to the left (or up).
activeOffsetX(20)starts the pan only after 20 pixels right. - A negative number is open to the right (or down).
activeOffsetX(-20)starts the pan only after 20 pixels left.
With active offsets on both axes, leaving either range starts the pan.
A horizontal pan inside a vertical scroll view, which lets the scroll view have the vertical drags:
- A fail offset counts only until the pan starts. Without an active offset, the pan starts at
minDistance, which is0. So give it an active offset or aminDistance. - How AngularLynx enforces these, and what that means for other gestures on the element, is under Options AngularLynx enforces.
Callbacks: all six.
translationXis measured from where the finger touched down, whenonBeginfires. So atonStartit already includes the distance moved before the pan activated, such as the 10 pixels ofminDistance(10).velocityXandvelocityYare in pixels a second, positive to the right and down, averaged over the last 100 ms. Lynx doesn't send velocity: AngularLynx works it out from the finger's positions and the events' timestamps.- In
onEnd, they're the speed the finger let go at, and0if it stopped before lifting. So they can decide whether a swiped card flies off or a dragged sheet closes:
FlingGesture
Follows the momentum of a quick drag after the finger lifts, the way a list keeps scrolling after a flick.
Give the element a pan as well, with Gesture.Simultaneous. Lynx flings only the element that won the touch. A fling ignores the touch until the finger lifts, so on its own it rarely fires.
A fling goes the way its first frame moves, along whichever axis it moves further. With direction set:
- A fling another way runs none of its callbacks, and neither does one too slow to move.
onBeginfires on the first frame, with that frame'sonUpdate, rather than when the finger lifts.
Callbacks:
onBeginfires when the finger lifts.onUpdatefires on every frame of the fling. The event'sdeltaXanddeltaYsay how far it moved since the last frame.onEndfires when the fling stops, or as soon as the finger lifts if it was too slow to fling.onStartdoesn't fire: Lynx starts a fling that follows a touch without activating it.
velocityXandvelocityYare how fast the fling still carries, in pixels a second, in the swipe's direction like a pan's. They start near the release speed and fall to about0as it slows.- In
onBegin, they're0, since the fling hasn't moved yet. Read the speed the finger let go at from the pan'sonEnd. - Lynx's
deltaXanddeltaYare on the event too, but the type doesn't declare them yet. Read them fromevent.params.
LongPressGesture
Recognizes a finger held still on the element.
Callbacks: onBegin, onStart, onEnd, onTouchesDown, onTouchesUp. onStart fires once the hold is long enough. onEnd fires when the finger lifts after a successful long press.
PinchGesture and RotationGesture
Two-finger zoom and rotate. Neither class has options.
No Lynx platform has a native pinch or rotation handler, so these gestures never fire, on a device or in the web preview. You can still compose them, for example Gesture.Simultaneous(pan, pinch), but drive zoom from a pan or on-screen buttons for now.
Callbacks: all six.
Why the defaults are sent
Once a gesture sends any option, Lynx reads every option it leaves out as 0. Without the defaults, a tap that set only numberOfTaps would get a maxDuration of 0, and fail the instant a finger lands.
So TapGesture, LongPressGesture and PanGesture always send their full default set, shown above. Every other gesture sends { enabled: true }. You don't need to set them yourself.
Options AngularLynx enforces
Lynx 4.1's native handlers read only a tap's maxDuration and maxDistance, a long press's minDuration and maxDistance, and a pan's minDistance. AngularLynx enforces the others itself, the same way on a device and in the web preview:
enabled(false):[lynxGesture]doesn't register a disabled gesture with Lynx, so it can't run a callback or take a touch, and registers it again when it's enabled.- A pan's
activeOffsetX,activeOffsetY,failOffsetXandfailOffsetY: AngularLynx holdsonStartandonUpdateback until the pan passes an active offset, and calls the state manager'sfail()when it passes a fail offset first. - A fling's
direction: AngularLynx holdsonBeginback until the first frame shows the fling's direction, and fails a fling that goes another way. - A tap's
numberOfTaps: AngularLynx counts the taps Lynx recognizes, and runsonStartandonEndon the last one.
Lynx doesn't know about the pan offsets, so they only decide when your callbacks run:
- To Lynx, a pan is active from
minDistanceon. While it waits for an active offset, it already holds the touch, and fails the element's other gestures that aren't simultaneous with it. - A vertical pan beside a horizontal one on the same element can't wait for its offset. Whichever Lynx activates first wins. Put them on different elements, or use one pan and read
translationXandtranslationY. minPointers,maxPointersand a fling'snumberOfPointersstill do nothing. Lynx follows one finger at a time, and doesn't say how many are down.- An option set after the gesture is bound takes effect at once.
[lynxGesture]registers the gesture with Lynx again.
If no gesture fires
Lynx ignores every gesture, with no error, unless the bundle was built with enableNewGesture: true. AngularLynx turns it on by default. If you pass plugin options in lynx.config.ts, don't set it to false.
Types
Every event also has Lynx's raw fields as properties, such as pageX and clientX. params holds the same fields. GestureState is on Lifecycle.
