Gestures
Attach native gestures to an element, and control how several gestures on one element compete. import { Gesture, LynxGestureDetector } from '@blotch/angular-lynx';
Usage
- Import
LynxGestureDetectorin your component, next toLYNX_ELEMENTS(see Elements). - Build each gesture once, as a
readonlyfield. The directive re-registers every gesture when the input changes, so a getter that returns a new gesture each time re-registers on every render. - Each gesture class and its options are on Gesture types. The callbacks are on Lifecycle.
API
[lynxGesture]
The directive's selector is [lynxGesture]. It takes one of:
An array can't hold a ComposedGesture, and the helpers don't nest. When the element is destroyed, its gestures are removed.
Gesture.Exclusive(...gestures)
Tries the gestures in order. Each one waits until every gesture before it has failed, so the first one listed wins ties.
Gesture.Simultaneous(...gestures)
Lets every gesture be active at the same time. Without it, only one gesture on an element is active at once.
Gesture.Race(...gestures)
Sets no relations: the first gesture to be recognized wins. It behaves like passing the same gestures as an array.
waitFor(...gestures)
Holds this gesture back until all the listed gestures have failed. Gesture.Exclusive sets this for you.
simultaneousWith(...gestures)
Lets this gesture be active at the same time as the listed gestures. Gesture.Simultaneous sets this on every pair.
continueWith(...gestures)
Lets this gesture activate after the listed gestures end successfully, such as a drag that follows a long press.
enabled(value)
Turns the gesture on or off. Gestures start enabled.
These four methods are on every gesture class. TSelf is the gesture's own class, so calls chain. They change the gesture they're called on, as Gesture.Exclusive and Gesture.Simultaneous do.
Constraints
- Callbacks run on the main thread, inside the native gesture. Changing signals there is safe.
- Keep the element count fixed during a gesture. Adding or removing elements from a callback can crash the app. Defer it with
setTimeout, as thesetTimeoutrule explains. - Gestures need the
enableNewGesturebuild option, which is on by default. See Gesture types.
Types
GestureEvent and GestureType are on Gesture types.
