UNPKG

@nativescript/core

Version:

A JavaScript library providing an easy to use api for interacting with iOS and Android platform APIs.

227 lines • 6.14 kB
export * from './touch-manager'; /** * Events emitted during gesture lifecycle */ export var GestureEvents; (function (GestureEvents) { /** * When the gesture is attached to the view * Provides access to the native gesture recognizer for further customization */ GestureEvents["gestureAttached"] = "gestureAttached"; /** * When a touch down was detected */ GestureEvents["touchDown"] = "touchDown"; /** * When a touch up was detected */ GestureEvents["touchUp"] = "touchUp"; })(GestureEvents || (GestureEvents = {})); /** * Defines an enum with supported gesture types. */ export var GestureTypes; (function (GestureTypes) { /** * Denotes tap (click) gesture. */ GestureTypes[GestureTypes["tap"] = 1] = "tap"; /** * Denotes double tap gesture. */ GestureTypes[GestureTypes["doubleTap"] = 2] = "doubleTap"; /** * Denotes pinch gesture. */ GestureTypes[GestureTypes["pinch"] = 4] = "pinch"; /** * Denotes pan gesture. */ GestureTypes[GestureTypes["pan"] = 8] = "pan"; /** * Denotes swipe gesture. */ GestureTypes[GestureTypes["swipe"] = 16] = "swipe"; /** * Denotes rotation gesture. */ GestureTypes[GestureTypes["rotation"] = 32] = "rotation"; /** * Denotes long press gesture. */ GestureTypes[GestureTypes["longPress"] = 64] = "longPress"; /** * Denotes touch action. */ GestureTypes[GestureTypes["touch"] = 128] = "touch"; })(GestureTypes || (GestureTypes = {})); /** * Defines an enum with supported gesture states. */ export var GestureStateTypes; (function (GestureStateTypes) { /** * Gesture canceled. */ GestureStateTypes[GestureStateTypes["cancelled"] = 0] = "cancelled"; /** * Gesture began. */ GestureStateTypes[GestureStateTypes["began"] = 1] = "began"; /** * Gesture changed. */ GestureStateTypes[GestureStateTypes["changed"] = 2] = "changed"; /** * Gesture ended. */ GestureStateTypes[GestureStateTypes["ended"] = 3] = "ended"; })(GestureStateTypes || (GestureStateTypes = {})); /** * Defines an enum for swipe gesture direction. */ export var SwipeDirection; (function (SwipeDirection) { /** * Denotes right direction for swipe gesture. */ SwipeDirection[SwipeDirection["right"] = 1] = "right"; /** * Denotes left direction for swipe gesture. */ SwipeDirection[SwipeDirection["left"] = 2] = "left"; /** * Denotes up direction for swipe gesture. */ SwipeDirection[SwipeDirection["up"] = 4] = "up"; /** * Denotes down direction for swipe gesture. */ SwipeDirection[SwipeDirection["down"] = 8] = "down"; })(SwipeDirection || (SwipeDirection = {})); /** * Defines a touch action */ export var TouchAction; (function (TouchAction) { /** * Down action. */ TouchAction["down"] = "down"; /** * Up action. */ TouchAction["up"] = "up"; /** * Move action. */ TouchAction["move"] = "move"; /** * Cancel action. */ TouchAction["cancel"] = "cancel"; })(TouchAction || (TouchAction = {})); /** * Returns a string representation of a gesture type. * @param type - Type of the gesture. * @param separator(optional) - Text separator between gesture type strings. */ export function toString(type, separator) { const types = new Array(); if (type & GestureTypes.tap) { types.push('tap'); } if (type & GestureTypes.doubleTap) { types.push('doubleTap'); } if (type & GestureTypes.pinch) { types.push('pinch'); } if (type & GestureTypes.pan) { types.push('pan'); } if (type & GestureTypes.swipe) { types.push('swipe'); } if (type & GestureTypes.rotation) { types.push('rotation'); } if (type & GestureTypes.longPress) { types.push('longPress'); } if (type & GestureTypes.touch) { types.push('touch'); } return types.join(separator); } // NOTE: toString could return the text of multiple GestureTypes. // Souldn't fromString do split on separator and return multiple GestureTypes? /** * Returns a gesture type enum value from a string (case insensitive). * @param type - A string representation of a gesture type (e.g. Tap). */ export function fromString(type) { const t = type.trim().toLowerCase(); if (t === 'tap') { return GestureTypes.tap; } else if (t === 'doubletap') { return GestureTypes.doubleTap; } else if (t === 'pinch') { return GestureTypes.pinch; } else if (t === 'pan') { return GestureTypes.pan; } else if (t === 'swipe') { return GestureTypes.swipe; } else if (t === 'rotation') { return GestureTypes.rotation; } else if (t === 'longpress') { return GestureTypes.longPress; } else if (t === 'touch') { return GestureTypes.touch; } return undefined; } export class GesturesObserverBase { get callback() { return this._callback; } get target() { return this._target; } get context() { return this._context; } constructor(target, callback, context) { this._target = target; this._callback = callback; this._context = context; } disconnect() { // remove gesture observer from map if (this.target) { const list = this.target.getGestureObservers(this.type); if (list && list.length > 0) { for (let i = 0; i < list.length; i++) { if (list[i].callback === this.callback) { break; } } list.length = 0; this.target._gestureObservers[this.type] = undefined; delete this.target._gestureObservers[this.type]; } } this._target = null; this._callback = null; this._context = null; } } //# sourceMappingURL=gestures-common.js.map