Ionic Gestures is a utility that allows developers to build custom gestures and interactions for their application in a platform agnostic manner. Developers do not need to be using a particular framework such as React or Angular, nor do they even need to be building an Ionic app! As long as developers have access to v5.0 or greater of Ionic Framework, they will have access to all of Ionic Animations.
Building complex gestures can be time consuming. Other libraries that provide custom gestures are often times too heavy handed and end up capturing mouse or touch events and not letting them propagate. This can result in other elements no longer being scrollable or clickable.
Developers using Ionic Core and TypeScript should install the latest version of
Developers using Angular should install the latest version of
@ionic/angular. Animations can be created via the
AnimationController dependency injection.
By default, gesture callbacks do not run inside of NgZone. Developers can either set the
runInsideAngularZone parameter to
true when creating a gesture,
or they can wrap their callbacks in an
Developers using React should install the latest version of
@ionic/react. Full React wrappers are coming soon!
Developers using Ionic Vue should install the latest version of
In this example, our app listens for gestures on the
.rectangle element. When a gesture movement is detected, the
onMove function is called, and our app logs the current gesture information.
In the example above, we want to be able to detect double clicks on an element. By setting our
0, we can ensure our gesture object can detect clicks. Additionally, we define a click threshold so that only 2 clicks that occur in quick succession count as a double click.
See our guide on implementing gesture animations: Gesture Animations with Ionic Animations
|el||The element to listen on for gestures.|
|disableScroll||If true, scrolling will be disabled on |
|direction||Limit gesture detection to movements along a certain axis.|
|gestureName||The name of the gesture to create.|
|gesturePriority||Gestures with higher priorities will override gestures with lower priorities. Useful for ensuring the multiple gestures do not collide with one another.|
|passive||If true, this will indicate that the gesture will never call |
|maxAngle||The maximum angle to allow when detecting a gesture.|
|threshold||Defines how much a pointer must move before the gesture starts.|
|blurOnStart||If true, the gesture will blur any active selectable element such as an input or a textarea before firing the |
|canStart||A callback that returns true if a gesture is allowed to start.|
|onWillStart||A callback that fires when a gesture is about to start. This is fired after |
|onStart||A callback that fires when a gesture has started.|
|onMove||A callback that fires when a gesture movement was detected.|
|onEnd||A callback that fires when a gesture has ended. This is usually when a pointer has been released.|
|notCaptured||A callback that fires when a gesture has not been captured. This usually happens when there is a conflicting gesture with a higher priority.|
|type||The type of gesture that was detected.|
|startX||The starting x coordinate of the gesture.|
|startY||The starting y coordinate of the gesture.|
|startTimeStamp||The timestamp at which the gesture was started.|
|currentX||The current x coordinate of the gesture.|
|currentY||The current y coordinate of the gesture.|
|velocityX||How fast the gesture is currently moving on the x axis.|
|velocityY||How fast the gesture is currently moving on the y axis.|
|deltaX||How much the gesture has moved on the x axis since it started.|
|deltaY||How much the gesture has moved on the y axis since it started.|
|timeStamp||The current timestamp of the gesture.|
|event||The native event dispatched by the browser. See UIEvent for more information.|
|data||Any data specified by the user. This can be set and read in any of the callbacks.|
enable(enable: boolean = true) => void#
Enable or disable the gesture.
destroy() => void#
Destroy the gesture instance and stop listening on the target element.