I often see the term swipe gestures in reference to my phone in the settings, but don’t have any options to enable it or use it and it doesn’t explain what it is. I finally found out how to come across it via the Internet. It was hard and I don’t know how, but hey here is it’s like they’re talking to an app developer, and that’s what I’m hacked with his apps.
Prompt Dialog Result Properties #
The result are received in the dialog resolved promise after the user closes or dismisses the dialog.
API References #
Native Component #
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.
- on( type Number | name String | names Comma separated String, callback Function… **)
- type – Number | name – String | names – Comma separated String
- callback – Function(args GestureEventData)
- off( type Number | name String | names Comma separated String, callback Function… **)
- type – Number | name – String | names – Comma separated String
- callback – Function(args GestureEventData)
Tap #
Action: Briefly touch the screen.
ANGULARPLAIN
TSHTML
`import { GestureEventData } from ‘@nativescript/core’
onTap(args: GestureEventData) { console.log(“Tap!”); }`
Double Tap #
Action: Two taps in a quick succession.
ANGULARPLAIN
TSHTML
`import { GestureEventData } from ‘@nativescript/core’
onDoubleTap(args: GestureEventData) { console.log(“DoubleTap!”); }`
Possible implementation:
- Scale up the object with a predefined percentage, centered around the double-tapped region. If a user keeps repeating the double tap gesture, continue to scale up until the maximum scale is reached.
- Scale up the smallest targetable view or returns it to its original scale in nested views.
- Select text.
Long Press #
Action: Press your finger against the screen for a few moments.
ANGULARPLAIN
TSHTML
`import { GestureEventData } from ‘@nativescript/core’
onLongPress(args: GestureEventData) { console.log(“LongPress!”); }`
Possible implementation: Select one or more items in a view and act upon the data using a contextual action bar. Enter data selection mode. Avoid using long press for displaying contextual menus.
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.
ANGULARPLAIN
TSHTML
`import { SwipeGestureEventData } from ‘@nativescript/core’
onSwipe(args: SwipeGestureEventData) { console.log(“Swipe Direction: ” + args.direction); }`
Possible implementation: Navigate between views in the same hierarchy.
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.
ANGULARPLAIN
TSHTML
`import { PanGestureEventData } from ‘@nativescript/core’
onPan(args: PanGestureEventData) { console.log(“Pan delta: [” + args.deltaX + “, ” + args.deltaY + “] state: ” + args.state); }`
Pinch #
Action: Touch the screen using two of your fingers, then move them towards each other or away from each other.
ANGULARPLAIN
TSHTML
`import { PinchGestureEventData } from ‘@nativescript/core’
onPinch(args: PinchGestureEventData) { console.log(“Pinch scale: ” + args.scale + ” state: ” + args.state); }`
Possible implementation: Zoom into content or out of content.
Rotation #
Action: Touch the screen using two of your fingers, then rotate them simultaneously left or right.
ANGULARPLAIN
TSHTML
`import { RotationGestureEventData } from ‘@nativescript/core’
onRotate(args: RotationGestureEventData) { console.log(“Rotate angle: ” + args.rotation + ” state: ” + args.state); }`
Touch #
Action: A finger action was performed.
This is a general purpose gesture that is triggered whenever a pointer (usually a finger) has performed a touch action (up, down, move or cancel). TouchGestureEventData
provides information about all the pointers currently on the screen and their position inside the view that triggered the event.
ANGULARPLAIN
TSHTML
`import { TouchGestureEventData } from ‘@nativescript/core’
onTouch(args: TouchGestureEventData) { console.log( “Touch point: [” + args.getX() + “, ” + args.getY() + “] activePointers: ” + args.getActivePointers().length); }`
Subscribing to Multiple Gestures and Events #
Since the release of NativeScript 1.3, when subscribing you can use gestures names, comma separated gestures names and/or even mix with events.
PLAIN
`import { GestureEventData, Label } from ‘@nativescript/core’
var label = new Label() label.on(‘loaded, tap, doubleTap, longPress’, (args: GestureEventData) => { console.log(‘Event: ‘ + args.eventName + ‘, sender: ‘ + args.object) })`
Gesture Manipulations #
In some scenarios, you would want to disable the user interaction or to create more complex UI where some gestures are passing through the parents of the actual interactive zone. NativeScript provides some specific properties for handling similar cases as follows:
isUserInteractionEnabled
– Gets or sets a boolean value indicating whether the user can interact with the view. Does not affect the appearance of the view. The default value istrue
.isEnabled
– Gets or sets a boolean value indicating whether the view is enabled. Affects the appearance of the view. The default value istrue
.isPassThroughParentEnabled
– Gets or sets a value indicating whether touch events should pass through to a parent view of the layout container in case an interactive child view did not handle the event. Does not affect the appearance of the view. The default value isfalse
.