UNPKG

@nativescript/core

Version:

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

277 lines (276 loc) • 6.93 kB
import type { GesturesObserver as GesturesObserverDefinition } from '.'; import type { View } from '../core/view'; import type { EventData } from '../../data/observable'; export * from './touch-manager'; /** * Events emitted during gesture lifecycle */ export declare enum GestureEvents { /** * When the gesture is attached to the view * Provides access to the native gesture recognizer for further customization */ gestureAttached = "gestureAttached", /** * When a touch down was detected */ touchDown = "touchDown", /** * When a touch up was detected */ touchUp = "touchUp" } /** * Defines an enum with supported gesture types. */ export declare enum GestureTypes { /** * Denotes tap (click) gesture. */ tap = 1, /** * Denotes double tap gesture. */ doubleTap = 2, /** * Denotes pinch gesture. */ pinch = 4, /** * Denotes pan gesture. */ pan = 8, /** * Denotes swipe gesture. */ swipe = 16, /** * Denotes rotation gesture. */ rotation = 32, /** * Denotes long press gesture. */ longPress = 64, /** * Denotes touch action. */ touch = 128 } /** * Defines an enum with supported gesture states. */ export declare enum GestureStateTypes { /** * Gesture canceled. */ cancelled = 0, /** * Gesture began. */ began = 1, /** * Gesture changed. */ changed = 2, /** * Gesture ended. */ ended = 3 } /** * Defines an enum for swipe gesture direction. */ export declare enum SwipeDirection { /** * Denotes right direction for swipe gesture. */ right = 1, /** * Denotes left direction for swipe gesture. */ left = 2, /** * Denotes up direction for swipe gesture. */ up = 4, /** * Denotes down direction for swipe gesture. */ down = 8 } /** * Defines a touch action */ export declare enum TouchAction { /** * Down action. */ down = "down", /** * Up action. */ up = "up", /** * Move action. */ move = "move", /** * Cancel action. */ cancel = "cancel" } /** * Provides gesture event data. */ export interface GestureEventData extends EventData { /** * Gets the type of the gesture. */ type: GestureTypes; /** * Gets the view which originates the gesture. */ view: View; /** * Gets the underlying native iOS specific [UIGestureRecognizer](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIGestureRecognizer_Class/). */ ios: any; /** * Gets the underlying native android specific [gesture detector](http://developer.android.com/reference/android/view/GestureDetector.html). */ android: any; } /** * Provides gesture event data. */ export interface TapGestureEventData extends GestureEventData { /** * Gets the number of pointers in the event. */ getPointerCount(): number; /** * Gets the X coordinate of this event inside the view that triggered the event */ getX(): number; /** * Gets the Y coordinate of the event inside the view that triggered the event. */ getY(): number; } /** * Provides gesture event data. */ export interface TouchGestureEventData extends TapGestureEventData { /** * Gets action of the touch. Possible values: 'up', 'move', 'down', 'cancel' */ action: 'up' | 'move' | 'down' | 'cancel'; /** * Gets the pointers that triggered the event. * Note: In Android there is aways only one active pointer. */ getActivePointers(): Array<Pointer>; /** * Gets all pointers. */ getAllPointers(): Array<Pointer>; } /** * Pointer is an object representing a finger (or other object) that is touching the screen. */ export interface Pointer { /** * The id of the pointer. */ android: any; /** * The UITouch object associated to the touch */ ios: any; /** * Gets the X coordinate of the pointer inside the view that triggered the event. */ getX(): number; /** * Gets the Y coordinate of the pointer inside the view that triggered the event. */ getY(): number; /** * Gests the X coordinate of the pointer inside the view that triggered the event. * @returns The X coordinate in _Device Pixels_. */ getXPixels(): number; /** * Gets the X coordinate of the pointer inside the view that triggered the event. * @returns The X coordinate in _Device Independent Pixels_. */ getXDIP(): number; /** * Gests the Y coordinate of the pointer inside the view that triggered the event. * @returns The Y coordinate in _Device Pixels_. */ getYPixels(): number; /** * Gets the Y coordinate of the pointer inside the view that triggered the event. * @returns The Y coordinate in _Device Independent Pixels_. */ getYDIP(): number; } /** * Provides gesture event data. */ export interface GestureEventDataWithState extends GestureEventData { state: number; } /** * Provides gesture event data for pinch gesture. */ export interface PinchGestureEventData extends GestureEventDataWithState { scale: number; getFocusX(): number; getFocusY(): number; } /** * Provides gesture event data for swipe gesture. */ export interface SwipeGestureEventData extends GestureEventData { direction: SwipeDirection; } /** * Provides gesture event data for pan gesture. */ export interface PanGestureEventData extends GestureEventDataWithState { deltaX: number; deltaY: number; } /** * Provides gesture event data for rotation gesture. */ export interface RotationGestureEventData extends GestureEventDataWithState { rotation: number; } /** * Returns a string representation of a gesture type. * @param type - Type of the gesture. * @param separator(optional) - Text separator between gesture type strings. */ export declare function toString(type: GestureTypes, separator?: string): string; /** * Returns a gesture type enum value from a string (case insensitive). * @param type - A string representation of a gesture type (e.g. Tap). */ export declare function fromString(type: string): GestureTypes; export declare abstract class GesturesObserverBase implements GesturesObserverDefinition { private _callback; private _target; private _context; type: GestureTypes; get callback(): (args: GestureEventData) => void; get target(): View; get context(): any; constructor(target: View, callback: (args: GestureEventData) => void, context: any); abstract androidOnTouchEvent(motionEvent: android.view.MotionEvent): any; abstract observe(type: GestureTypes): any; disconnect(): void; }