Gestures

Detecting user gestures requires the "ui/gestures" module.

import * as gestures from "tns-core-modules/ui/gestures";

Double Tap

var label = new labelModule.Label();
var observer = label.on(gestures.GestureTypes.doubleTap, function (args: gestures.GestureEventData) { 
    console.log("Double Tap");
});

Double Tap

var label = new labelModule.Label();
var observer = label.on("doubleTap", function (args: gestures.GestureEventData) {
    console.log("Double Tap");
});

Long Press

var label = new labelModule.Label();
var observer = label.on(gestures.GestureTypes.longPress, function (args: gestures.GestureEventData) {
    console.log("Long Press");
});

Long Press

var label = new labelModule.Label();
var observer = label.on("longPress", function (args: gestures.GestureEventData) {
    console.log("Long Press");
});

Pan

var label = new labelModule.Label();
var observer = label.on(gestures.GestureTypes.pan, function (args: gestures.PanGestureEventData) {
    console.log("Pan deltaX:" + args.deltaX + "; deltaY:" + args.deltaY + ";");
});

Pan

var label = new labelModule.Label();
var observer = label.on("pan", function (args: gestures.PanGestureEventData) {
    console.log("Pan deltaX:" + args.deltaX + "; deltaY:" + args.deltaY + ";");
});

Pinch

var label = new labelModule.Label();
var observer = label.on(gestures.GestureTypes.pinch, function (args: gestures.PinchGestureEventData) {
    console.log("Pinch scale: " + args.scale);
});

Pinch

var label = new labelModule.Label();
var observer = label.on("pinch", function (args: gestures.PinchGestureEventData) {
    console.log("Pinch scale: " + args.scale);
});

Rotation

var label = new labelModule.Label();
var observer = label.on(gestures.GestureTypes.rotation, function (args: gestures.RotationGestureEventData) {
    console.log("Rotation: " + args.rotation);
});

Rotation

var label = new labelModule.Label();
var observer = label.on("rotation", function (args: gestures.RotationGestureEventData) {
    console.log("Rotation: " + args.rotation);
});

Swipe

var label = new labelModule.Label();
var observer = label.on(gestures.GestureTypes.swipe, function (args: gestures.SwipeGestureEventData) {
    console.log("Swipe direction: " + args.direction);
});

Swipe

var label = new labelModule.Label();
var observer = label.on("swipe", function (args: gestures.SwipeGestureEventData) {
    console.log("Swipe direction: " + args.direction);
});

Tap

var label = new labelModule.Label();
var observer = label.on(gestures.GestureTypes.tap, function (args: gestures.GestureEventData) {
    console.log("Tap");
});

Tap

var label = new labelModule.Label();
var observer = label.on("tap", function (args: gestures.GestureEventData) {
    console.log("Tap");
});

Stop observing

var label = new labelModule.Label();
var observer = label.on(gestures.GestureTypes.tap, function (args: gestures.GestureEventData) {
    console.log("Tap");
});
observer.disconnect();

Multiple gestures

var label = new labelModule.Label();
var observer = label.on(gestures.GestureTypes.tap | gestures.GestureTypes.doubleTap | gestures.GestureTypes.longPress, function (args: gestures.GestureEventData) {
    console.log("Event: " + args.eventName);
});

Multiple gestures as comma separated string

var label = new labelModule.Label();
var observer = label.on("tap, doubleTap, longPress", function (args: gestures.GestureEventData) {
    console.log("Event: " + args.eventName);
});

Events combined with gestures as comma separated string

var label = new labelModule.Label();
var observer = label.on("loaded, tap, longPress", function (args: gestures.GestureEventData) {
    console.log("Event: " + args.eventName);
});

Stay connected with NativeScript

(expect a newsletter every 4-8 weeks)

NativeScript
NativeScript is licensed under the Apache 2.0 license .
© Progress Software Corporation. All Rights Reserved.