For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /api/gestures/gesture-types.md.

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

readonly pan = new PanGesture()
  .minDistance(10) // options
  .onUpdate((event) => this.offset.set(event.translationX)); // callbacks

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

OptionTypeDefaultDescription
enabled(value)booleantrueTurns the gesture off and on, at any time. A disabled gesture runs no callbacks and takes no touches from others
CallbackTap, LongPressPan, Fling, Pinch, Rotation
onBeginYesYes
onStartYesYes
onUpdateNoYes
onEndYesYes
onTouchesDownYesYes
onTouchesUpYesYes
  • 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, skip onStart and onEnd unless an onBegin is 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 the page, the root of your app.
  • translationX, translationY (pan only): how far the finger has moved since it touched down. AngularLynx works it out from absoluteX and absoluteY, because Lynx reports only positions.

TapGesture

Recognizes a quick touch and release.

readonly tap = new TapGesture().maxDistance(20).onEnd((event) => this.select(event.x));
OptionTypeDefaultDescription
maxDuration(ms)number500The longest the finger can stay down. A longer touch fails
maxDistance(px)number10How far the finger can move. Moving further fails the tap
numberOfTaps(n)number1How many taps in a row it takes: 2 is a double tap

Callbacks: onBegin, onStart, onEnd, onTouchesDown, onTouchesUp. onEnd fires only when the tap succeeded. With numberOfTaps, onStart and onEnd fire on the last tap only.

interface TapGestureEvent extends GestureEvent {
  x: number;
  y: number;
}
readonly like = new TapGesture().numberOfTaps(2).onEnd(() => this.toggleLike());
Double taps

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.

readonly pan = new PanGesture()
  .minDistance(10)
  .onUpdate((event) => this.offset.set(event.translationX))
  .onEnd(() => this.settle());

A pointer is one finger touching the screen. minPointers(2) means the gesture needs two fingers.

OptionTypeDefaultDescription
minDistance(px)number0How far the finger moves before the pan activates. 0 activates at once
activeOffsetX(offset)number | [number, number]—The pan starts once the horizontal movement leaves this range
activeOffsetY(offset)number | [number, number]—The same, vertically
failOffsetX(offset)number | [number, number]—The pan fails once the horizontal movement leaves this range before it starts
failOffsetY(offset)number | [number, number]—The same, vertically. Lets a scroll view take a vertical drag
minPointers(n)number—Does nothing: Lynx follows one finger at a time
maxPointers(n)number—Does nothing, as minPointers

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:

readonly swipe = new PanGesture()
  .activeOffsetX([-20, 20])
  .failOffsetY([-10, 10])
  .onUpdate((event) => this.offset.set(event.translationX));
  • A fail offset counts only until the pan starts. Without an active offset, the pan starts at minDistance, which is 0. So give it an active offset or a minDistance.
  • How AngularLynx enforces these, and what that means for other gestures on the element, is under Options AngularLynx enforces.

Callbacks: all six.

interface PanGestureEvent extends GestureEvent {
  translationX: number;
  translationY: number;
  velocityX: number;
  velocityY: number;
}
  • translationX is measured from where the finger touched down, when onBegin fires. So at onStart it already includes the distance moved before the pan activated, such as the 10 pixels of minDistance(10).
  • velocityX and velocityY are 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, and 0 if it stopped before lifting. So they can decide whether a swiped card flies off or a dragged sheet closes:
readonly swipe = new PanGesture()
  .onUpdate((event) => this.offset.set(event.translationX))
  .onEnd((event) => {
    if (Math.abs(event.velocityX) > 800) this.dismiss(Math.sign(event.velocityX));
    else this.offset.set(0);
  });

FlingGesture

Follows the momentum of a quick drag after the finger lifts, the way a list keeps scrolling after a flick.

import { FlingGesture, Gesture, PanGesture } from '@blotch/angular-lynx';

readonly drag = new PanGesture().onUpdate((event) => this.follow(event));
readonly fling = new FlingGesture()
  .onUpdate((event) => this.coast(event.params?.['deltaX'] as number))
  .onEnd(() => this.settle());

// Bind this one with [lynxGesture]="gesture".
readonly gesture = Gesture.Simultaneous(this.drag, this.fling);

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.

OptionTypeDefaultDescription
direction(dir)FlingDirectionanyThe directions to recognize. Combine them with |
numberOfPointers(n)number—Does nothing: Lynx follows one finger at a time

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.
  • onBegin fires on the first frame, with that frame's onUpdate, rather than when the finger lifts.
readonly fling = new FlingGesture()
  .direction(FlingDirection.LEFT | FlingDirection.RIGHT)
  .onBegin(() => this.flip());

Callbacks:

  • onBegin fires when the finger lifts.
  • onUpdate fires on every frame of the fling. The event's deltaX and deltaY say how far it moved since the last frame.
  • onEnd fires when the fling stops, or as soon as the finger lifts if it was too slow to fling.
  • onStart doesn't fire: Lynx starts a fling that follows a touch without activating it.
interface FlingGestureEvent extends GestureEvent {
  velocityX: number;
  velocityY: number;
}
  • velocityX and velocityY are 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 about 0 as it slows.
  • In onBegin, they're 0, since the fling hasn't moved yet. Read the speed the finger let go at from the pan's onEnd.
  • Lynx's deltaX and deltaY are on the event too, but the type doesn't declare them yet. Read them from event.params.

LongPressGesture

Recognizes a finger held still on the element.

readonly hold = new LongPressGesture().minDuration(800).onStart(() => this.openMenu());
OptionTypeDefaultDescription
minDuration(ms)number500How long the finger must stay down before the gesture activates
maxDistance(px)number10How far the finger can drift. Drifting further fails it

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.

interface LongPressGestureEvent extends GestureEvent {
  x: number;
  y: number;
  duration: number;
}

PinchGesture and RotationGesture

Two-finger zoom and rotate. Neither class has options.

These don't fire yet

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.

interface PinchGestureEvent extends GestureEvent {
  scale: number; // 1 means unchanged
  velocity: number;
}

interface RotationGestureEvent extends GestureEvent {
  rotation: number;
  velocity: number;
}

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, failOffsetX and failOffsetY: AngularLynx holds onStart and onUpdate back until the pan passes an active offset, and calls the state manager's fail() when it passes a fail offset first.
  • A fling's direction: AngularLynx holds onBegin back 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 runs onStart and onEnd on 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 minDistance on. 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 translationX and translationY.
  • minPointers, maxPointers and a fling's numberOfPointers still 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

interface GestureEvent {
  state?: GestureState; // usually absent: the callback tells you the phase
  absoluteX?: number;
  absoluteY?: number;
  params?: Record<string, unknown>; // Lynx's raw event fields
}

enum FlingDirection {
  RIGHT = 1,
  LEFT = 2,
  UP = 4,
  DOWN = 8,
}

enum GestureType {
  PAN = 0,
  FLING = 1,
  DEFAULT = 2,
  TAP = 3,
  LONGPRESS = 4,
  ROTATION = 5,
  PINCH = 6,
  NATIVE = 7,
}

Every event also has Lynx's raw fields as properties, such as pageX and clientX. params holds the same fields. GestureState is on Lifecycle.