Higher-level state machines that interpret sequences of events as meaningful gestures.
The browser provides two separate event families for pointing—mouse events on desktop and touch events on mobile—with different semantics, coordinate systems, and lifecycle patterns. Without an abstraction layer, every interactive view needs parallel code paths for both input types, plus logic to prevent ghost clicks and handle edge cases where both fire simultaneously.
Gesture recognizers eliminate this complexity:
SvPanGestureRecognizer works identically whether driven by a mouse drag or a finger swipe—the view implements onPanBegin once and it works on every device.Mouse input naturally supports single-finger gestures (tap, pan, long-press, slide). Multi-finger gestures (pinch, rotation) require touch input or desktop Shift-click multi-touch emulation.
A gesture recognizer is a state machine attached to a view via addGestureRecognizer(). When gesture conditions are met, the recognizer sends delegate messages to the view:
acceptsGestureType(gesture) — Optional: can the view accept this gesture?
onGestureTypeBegin(gesture) — Gesture recognized and started
onGestureTypeMove(gesture) — Gesture in progress
onGestureTypeComplete(gesture) — Gesture completed successfully
onGestureTypeCancelled(gesture) — Gesture interrupted or cancelled| Recognizer Class | Detects | Primary Configuration Settors | |||
|---|---|---|---|---|---|
SvTapGestureRecognizer | Single or multi-tap | setNumberOfTapsRequired(), setNumberOfFingersRequired(), setMaxHoldPeriod() | |||
SvPanGestureRecognizer | Click-and-drag panning | setMinNumberOfFingersRequired(), setMaxNumberOfFingersAllowed() | |||
SvPinchGestureRecognizer | Two-finger pinch/zoom | Fixed to 2 fingers | |||
SvRotationGestureRecognizer | Two-finger rotation | Fixed to 2 fingers | |||
SvLongPressGestureRecognizer | Press-and-hold gesture | setTimePeriod() (default 500ms) | |||
SvSlideGestureRecognizer | Directional slide | `setDirection("left" | "right" | "up" | "down"), setMaxPerpendicularDistToBegin()` |
SvEdgePanGestureRecognizer | Pan starting at view edge | Subclasses for left, right, top, bottom edges | |||
SvScreenEdgePan | Pan starting at screen boundary | Subclasses for left, right, top, bottom screen boundaries |
// Convenience methods on SvDomView
view.addDefaultTapGesture(); // Single tap
view.addDefaultDoubleTapGesture(); // Double tap
view.addDefaultPanGesture(); // Drag panning
// Custom recognizer configuration
const gesture = SvLongPressGestureRecognizer.clone();
gesture.setTimePeriod(800); // 800ms hold requirement
view.addGestureRecognizer(gesture);
// View implements callback handler
onLongPressComplete (gesture) {
this.openContextMenu();
}SvGestureManager is a singleton that coordinates competing gestures globally across the entire view tree:
view.cancelAllGesturesExcept(panGesture).When a view is retired and unmounted from the DOM hierarchy, prepareToRetire() executes a 3-step cleanup pipeline:
removeAllGestureRecognizers(): Stops each recognizer, removes DOM listeners, and clears the view target.removeAllListeners(): Unbinds all element-level DOM event listeners.cancelAllTimeouts(): Clears any pending gesture hold timers.Gesture recognizers use addWeakTimeout() for internal hold delays. addWeakTimeout() holds only a WeakRef to the view target, enabling unmounted views to be reclaimed cleanly by JavaScript's garbage collector without timer leaks.
On desktop browsers, holding Shift while clicking simulates a second touch point. This allows testing multi-finger pinch, zoom, and rotation gestures using a standard mouse.