@nativescript/core
Version:
A JavaScript library providing an easy to use api for interacting with iOS and Android platform APIs.
302 lines (301 loc) • 7.7 kB
TypeScript
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
*
* @nsEvent {GestureEventData} gestureAttached
*/
gestureAttached = "gestureAttached",
/**
* When a touch down was detected
*
* @nsEvent touchDown
*/
touchDown = "touchDown",
/**
* When a touch up was detected
*
* @nsEvent touchUp
*/
touchUp = "touchUp"
}
/**
* Defines an enum with supported gesture types.
*/
export declare enum GestureTypes {
/**
* Denotes tap (click) gesture.
*
* @nsEvent {TapGestureEventData} tap
*/
tap = 1,
/**
* Denotes double tap gesture.
*
* @nsEvent {TapGestureEventData} doubleTap
*/
doubleTap = 2,
/**
* Denotes pinch gesture.
*
* @nsEvent {PinchGestureEventData} pinch
*/
pinch = 4,
/**
* Denotes pan gesture.
*
* @nsEvent {PanGestureEventData} pan
*/
pan = 8,
/**
* Denotes swipe gesture.
*
* @nsEvent {SwipeGestureEventData} swipe
*/
swipe = 16,
/**
* Denotes rotation gesture.
*
* @nsEvent {RotationGestureEventData} rotate
*/
rotation = 32,
/**
* Denotes long press gesture.
*
* @nsEvent {GestureEventDataWithState} longPress
*/
longPress = 64,
/**
* Denotes touch action.
*
* @nsEvent {TouchGestureEventData} touch
*/
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 - The singular type of the gesture. Looks for an exact match, so
* passing plural types like `GestureTypes.tap & GestureTypes.doubleTap` will
* simply return undefined.
*/
export declare function toString(type: GestureTypes): (typeof GestureTypes)[GestureTypes] | undefined;
/**
* Returns a gesture type enum value from a string (case insensitive).
*
* @param type - A string representation of a single gesture type (e.g. "tap").
*/
export declare function fromString(type: (typeof GestureTypes)[GestureTypes]): GestureTypes | undefined;
export declare abstract class GesturesObserverBase implements GesturesObserverDefinition {
private _callback;
private _target;
private _context?;
/** This is populated on the first call to observe(). */
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;
}