Gestures
Gestures, such as tap, slide and pinch, allow users to interact with your app by manipulating UI elements on the screen.
In NativeScript, View—the base class for all NativeScript UI elements—has on and off methods that let you subscribe or unsubscribe to all events and gestures recognized by the UI element.
As the first parameter, you pass an on or off method and the type of gesture you want to track. The second parameter is a function that is called each time the specified gesture is recognized. The function arguments contain additional information about the gesture, if applicable.
List of supported gestures in NativeScript:
Tap
Action: Briefly touch the screen.
Double Tap
Action: Two taps in a quick succession.
Touch
Action: A finger action was performed.
Swipe
Action: Swiftly slide your finger across the screen. Swipes are quick and affect the screen even after the finger is lifted off the screen.
Long Press
Action: Press your finger against the screen for a few moments.
Pan
Action: Press your finger down and immediately start moving it around. Pans are executed more slowly and allow for more precision and the screen stops responding as soon as the finger is lifted off it.
Pinch
Action: Touch the screen using two of your fingers, then move them towards each other or away from each other.
Rotation
Action: Touch the screen using two of your fingers, then rotate them simultaneously left or right.
Events
Each interactive view in NativeScript can access the gesture events it will raise on user interaction.
Name | Description |
---|---|
tap |
Emitted when the view is tapped. |
doubleTap |
Emitted when the view is double tapped. |
touch |
Emitted when the view is touched. Returns action state
from
TouchGestureEventData
|
longPress |
Emitted when the view is tapped and hold. Returns
state .
|
pan |
Emitted when the view is paned. Rewturns
deltaX and deltaY coordinates as
numbers.
|
pinch |
Emitted when the view is pinched. Returns
scale
|
swipe |
Emitted when the view is swiped left/right. Returns
direction as
SwipeDirection
|
API References
Native Component
Android | iOS |
---|---|
android.widget.Button | UIButton |