forked from NativeScript/NativeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgestures-common.ts
More file actions
157 lines (129 loc) · 3.99 KB
/
gestures-common.ts
File metadata and controls
157 lines (129 loc) · 3.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import definition = require("ui/gestures");
import view = require("ui/core/view");
export enum GestureTypes {
tap = 1 << 0,
doubleTap = 1 << 1,
pinch = 1 << 2,
pan = 1 << 3,
swipe = 1 << 4,
rotation = 1 << 5,
longPress = 1 << 6,
touch = 1 << 7
}
export enum GestureStateTypes {
cancelled,
began,
changed,
ended
}
export enum SwipeDirection {
right = 1 << 0,
left = 1 << 1,
up = 1 << 2,
down = 1 << 3
}
export module TouchAction {
export var down = "down";
export var up = "up";
export var move = "move";
export var cancel = "cancel";
}
export function observe(target: view.View, type: definition.GestureTypes, callback: (args: definition.GestureEventData) => void, context?: any): definition.GesturesObserver {
var observer = new definition.GesturesObserver(target, callback, context);
observer.observe(type);
return observer;
}
export function toString(type: GestureTypes, separator?: string): string {
var types = new Array<string>();
if (type & definition.GestureTypes.tap) {
types.push("tap");
}
if (type & definition.GestureTypes.doubleTap) {
types.push("doubleTap");
}
if (type & definition.GestureTypes.pinch) {
types.push("pinch");
}
if (type & definition.GestureTypes.pan) {
types.push("pan");
}
if (type & definition.GestureTypes.swipe) {
types.push("swipe");
}
if (type & definition.GestureTypes.rotation) {
types.push("rotation");
}
if (type & definition.GestureTypes.longPress) {
types.push("longPress");
}
if (type & definition.GestureTypes.touch) {
types.push("touch");
}
return types.join(separator);
}
export function fromString(type: string): definition.GestureTypes {
var t = type.trim().toLowerCase();
if (t === "tap") {
return definition.GestureTypes.tap;
} else if (t === "doubletap") {
return definition.GestureTypes.doubleTap;
} else if (t === "pinch") {
return definition.GestureTypes.pinch;
} else if (t === "pan") {
return definition.GestureTypes.pan;
} else if (t === "swipe") {
return definition.GestureTypes.swipe;
} else if (t === "rotation") {
return definition.GestureTypes.rotation;
} else if (t === "longpress") {
return definition.GestureTypes.longPress;
} else if (t === "touch") {
return definition.GestureTypes.touch;
}
return undefined;
}
export class GesturesObserver implements definition.GesturesObserver {
private _callback: (args: definition.GestureEventData) => void;
private _target: view.View;
private _context: any;
public type: definition.GestureTypes;
public get callback(): (args: definition.GestureEventData) => void {
return this._callback;
}
public get target(): view.View {
return this._target;
}
public get context() {
return this._context;
}
constructor(target: view.View, callback: (args: definition.GestureEventData) => void, context: any) {
this._target = target;
this._callback = callback;
this._context = context;
}
public androidOnTouchEvent(motionEvent: android.view.MotionEvent) {
//
}
public observe(type: definition.GestureTypes) {
//
}
public disconnect() {
// remove gesture observer from map
if (this.target) {
var 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;
}
}