@react-native-oh-tpl/react-native-gesture-handler 2.14.8-rc.1 → 2.14.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. package/DrawerLayout/index.ts +2 -2
  2. package/Swipeable/index.ts +2 -2
  3. package/harmony/gesture_handler/BuildProfile.ets +17 -0
  4. package/harmony/gesture_handler/build-profile.json5 +19 -0
  5. package/harmony/gesture_handler/hvigorfile.ts +2 -0
  6. package/harmony/gesture_handler/index.ets +2 -0
  7. package/harmony/gesture_handler/oh-package-lock.json5 +18 -0
  8. package/harmony/gesture_handler/oh-package.json5 +12 -0
  9. package/harmony/gesture_handler/src/main/cpp/CMakeLists.txt +8 -0
  10. package/harmony/gesture_handler/src/main/cpp/GestureHandlerPackage.h +12 -0
  11. package/harmony/gesture_handler/src/main/cpp/RnohReactNativeHarmonyGestureHandlerPackage.cpp +123 -0
  12. package/harmony/gesture_handler/src/main/cpp/RnohReactNativeHarmonyGestureHandlerPackage.h +15 -0
  13. package/harmony/gesture_handler/src/main/cpp/componentInstances/RNGestureHandlerButtonComponentInstance.h +27 -0
  14. package/harmony/gesture_handler/src/main/cpp/componentInstances/RNGestureHandlerRootViewComponentInstance.h +245 -0
  15. package/harmony/gesture_handler/src/main/ets/RNOHPackage.ets +17 -0
  16. package/harmony/gesture_handler/src/main/ets/core/CircularBuffer.ts +42 -0
  17. package/harmony/gesture_handler/src/main/ets/core/GestureHandler.ts +739 -0
  18. package/harmony/gesture_handler/src/main/ets/core/GestureHandlerOrchestrator.ts +344 -0
  19. package/harmony/gesture_handler/src/main/ets/core/GestureHandlerRegistry.ts +63 -0
  20. package/harmony/gesture_handler/src/main/ets/core/IncomingEvent.ts +78 -0
  21. package/harmony/gesture_handler/src/main/ets/core/InteractionManager.ts +144 -0
  22. package/harmony/gesture_handler/src/main/ets/core/LeastSquareSolver.ts +182 -0
  23. package/harmony/gesture_handler/src/main/ets/core/Multiset.ts +26 -0
  24. package/harmony/gesture_handler/src/main/ets/core/OutgoingEvent.ts +34 -0
  25. package/harmony/gesture_handler/src/main/ets/core/OutgoingEventDispatcher.ts +12 -0
  26. package/harmony/gesture_handler/src/main/ets/core/PointerTracker.ts +239 -0
  27. package/harmony/gesture_handler/src/main/ets/core/RNGHError.ts +5 -0
  28. package/harmony/gesture_handler/src/main/ets/core/RNGHLogger.ts +16 -0
  29. package/harmony/gesture_handler/src/main/ets/core/State.ts +47 -0
  30. package/harmony/gesture_handler/src/main/ets/core/Vector2D.ts +80 -0
  31. package/harmony/gesture_handler/src/main/ets/core/VelocityTracker.ts +106 -0
  32. package/harmony/gesture_handler/src/main/ets/core/View.ts +21 -0
  33. package/harmony/gesture_handler/src/main/ets/core/ViewRegistry.ts +7 -0
  34. package/harmony/gesture_handler/src/main/ets/core/index.ts +15 -0
  35. package/harmony/gesture_handler/src/main/ets/detectors/ScaleGestureDetector.ts +169 -0
  36. package/harmony/gesture_handler/src/main/ets/gesture-handlers/FlingGestureHandler.ts +219 -0
  37. package/harmony/gesture_handler/src/main/ets/gesture-handlers/GestureHandlerFactory.ts +67 -0
  38. package/harmony/gesture_handler/src/main/ets/gesture-handlers/LongPressGestureHandler.ts +139 -0
  39. package/harmony/gesture_handler/src/main/ets/gesture-handlers/ManualGestureHandler.ts +50 -0
  40. package/harmony/gesture_handler/src/main/ets/gesture-handlers/NativeViewGestureHandler.ts +124 -0
  41. package/harmony/gesture_handler/src/main/ets/gesture-handlers/PanGestureHandler.ts +361 -0
  42. package/harmony/gesture_handler/src/main/ets/gesture-handlers/PinchGestureHandler.ts +174 -0
  43. package/harmony/gesture_handler/src/main/ets/gesture-handlers/RotationGestureHandler.ts +172 -0
  44. package/harmony/gesture_handler/src/main/ets/gesture-handlers/TapGestureHandler.ts +216 -0
  45. package/harmony/gesture_handler/src/main/ets/gesture-handlers/detectors/RotationGestureDetector.ts +167 -0
  46. package/harmony/gesture_handler/src/main/ets/gesture-handlers/index.ts +1 -0
  47. package/harmony/gesture_handler/src/main/ets/rnoh/GestureHandlerPackage.ts +25 -0
  48. package/harmony/gesture_handler/src/main/ets/rnoh/Logger.ts +107 -0
  49. package/harmony/gesture_handler/src/main/ets/rnoh/OutgoingEventDispatchers.ts +94 -0
  50. package/harmony/gesture_handler/src/main/ets/rnoh/RNGHRootViewController.ts +182 -0
  51. package/harmony/gesture_handler/src/main/ets/rnoh/RNGHView.ts +62 -0
  52. package/harmony/gesture_handler/src/main/ets/rnoh/RNGHViewController.ts +262 -0
  53. package/harmony/gesture_handler/src/main/ets/rnoh/RNGHViewRegistry.ts +19 -0
  54. package/harmony/gesture_handler/src/main/ets/rnoh/RNGestureHandlerModule.ts +267 -0
  55. package/harmony/gesture_handler/src/main/ets/rnoh/RNOHGestureResponder.ts +15 -0
  56. package/harmony/gesture_handler/src/main/ets/rnoh/RNOHScrollLocker.ts +25 -0
  57. package/harmony/gesture_handler/src/main/ets/rnoh/types.ts +25 -0
  58. package/harmony/gesture_handler/src/main/module.json5 +9 -0
  59. package/harmony/gesture_handler/src/main/resources/base/element/color.json +8 -0
  60. package/harmony/gesture_handler/src/main/resources/base/element/string.json +16 -0
  61. package/harmony/gesture_handler/src/main/resources/base/media/icon.png +0 -0
  62. package/harmony/gesture_handler/src/main/resources/base/profile/main_pages.json +5 -0
  63. package/harmony/gesture_handler/src/main/resources/en_US/element/string.json +16 -0
  64. package/harmony/gesture_handler/src/main/resources/zh_CN/element/string.json +16 -0
  65. package/harmony/gesture_handler/ts.ts +2 -0
  66. package/harmony/gesture_handler.har +0 -0
  67. package/lib/commonjs/RNGestureHandlerModule.js +3 -2
  68. package/lib/commonjs/RNGestureHandlerModule.js.map +1 -1
  69. package/lib/commonjs/components/GestureHandlerRootView.js +3 -3
  70. package/lib/commonjs/components/GestureHandlerRootView.js.map +1 -1
  71. package/lib/commonjs/handlers/createHandler.js +18 -15
  72. package/lib/commonjs/handlers/createHandler.js.map +1 -1
  73. package/lib/commonjs/index.js +36 -8
  74. package/lib/commonjs/index.js.map +1 -1
  75. package/lib/commonjs/specs/NativeRNGestureHandlerModule.js +2 -1
  76. package/lib/commonjs/specs/NativeRNGestureHandlerModule.js.map +1 -1
  77. package/lib/commonjs/specs/RNGestureHandlerButtonNativeComponent.js +3 -2
  78. package/lib/commonjs/specs/RNGestureHandlerButtonNativeComponent.js.map +1 -1
  79. package/lib/commonjs/specs/RNGestureHandlerRootViewNativeComponent.js +3 -2
  80. package/lib/commonjs/specs/RNGestureHandlerRootViewNativeComponent.js.map +1 -1
  81. package/lib/module/RNGestureHandlerModule.js.map +1 -1
  82. package/lib/module/components/GestureHandlerRootView.js.map +1 -1
  83. package/lib/module/handlers/createHandler.js +15 -12
  84. package/lib/module/handlers/createHandler.js.map +1 -1
  85. package/lib/module/index.js +5 -7
  86. package/lib/module/index.js.map +1 -1
  87. package/lib/module/specs/NativeRNGestureHandlerModule.js.map +1 -1
  88. package/lib/module/specs/RNGestureHandlerButtonNativeComponent.js.map +1 -1
  89. package/lib/module/specs/RNGestureHandlerRootViewNativeComponent.js.map +1 -1
  90. package/lib/typescript/RNGestureHandlerModule.d.ts +2 -2
  91. package/lib/typescript/components/GestureHandlerRootView.d.ts +6 -6
  92. package/lib/typescript/handlers/createHandler.d.ts +11 -11
  93. package/lib/typescript/index.d.ts +47 -42
  94. package/lib/typescript/index.d.ts.map +1 -1
  95. package/lib/typescript/specs/NativeRNGestureHandlerModule.d.ts +14 -14
  96. package/lib/typescript/specs/RNGestureHandlerButtonNativeComponent.d.ts +14 -14
  97. package/lib/typescript/specs/RNGestureHandlerRootViewNativeComponent.d.ts +6 -6
  98. package/package.json +78 -70
  99. package/src/RNGestureHandlerModule.ts +4 -4
  100. package/src/components/GestureHandlerRootView.tsx +23 -23
  101. package/src/handlers/createHandler.tsx +534 -534
  102. package/src/index.ts +172 -172
  103. package/src/specs/NativeRNGestureHandlerModule.ts +26 -26
  104. package/src/specs/RNGestureHandlerButtonNativeComponent.ts +18 -18
  105. package/src/specs/RNGestureHandlerRootViewNativeComponent.ts +6 -6
@@ -0,0 +1,739 @@
1
+ import type { GestureHandlerOrchestrator } from "./GestureHandlerOrchestrator"
2
+ import type { PointerTracker } from "./PointerTracker"
3
+ import type { View } from "./View"
4
+ import type { InteractionManager } from "./InteractionManager"
5
+ import type { RNGHLogger } from './RNGHLogger'
6
+ import { OutgoingEventDispatcher } from "./OutgoingEventDispatcher"
7
+ import { State, getStateName } from "./State"
8
+ import { HitSlop, Directions, IncomingEvent, PointerType, TouchEventType, EventType } from "./IncomingEvent"
9
+ import { GestureStateChangeEvent, GestureTouchEvent, TouchData } from "./OutgoingEvent"
10
+
11
+
12
+ export type GHTag = number
13
+
14
+ export interface Handler {
15
+ handlerTag: GHTag;
16
+ }
17
+
18
+ export const DEFAULT_TOUCH_SLOP = 15;
19
+
20
+ export interface GestureConfig {
21
+ enabled?: boolean;
22
+ manualActivation?: boolean;
23
+ simultaneousHandlers?: Handler[] | null;
24
+ waitFor?: Handler[] | null;
25
+ blocksHandlers?: Handler[] | null;
26
+ hitSlop?: HitSlop;
27
+ shouldCancelWhenOutside?: boolean;
28
+ activateAfterLongPress?: number;
29
+ failOffsetXStart?: number;
30
+ failOffsetYStart?: number;
31
+ failOffsetXEnd?: number;
32
+ failOffsetYEnd?: number;
33
+ activeOffsetXStart?: number;
34
+ activeOffsetXEnd?: number;
35
+ activeOffsetYStart?: number;
36
+ activeOffsetYEnd?: number;
37
+ minPointers?: number;
38
+ maxPointers?: number;
39
+ minDist?: number;
40
+ minDistSq?: number;
41
+ minVelocity?: number;
42
+ minVelocityX?: number;
43
+ minVelocityY?: number;
44
+ minVelocitySq?: number;
45
+ maxDist?: number;
46
+ maxDistSq?: number;
47
+ numberOfPointers?: number;
48
+ minDurationMs?: number;
49
+ numberOfTaps?: number;
50
+ maxDurationMs?: number;
51
+ maxDelayMs?: number;
52
+ maxDeltaX?: number;
53
+ maxDeltaY?: number;
54
+ shouldActivateOnStart?: boolean;
55
+ disallowInterruption?: boolean;
56
+ direction?: Directions;
57
+ needsPointerData?: boolean
58
+ // --- Tap
59
+ minNumberOfPointers?: number
60
+ }
61
+
62
+ type PointerId = number
63
+
64
+ export interface ScrollLocker {
65
+ lockScrollContainingViewTag(viewTag: number): () => void
66
+ }
67
+
68
+ export interface RNGestureResponder {
69
+ lock: (viewTag: number) => () => void
70
+ }
71
+
72
+ export type GestureHandlerDependencies = {
73
+ handlerTag: number
74
+ orchestrator: GestureHandlerOrchestrator
75
+ tracker: PointerTracker
76
+ interactionManager: InteractionManager
77
+ logger: RNGHLogger
78
+ scrollLocker: ScrollLocker
79
+ rnGestureResponder: RNGestureResponder
80
+ }
81
+
82
+ export abstract class GestureHandler<TGestureConfig extends GestureConfig = GestureConfig> {
83
+ protected config: TGestureConfig = this.getDefaultConfig()
84
+ protected currentState: State = State.UNDETERMINED
85
+ protected view: View | undefined = undefined
86
+ protected lastSentState: State | undefined = undefined
87
+ protected shouldCancelWhenOutside = false
88
+
89
+ protected isActivated = false
90
+ protected isAwaiting_ = false
91
+ protected pointerType: PointerType
92
+ protected activationIndex = 0
93
+ protected shouldResetProgress = false;
94
+
95
+ protected handlerTag: number
96
+ protected orchestrator: GestureHandlerOrchestrator
97
+ protected tracker: PointerTracker
98
+ protected eventDispatcher: OutgoingEventDispatcher
99
+ protected interactionManager: InteractionManager
100
+ protected logger: RNGHLogger
101
+ protected scrollLocker: ScrollLocker
102
+ protected rnGestureResponder: RNGestureResponder
103
+
104
+ constructor(deps: GestureHandlerDependencies
105
+ ) {
106
+ this.handlerTag = deps.handlerTag
107
+ this.orchestrator = deps.orchestrator
108
+ this.tracker = deps.tracker
109
+ this.interactionManager = deps.interactionManager
110
+ this.logger = deps.logger.cloneAndJoinPrefix("GestureHandler")
111
+ this.scrollLocker = deps.scrollLocker
112
+ this.rnGestureResponder = deps.rnGestureResponder
113
+ }
114
+
115
+ public abstract getName(): string;
116
+
117
+ public abstract isGestureContinuous(): boolean;
118
+
119
+ public setEventDispatcher(eventDispatcher: OutgoingEventDispatcher) {
120
+ // TurboModule provides info about kind of event dispatcher when attaching GH to a view, not when GH is created.
121
+ // This method must be called before any other
122
+ this.eventDispatcher = eventDispatcher
123
+ }
124
+
125
+ public onPointerDown(e: IncomingEvent) {
126
+ const stopTracing = this.logger.cloneAndJoinPrefix("onPointerDown").startTracing()
127
+ this.orchestrator.registerHandlerIfNotPresent(this);
128
+ this.pointerType = e.pointerType;
129
+ if (this.pointerType === PointerType.TOUCH) {
130
+ this.orchestrator.cancelMouseAndPenGestures(this);
131
+ }
132
+ if (this.config.needsPointerData) {
133
+ this.sendTouchEvent(e);
134
+ }
135
+ stopTracing()
136
+ }
137
+
138
+ protected sendTouchEvent(e: IncomingEvent) {
139
+ if (!this.config.enabled) {
140
+ return;
141
+ }
142
+
143
+
144
+ const touchEvent: GestureTouchEvent | undefined =
145
+ this.transformToTouchEvent(e);
146
+
147
+ if (touchEvent) {
148
+ this.eventDispatcher.onGestureHandlerEvent(touchEvent)
149
+ }
150
+ }
151
+
152
+ protected transformToTouchEvent(event: IncomingEvent): GestureTouchEvent | undefined {
153
+ const rect = this.view.getBoundingRect();
154
+
155
+ const all: TouchData[] = [];
156
+ const changed: TouchData[] = [];
157
+
158
+ const trackerData = this.tracker.getData();
159
+
160
+ // This if handles edge case where all pointers have been cancelled
161
+ // When pointercancel is triggered, reset method is called. This means that tracker will be reset after first pointer being cancelled
162
+ // The problem is, that handler will receive another pointercancel event from the rest of the pointers
163
+ // To avoid crashing, we don't send event if tracker tracks no pointers, i.e. has been reset
164
+ if (trackerData.size === 0 || !trackerData.has(event.pointerId)) {
165
+ return;
166
+ }
167
+
168
+ trackerData.forEach((element, key): void => {
169
+ const id: number = this.tracker.getMappedTouchEventId(key);
170
+
171
+ all.push({
172
+ id: id,
173
+ x: element.lastX - rect.x,
174
+ y: element.lastY - rect.y,
175
+ absoluteX: element.lastX,
176
+ absoluteY: element.lastY,
177
+ });
178
+ });
179
+
180
+ // Each pointer sends its own event, so we want changed touches to contain only the pointer that has changed.
181
+ // However, if the event is cancel, we want to cancel all pointers to avoid crashes
182
+ if (event.eventType !== EventType.CANCEL) {
183
+ changed.push({
184
+ id: this.tracker.getMappedTouchEventId(event.pointerId),
185
+ x: event.x - rect.x,
186
+ y: event.y - rect.y,
187
+ absoluteX: event.x,
188
+ absoluteY: event.y,
189
+ });
190
+ } else {
191
+ trackerData.forEach((element, key: number): void => {
192
+ const id: number = this.tracker.getMappedTouchEventId(key);
193
+
194
+ changed.push({
195
+ id: id,
196
+ x: element.lastX - rect.x,
197
+ y: element.lastY - rect.y,
198
+ absoluteX: element.lastX,
199
+ absoluteY: element.lastY,
200
+ });
201
+ });
202
+ }
203
+
204
+ let eventType: TouchEventType = TouchEventType.UNDETERMINED;
205
+
206
+ switch (event.eventType) {
207
+ case EventType.DOWN:
208
+ case EventType.ADDITIONAL_POINTER_DOWN:
209
+ eventType = TouchEventType.DOWN;
210
+ break;
211
+ case EventType.UP:
212
+ case EventType.ADDITIONAL_POINTER_UP:
213
+ eventType = TouchEventType.UP;
214
+ break;
215
+ case EventType.MOVE:
216
+ eventType = TouchEventType.MOVE;
217
+ break;
218
+ case EventType.CANCEL:
219
+ eventType = TouchEventType.CANCELLED;
220
+ break;
221
+ }
222
+
223
+ // Here, when we receive up event, we want to decrease number of touches
224
+ // That's because we want handler to send information that there's one pointer less
225
+ // However, we still want this pointer to be present in allTouches array, so that its data can be accessed
226
+ let numberOfTouches: number = all.length;
227
+
228
+ if (
229
+ event.eventType === EventType.UP ||
230
+ event.eventType === EventType.ADDITIONAL_POINTER_UP
231
+ ) {
232
+ --numberOfTouches;
233
+ }
234
+
235
+ return {
236
+ handlerTag: this.handlerTag,
237
+ state: this.currentState,
238
+ eventType: event.touchEventType ?? eventType,
239
+ changedTouches: changed,
240
+ allTouches: all,
241
+ numberOfTouches: numberOfTouches,
242
+ };
243
+ }
244
+
245
+ public onPointerUp(e: IncomingEvent): void {
246
+ const stopTracing = this.logger.cloneAndJoinPrefix("onPointerUp").startTracing()
247
+ if (this.config.needsPointerData) {
248
+ this.sendTouchEvent(e)
249
+ }
250
+ stopTracing()
251
+ }
252
+
253
+ public onAdditionalPointerAdd(e: IncomingEvent): void {
254
+ const stopTracing = this.logger.cloneAndJoinPrefix("onAdditionalPointerAdd").startTracing()
255
+ if (this.config.needsPointerData) {
256
+ this.sendTouchEvent(e)
257
+ }
258
+ stopTracing()
259
+ }
260
+
261
+ public onAdditionalPointerRemove(e: IncomingEvent): void {
262
+ const stopTracing = this.logger.cloneAndJoinPrefix("onAdditionalPointerRemove").startTracing()
263
+ if (this.config.needsPointerData) {
264
+ this.sendTouchEvent(e)
265
+ }
266
+ stopTracing()
267
+ }
268
+
269
+ public onPointerMove(e: IncomingEvent): void {
270
+ const stopTracing = this.logger.cloneAndJoinPrefix("onPointerMove").startTracing()
271
+ this.tryToSendMoveEvent(false);
272
+ if (this.config.needsPointerData) {
273
+ this.sendTouchEvent(e);
274
+ }
275
+ stopTracing()
276
+ }
277
+
278
+ private tryToSendMoveEvent(out: boolean): void {
279
+ const logger = this.logger.cloneAndJoinPrefix(`tryToSendMoveEvent`)
280
+ const stopTracing = logger.startTracing()
281
+ logger.debug({
282
+ out,
283
+ enabled: this.config.enabled,
284
+ isActivated: this.isActivated,
285
+ shouldCancelWhenOutside: this.shouldCancelWhenOutside
286
+ })
287
+ if (
288
+ this.config.enabled &&
289
+ this.isActivated &&
290
+ (!out || (out && !this.shouldCancelWhenOutside))
291
+ ) {
292
+ this.sendEvent({ newState: this.currentState, oldState: this.currentState });
293
+ }
294
+ stopTracing()
295
+ }
296
+
297
+ public onPointerEnter(e: IncomingEvent): void {
298
+ const stopTracing = this.logger.cloneAndJoinPrefix("onPointerEnter").startTracing()
299
+ if (this.config.needsPointerData) {
300
+ this.sendTouchEvent(e)
301
+ }
302
+ stopTracing()
303
+ }
304
+
305
+ public onPointerOut(e: IncomingEvent): void {
306
+ const stopTracing = this.logger.cloneAndJoinPrefix("onPointerOut").startTracing()
307
+ if (this.shouldCancelWhenOutside) {
308
+ switch (this.currentState) {
309
+ case State.ACTIVE:
310
+ this.cancel();
311
+ break;
312
+ case State.BEGAN:
313
+ this.fail();
314
+ break;
315
+ }
316
+ stopTracing()
317
+ return;
318
+ }
319
+ if (this.config.needsPointerData) {
320
+ this.sendTouchEvent(e);
321
+ }
322
+ stopTracing()
323
+ }
324
+
325
+ public onPointerCancel(e: IncomingEvent): void {
326
+ const stopTracing = this.logger.cloneAndJoinPrefix("onPointerCancel").startTracing()
327
+ if (this.config.needsPointerData) {
328
+ this.sendTouchEvent(e);
329
+ }
330
+ this.cancel();
331
+ this.reset();
332
+ stopTracing()
333
+ }
334
+
335
+ public onPointerOutOfBounds(e: IncomingEvent): void {
336
+ const stopTracing = this.logger.cloneAndJoinPrefix("onPointerOutOfBounds").startTracing()
337
+ this.tryToSendMoveEvent(true);
338
+ if (this.config.needsPointerData) {
339
+ this.sendTouchEvent(e);
340
+ }
341
+ stopTracing()
342
+ }
343
+
344
+ public onViewAttached(view: View) {
345
+ const stopTracing = this.logger.cloneAndJoinPrefix("onViewAttached").startTracing()
346
+ this.view = view
347
+ stopTracing()
348
+ }
349
+
350
+ public getTag(): number {
351
+ return this.handlerTag
352
+ }
353
+
354
+ public getTracker() {
355
+ return this.tracker
356
+ }
357
+
358
+ public getView() {
359
+ return this.view
360
+ }
361
+
362
+ public begin(): void {
363
+ const stopTracing = this.logger.cloneAndJoinPrefix("begin").startTracing()
364
+ if (!this.isWithinHitSlop()) {
365
+ stopTracing()
366
+ return;
367
+ }
368
+ if (this.currentState === State.UNDETERMINED) {
369
+ this.moveToState(State.BEGAN);
370
+ }
371
+ stopTracing()
372
+ }
373
+
374
+ private isWithinHitSlop(): boolean {
375
+ if (!this.config.hitSlop) {
376
+ return true;
377
+ }
378
+
379
+ const width = this.view.getBoundingRect().width;
380
+ const height = this.view.getBoundingRect().height;
381
+
382
+ let left = 0;
383
+ let top = 0;
384
+ let right: number = width;
385
+ let bottom: number = height;
386
+
387
+ if (this.config.hitSlop.horizontal !== undefined) {
388
+ left -= this.config.hitSlop.horizontal;
389
+ right += this.config.hitSlop.horizontal;
390
+ }
391
+
392
+ if (this.config.hitSlop.vertical !== undefined) {
393
+ top -= this.config.hitSlop.vertical;
394
+ bottom += this.config.hitSlop.vertical;
395
+ }
396
+
397
+ if (this.config.hitSlop.left !== undefined) {
398
+ left = -this.config.hitSlop.left;
399
+ }
400
+
401
+ if (this.config.hitSlop.right !== undefined) {
402
+ right = width + this.config.hitSlop.right;
403
+ }
404
+
405
+ if (this.config.hitSlop.top !== undefined) {
406
+ top = -this.config.hitSlop.top;
407
+ }
408
+
409
+ if (this.config.hitSlop.bottom !== undefined) {
410
+ bottom = width + this.config.hitSlop.bottom;
411
+ }
412
+ if (this.config.hitSlop.width !== undefined) {
413
+ if (this.config.hitSlop.left !== undefined) {
414
+ right = left + this.config.hitSlop.width;
415
+ } else if (this.config.hitSlop.right !== undefined) {
416
+ left = right - this.config.hitSlop.width;
417
+ }
418
+ }
419
+
420
+ if (this.config.hitSlop.height !== undefined) {
421
+ if (this.config.hitSlop.top !== undefined) {
422
+ bottom = top + this.config.hitSlop.height;
423
+ } else if (this.config.hitSlop.bottom !== undefined) {
424
+ top = bottom - this.config.hitSlop.height;
425
+ }
426
+ }
427
+
428
+ const rect = this.view.getBoundingRect();
429
+ const offsetX: number = this.tracker.getLastX() - rect.x;
430
+ const offsetY: number = this.tracker.getLastY() - rect.y;
431
+
432
+ if (
433
+ offsetX >= left &&
434
+ offsetX <= right &&
435
+ offsetY >= top &&
436
+ offsetY <= bottom
437
+ ) {
438
+ return true;
439
+ }
440
+ return false;
441
+ }
442
+
443
+ public activate(): void {
444
+ const stopTracing = this.logger.cloneAndJoinPrefix("activate").startTracing()
445
+ if (!this.config.manualActivation || this.currentState === State.UNDETERMINED ||
446
+ this.currentState === State.BEGAN) {
447
+ this.moveToState(State.ACTIVE)
448
+ }
449
+ stopTracing()
450
+ }
451
+
452
+ protected moveToState(state: State) {
453
+ const stopTracing = this.logger.cloneAndJoinPrefix(`moveToState ${getStateName(state)}`).startTracing()
454
+ if (state === this.currentState) {
455
+ stopTracing()
456
+ return;
457
+ }
458
+ const oldState = this.currentState
459
+ this.currentState = state;
460
+ if (this.tracker.getTrackedPointersCount() > 0 && this.config.needsPointerData && this.isFinished()) {
461
+ this.cancelTouches()
462
+ }
463
+ this.orchestrator.onHandlerStateChange(this, state, oldState)
464
+ this.onStateChange(state, oldState)
465
+
466
+ if (!this.isEnabled() && this.isFinished()) {
467
+ this.currentState = State.UNDETERMINED;
468
+ }
469
+ stopTracing()
470
+ }
471
+
472
+ private isFinished() {
473
+ return (
474
+ this.currentState === State.END ||
475
+ this.currentState === State.FAILED ||
476
+ this.currentState === State.CANCELLED
477
+ );
478
+ }
479
+
480
+ private cancelTouches(): void {
481
+ const rect = this.view.getBoundingRect();
482
+ const all: TouchData[] = [];
483
+ const changed: TouchData[] = [];
484
+ const trackerData = this.tracker.getData();
485
+ if (trackerData.size === 0) {
486
+ return;
487
+ }
488
+ trackerData.forEach((element, key): void => {
489
+ const id: number = this.tracker.getMappedTouchEventId(key);
490
+ all.push({
491
+ id: id,
492
+ x: element.lastX - rect.x,
493
+ y: element.lastY - rect.y,
494
+ absoluteX: element.lastX,
495
+ absoluteY: element.lastY,
496
+ });
497
+ changed.push({
498
+ id: id,
499
+ x: element.lastX - rect.x,
500
+ y: element.lastY - rect.y,
501
+ absoluteX: element.lastX,
502
+ absoluteY: element.lastY,
503
+ });
504
+ });
505
+ const cancelEvent: GestureTouchEvent = {
506
+ handlerTag: this.handlerTag,
507
+ state: this.currentState,
508
+ eventType: TouchEventType.CANCELLED,
509
+ changedTouches: changed,
510
+ allTouches: all,
511
+ numberOfTouches: all.length,
512
+ };
513
+ this.eventDispatcher.onGestureHandlerEvent(cancelEvent)
514
+ }
515
+
516
+ protected onStateChange(newState: State, oldState: State) {
517
+ this.logger.info(`onStateChange: from ${getStateName(oldState)} to ${getStateName(newState)}`)
518
+ }
519
+
520
+
521
+ public updateGestureConfig(config: TGestureConfig): void {
522
+ this.config = { enabled: true, ...config }
523
+ if (this.config.shouldCancelWhenOutside !== undefined) {
524
+ this.setShouldCancelWhenOutside(this.config.shouldCancelWhenOutside);
525
+ }
526
+
527
+ // this.validateHitSlops();
528
+ if (this.config.enabled) {
529
+ return;
530
+ }
531
+ // switch (this.currentState) {
532
+ // case State.ACTIVE:
533
+ // this.fail(true);
534
+ // break;
535
+ // case State.UNDETERMINED:
536
+ // this.orchestrator.removeHandlerFromOrchestrator(this);
537
+ // break;
538
+ // default:
539
+ // this.cancel(true);
540
+ // break;
541
+ }
542
+
543
+ protected resetConfig(): void {
544
+ this.config = this.getDefaultConfig()
545
+ }
546
+
547
+ abstract getDefaultConfig(): TGestureConfig
548
+
549
+
550
+ public isEnabled(): boolean {
551
+ return Boolean(this.config.enabled)
552
+ }
553
+
554
+ public isActive(): boolean {
555
+ return this.isActivated
556
+ }
557
+
558
+ public cancel(): void {
559
+ const stopTracing = this.logger.cloneAndJoinPrefix(`cancel`).startTracing()
560
+ if (
561
+ this.currentState === State.ACTIVE ||
562
+ this.currentState === State.UNDETERMINED ||
563
+ this.currentState === State.BEGAN
564
+ ) {
565
+ this.onCancel();
566
+ this.moveToState(State.CANCELLED);
567
+ }
568
+ stopTracing()
569
+ }
570
+
571
+ protected onCancel(): void {
572
+ }
573
+
574
+ protected onReset(): void {
575
+ }
576
+
577
+ protected resetProgress(): void {
578
+ }
579
+
580
+ public getState(): State {
581
+ return this.currentState
582
+ }
583
+
584
+ public sendEvent({ newState, oldState }: {
585
+ oldState: State,
586
+ newState: State
587
+ }): void {
588
+ const logger =
589
+ this.logger.cloneAndJoinPrefix(`sendEvent`)
590
+ const stopTracing = logger.startTracing()
591
+ logger.debug({ tag: this.getTag(), newState, oldState })
592
+ const stateChangeEvent = this.createStateChangeEvent(newState, oldState);
593
+ if (this.lastSentState !== newState) {
594
+ this.lastSentState = newState;
595
+ logger.debug("calling onGestureHandlerStateChange")
596
+ this.eventDispatcher.onGestureHandlerStateChange(stateChangeEvent);
597
+ }
598
+ if (this.currentState === State.ACTIVE) {
599
+ stateChangeEvent.oldState = undefined;
600
+ logger.debug("calling onGestureHandlerEvent")
601
+ this.eventDispatcher.onGestureHandlerEvent(stateChangeEvent);
602
+ }
603
+ stopTracing()
604
+ }
605
+
606
+ private createStateChangeEvent(newState: State, oldState: State): GestureStateChangeEvent {
607
+ return {
608
+ numberOfPointers: this.tracker.getTrackedPointersCount(),
609
+ state: newState,
610
+ pointerInside: this.view.isPositionInBounds({
611
+ x: this.tracker.getLastAvgX(),
612
+ y: this.tracker.getLastAvgY(),
613
+ }),
614
+ ...this.transformNativeEvent(),
615
+ handlerTag: this.handlerTag,
616
+ target: this.view.getTag(),
617
+ oldState: newState !== oldState ? oldState : undefined,
618
+ };
619
+ }
620
+
621
+ protected transformNativeEvent(): Record<string, unknown> {
622
+ const rect = this.view.getBoundingRect();
623
+ return {
624
+ x: this.tracker.getLastAvgX() - rect.x,
625
+ y: this.tracker.getLastAvgY() - rect.y,
626
+ absoluteX: this.tracker.getLastAvgX(),
627
+ absoluteY: this.tracker.getLastAvgY(),
628
+ };
629
+ }
630
+
631
+ setAwaiting(isAwaiting: boolean): void {
632
+ this.isAwaiting_ = isAwaiting
633
+ }
634
+
635
+ shouldWaitForHandlerFailure(handler: GestureHandler): boolean {
636
+ if (handler === this) {
637
+ return false;
638
+ }
639
+ return this.interactionManager.shouldWaitForHandlerFailure(this, handler);
640
+ }
641
+
642
+ shouldRequireToWaitForFailure(handler: GestureHandler): boolean {
643
+ if (handler === this) {
644
+ return false;
645
+ }
646
+ return this.interactionManager.shouldRequireHandlerToWaitForFailure(this, handler);
647
+ }
648
+
649
+ shouldWaitFor(otherHandler: GestureHandler): boolean {
650
+ const logger = this.logger.cloneAndJoinPrefix(`shouldWaitFor(${otherHandler.getTag()})`)
651
+ const result = (
652
+ this !== otherHandler &&
653
+ (this.shouldWaitForHandlerFailure(otherHandler) ||
654
+ otherHandler.shouldRequireToWaitForFailure(this))
655
+ );
656
+ logger.debug(result)
657
+ return result
658
+ }
659
+
660
+ reset(): void {
661
+ const stopTracing = this.logger.cloneAndJoinPrefix("reset").startTracing()
662
+ this.tracker.resetTracker();
663
+ this.onReset();
664
+ this.resetProgress();
665
+ // this.eventManagers.forEach((manager: EventManager) =>
666
+ // manager.resetManager()
667
+ // );
668
+ this.currentState = State.UNDETERMINED;
669
+ stopTracing()
670
+ }
671
+
672
+ isAwaiting(): boolean {
673
+ return this.isAwaiting_
674
+ }
675
+
676
+ setActive(isActivated: boolean): void {
677
+ this.isActivated = isActivated
678
+ }
679
+
680
+ setActivationIndex(value: number): void {
681
+ this.activationIndex = value
682
+ }
683
+
684
+ setShouldResetProgress(value: boolean): void {
685
+ this.shouldResetProgress = value;
686
+ }
687
+
688
+ fail(): void {
689
+ const stopTracing = this.logger.cloneAndJoinPrefix('fail').startTracing()
690
+ if (
691
+ this.currentState === State.ACTIVE ||
692
+ this.currentState === State.BEGAN
693
+ ) {
694
+ this.moveToState(State.FAILED);
695
+ }
696
+ this.resetProgress();
697
+ stopTracing()
698
+ }
699
+
700
+ shouldBeCancelledByOther(otherHandler: GestureHandler): boolean {
701
+ if (otherHandler === this) {
702
+ return false;
703
+ }
704
+ return this.interactionManager.shouldHandlerBeCancelledBy(this, otherHandler);
705
+ }
706
+
707
+ getTrackedPointersID(): PointerId[] {
708
+ return this.tracker.getTrackedPointersID()
709
+ }
710
+
711
+ shouldRecognizeSimultaneously(otherHandler: GestureHandler): boolean {
712
+ const stopTracing =
713
+ this.logger.cloneAndJoinPrefix(`shouldRecognizeSimultaneously(${otherHandler.getTag()})`).startTracing()
714
+ if (otherHandler === this) {
715
+ stopTracing
716
+ return true;
717
+ }
718
+ const result = this.interactionManager.shouldRecognizeSimultaneously(this, otherHandler);
719
+ stopTracing()
720
+ return result;
721
+ }
722
+
723
+ public getPointerType(): PointerType {
724
+ return this.pointerType
725
+ }
726
+
727
+ protected setShouldCancelWhenOutside(shouldCancel: boolean) {
728
+ this.shouldCancelWhenOutside = shouldCancel
729
+ }
730
+
731
+ public end() {
732
+ const stopTracing = this.logger.cloneAndJoinPrefix("end").startTracing()
733
+ if (this.currentState === State.BEGAN || this.currentState === State.ACTIVE) {
734
+ this.moveToState(State.END);
735
+ }
736
+ this.resetProgress();
737
+ stopTracing()
738
+ }
739
+ }