UNPKG

6.14 kBJavaScriptView Raw
1export * from './touch-manager';
2/**
3 * Events emitted during gesture lifecycle
4 */
5export var GestureEvents;
6(function (GestureEvents) {
7 /**
8 * When the gesture is attached to the view
9 * Provides access to the native gesture recognizer for further customization
10 */
11 GestureEvents["gestureAttached"] = "gestureAttached";
12 /**
13 * When a touch down was detected
14 */
15 GestureEvents["touchDown"] = "touchDown";
16 /**
17 * When a touch up was detected
18 */
19 GestureEvents["touchUp"] = "touchUp";
20})(GestureEvents || (GestureEvents = {}));
21/**
22 * Defines an enum with supported gesture types.
23 */
24export var GestureTypes;
25(function (GestureTypes) {
26 /**
27 * Denotes tap (click) gesture.
28 */
29 GestureTypes[GestureTypes["tap"] = 1] = "tap";
30 /**
31 * Denotes double tap gesture.
32 */
33 GestureTypes[GestureTypes["doubleTap"] = 2] = "doubleTap";
34 /**
35 * Denotes pinch gesture.
36 */
37 GestureTypes[GestureTypes["pinch"] = 4] = "pinch";
38 /**
39 * Denotes pan gesture.
40 */
41 GestureTypes[GestureTypes["pan"] = 8] = "pan";
42 /**
43 * Denotes swipe gesture.
44 */
45 GestureTypes[GestureTypes["swipe"] = 16] = "swipe";
46 /**
47 * Denotes rotation gesture.
48 */
49 GestureTypes[GestureTypes["rotation"] = 32] = "rotation";
50 /**
51 * Denotes long press gesture.
52 */
53 GestureTypes[GestureTypes["longPress"] = 64] = "longPress";
54 /**
55 * Denotes touch action.
56 */
57 GestureTypes[GestureTypes["touch"] = 128] = "touch";
58})(GestureTypes || (GestureTypes = {}));
59/**
60 * Defines an enum with supported gesture states.
61 */
62export var GestureStateTypes;
63(function (GestureStateTypes) {
64 /**
65 * Gesture canceled.
66 */
67 GestureStateTypes[GestureStateTypes["cancelled"] = 0] = "cancelled";
68 /**
69 * Gesture began.
70 */
71 GestureStateTypes[GestureStateTypes["began"] = 1] = "began";
72 /**
73 * Gesture changed.
74 */
75 GestureStateTypes[GestureStateTypes["changed"] = 2] = "changed";
76 /**
77 * Gesture ended.
78 */
79 GestureStateTypes[GestureStateTypes["ended"] = 3] = "ended";
80})(GestureStateTypes || (GestureStateTypes = {}));
81/**
82 * Defines an enum for swipe gesture direction.
83 */
84export var SwipeDirection;
85(function (SwipeDirection) {
86 /**
87 * Denotes right direction for swipe gesture.
88 */
89 SwipeDirection[SwipeDirection["right"] = 1] = "right";
90 /**
91 * Denotes left direction for swipe gesture.
92 */
93 SwipeDirection[SwipeDirection["left"] = 2] = "left";
94 /**
95 * Denotes up direction for swipe gesture.
96 */
97 SwipeDirection[SwipeDirection["up"] = 4] = "up";
98 /**
99 * Denotes down direction for swipe gesture.
100 */
101 SwipeDirection[SwipeDirection["down"] = 8] = "down";
102})(SwipeDirection || (SwipeDirection = {}));
103/**
104 * Defines a touch action
105 */
106export var TouchAction;
107(function (TouchAction) {
108 /**
109 * Down action.
110 */
111 TouchAction["down"] = "down";
112 /**
113 * Up action.
114 */
115 TouchAction["up"] = "up";
116 /**
117 * Move action.
118 */
119 TouchAction["move"] = "move";
120 /**
121 * Cancel action.
122 */
123 TouchAction["cancel"] = "cancel";
124})(TouchAction || (TouchAction = {}));
125/**
126 * Returns a string representation of a gesture type.
127 * @param type - Type of the gesture.
128 * @param separator(optional) - Text separator between gesture type strings.
129 */
130export function toString(type, separator) {
131 const types = new Array();
132 if (type & GestureTypes.tap) {
133 types.push('tap');
134 }
135 if (type & GestureTypes.doubleTap) {
136 types.push('doubleTap');
137 }
138 if (type & GestureTypes.pinch) {
139 types.push('pinch');
140 }
141 if (type & GestureTypes.pan) {
142 types.push('pan');
143 }
144 if (type & GestureTypes.swipe) {
145 types.push('swipe');
146 }
147 if (type & GestureTypes.rotation) {
148 types.push('rotation');
149 }
150 if (type & GestureTypes.longPress) {
151 types.push('longPress');
152 }
153 if (type & GestureTypes.touch) {
154 types.push('touch');
155 }
156 return types.join(separator);
157}
158// NOTE: toString could return the text of multiple GestureTypes.
159// Souldn't fromString do split on separator and return multiple GestureTypes?
160/**
161 * Returns a gesture type enum value from a string (case insensitive).
162 * @param type - A string representation of a gesture type (e.g. Tap).
163 */
164export function fromString(type) {
165 const t = type.trim().toLowerCase();
166 if (t === 'tap') {
167 return GestureTypes.tap;
168 }
169 else if (t === 'doubletap') {
170 return GestureTypes.doubleTap;
171 }
172 else if (t === 'pinch') {
173 return GestureTypes.pinch;
174 }
175 else if (t === 'pan') {
176 return GestureTypes.pan;
177 }
178 else if (t === 'swipe') {
179 return GestureTypes.swipe;
180 }
181 else if (t === 'rotation') {
182 return GestureTypes.rotation;
183 }
184 else if (t === 'longpress') {
185 return GestureTypes.longPress;
186 }
187 else if (t === 'touch') {
188 return GestureTypes.touch;
189 }
190 return undefined;
191}
192export class GesturesObserverBase {
193 get callback() {
194 return this._callback;
195 }
196 get target() {
197 return this._target;
198 }
199 get context() {
200 return this._context;
201 }
202 constructor(target, callback, context) {
203 this._target = target;
204 this._callback = callback;
205 this._context = context;
206 }
207 disconnect() {
208 // remove gesture observer from map
209 if (this.target) {
210 const list = this.target.getGestureObservers(this.type);
211 if (list && list.length > 0) {
212 for (let i = 0; i < list.length; i++) {
213 if (list[i].callback === this.callback) {
214 break;
215 }
216 }
217 list.length = 0;
218 this.target._gestureObservers[this.type] = undefined;
219 delete this.target._gestureObservers[this.type];
220 }
221 }
222 this._target = null;
223 this._callback = null;
224 this._context = null;
225 }
226}
227//# sourceMappingURL=gestures-common.js.map
\No newline at end of file