@react-native-oh-tpl/react-native-gesture-handler 2.14.16 → 2.14.17-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/DrawerLayout/index.ts +2 -2
  2. package/Swipeable/index.ts +2 -2
  3. package/harmony/gesture_handler.har +0 -0
  4. package/lib/commonjs/RNGestureHandlerModule.js.map +1 -1
  5. package/lib/commonjs/components/GestureHandlerRootView.js.map +1 -1
  6. package/lib/commonjs/handlers/createHandler.js.map +1 -1
  7. package/lib/commonjs/index.js.map +1 -1
  8. package/lib/commonjs/specs/NativeRNGestureHandlerModule.js.map +1 -1
  9. package/lib/commonjs/specs/RNGestureHandlerButtonNativeComponent.js.map +1 -1
  10. package/lib/commonjs/specs/RNGestureHandlerRootViewNativeComponent.js.map +1 -1
  11. package/lib/module/RNGestureHandlerModule.js.map +1 -1
  12. package/lib/module/components/GestureHandlerRootView.js.map +1 -1
  13. package/lib/module/handlers/createHandler.js.map +1 -1
  14. package/lib/module/index.js.map +1 -1
  15. package/lib/module/specs/NativeRNGestureHandlerModule.js.map +1 -1
  16. package/lib/module/specs/RNGestureHandlerButtonNativeComponent.js.map +1 -1
  17. package/lib/module/specs/RNGestureHandlerRootViewNativeComponent.js.map +1 -1
  18. package/lib/typescript/RNGestureHandlerModule.d.ts +2 -2
  19. package/lib/typescript/components/GestureHandlerRootView.d.ts +6 -6
  20. package/lib/typescript/handlers/createHandler.d.ts +11 -11
  21. package/lib/typescript/index.d.ts +47 -47
  22. package/lib/typescript/specs/NativeRNGestureHandlerModule.d.ts +14 -14
  23. package/lib/typescript/specs/RNGestureHandlerButtonNativeComponent.d.ts +14 -14
  24. package/lib/typescript/specs/RNGestureHandlerRootViewNativeComponent.d.ts +6 -6
  25. package/package.json +83 -78
  26. package/src/RNGestureHandlerModule.ts +4 -4
  27. package/src/components/GestureHandlerRootView.tsx +23 -23
  28. package/src/handlers/createHandler.tsx +534 -534
  29. package/src/index.ts +172 -172
  30. package/src/specs/NativeRNGestureHandlerModule.ts +26 -26
  31. package/src/specs/RNGestureHandlerButtonNativeComponent.ts +18 -18
  32. package/src/specs/RNGestureHandlerRootViewNativeComponent.ts +6 -6
  33. package/harmony/gesture_handler/BuildProfile.ets +0 -17
  34. package/harmony/gesture_handler/build-profile.json5 +0 -12
  35. package/harmony/gesture_handler/hvigorfile.ts +0 -2
  36. package/harmony/gesture_handler/index.ets +0 -2
  37. package/harmony/gesture_handler/oh-package-lock.json5 +0 -19
  38. package/harmony/gesture_handler/oh-package.json5 +0 -12
  39. package/harmony/gesture_handler/src/main/cpp/CMakeLists.txt +0 -8
  40. package/harmony/gesture_handler/src/main/cpp/GestureHandlerPackage.h +0 -12
  41. package/harmony/gesture_handler/src/main/cpp/RnohReactNativeHarmonyGestureHandlerPackage.cpp +0 -123
  42. package/harmony/gesture_handler/src/main/cpp/RnohReactNativeHarmonyGestureHandlerPackage.h +0 -15
  43. package/harmony/gesture_handler/src/main/cpp/componentInstances/RNGestureHandlerButtonComponentInstance.h +0 -27
  44. package/harmony/gesture_handler/src/main/cpp/componentInstances/RNGestureHandlerRootViewComponentInstance.h +0 -245
  45. package/harmony/gesture_handler/src/main/ets/RNOHPackage.ets +0 -17
  46. package/harmony/gesture_handler/src/main/ets/core/CircularBuffer.ts +0 -42
  47. package/harmony/gesture_handler/src/main/ets/core/GestureHandler.ts +0 -739
  48. package/harmony/gesture_handler/src/main/ets/core/GestureHandlerOrchestrator.ts +0 -344
  49. package/harmony/gesture_handler/src/main/ets/core/GestureHandlerRegistry.ts +0 -63
  50. package/harmony/gesture_handler/src/main/ets/core/IncomingEvent.ts +0 -78
  51. package/harmony/gesture_handler/src/main/ets/core/InteractionManager.ts +0 -144
  52. package/harmony/gesture_handler/src/main/ets/core/LeastSquareSolver.ts +0 -182
  53. package/harmony/gesture_handler/src/main/ets/core/Multiset.ts +0 -26
  54. package/harmony/gesture_handler/src/main/ets/core/OutgoingEvent.ts +0 -34
  55. package/harmony/gesture_handler/src/main/ets/core/OutgoingEventDispatcher.ts +0 -12
  56. package/harmony/gesture_handler/src/main/ets/core/PointerTracker.ts +0 -239
  57. package/harmony/gesture_handler/src/main/ets/core/RNGHError.ts +0 -5
  58. package/harmony/gesture_handler/src/main/ets/core/RNGHLogger.ts +0 -16
  59. package/harmony/gesture_handler/src/main/ets/core/State.ts +0 -47
  60. package/harmony/gesture_handler/src/main/ets/core/Vector2D.ts +0 -80
  61. package/harmony/gesture_handler/src/main/ets/core/VelocityTracker.ts +0 -106
  62. package/harmony/gesture_handler/src/main/ets/core/View.ts +0 -21
  63. package/harmony/gesture_handler/src/main/ets/core/ViewRegistry.ts +0 -7
  64. package/harmony/gesture_handler/src/main/ets/core/index.ts +0 -15
  65. package/harmony/gesture_handler/src/main/ets/detectors/ScaleGestureDetector.ts +0 -169
  66. package/harmony/gesture_handler/src/main/ets/gesture-handlers/FlingGestureHandler.ts +0 -219
  67. package/harmony/gesture_handler/src/main/ets/gesture-handlers/GestureHandlerFactory.ts +0 -67
  68. package/harmony/gesture_handler/src/main/ets/gesture-handlers/LongPressGestureHandler.ts +0 -139
  69. package/harmony/gesture_handler/src/main/ets/gesture-handlers/ManualGestureHandler.ts +0 -50
  70. package/harmony/gesture_handler/src/main/ets/gesture-handlers/NativeViewGestureHandler.ts +0 -124
  71. package/harmony/gesture_handler/src/main/ets/gesture-handlers/PanGestureHandler.ts +0 -375
  72. package/harmony/gesture_handler/src/main/ets/gesture-handlers/PinchGestureHandler.ts +0 -174
  73. package/harmony/gesture_handler/src/main/ets/gesture-handlers/RotationGestureHandler.ts +0 -172
  74. package/harmony/gesture_handler/src/main/ets/gesture-handlers/TapGestureHandler.ts +0 -216
  75. package/harmony/gesture_handler/src/main/ets/gesture-handlers/detectors/RotationGestureDetector.ts +0 -167
  76. package/harmony/gesture_handler/src/main/ets/gesture-handlers/index.ts +0 -1
  77. package/harmony/gesture_handler/src/main/ets/rnoh/GestureHandlerPackage.ts +0 -25
  78. package/harmony/gesture_handler/src/main/ets/rnoh/Logger.ts +0 -107
  79. package/harmony/gesture_handler/src/main/ets/rnoh/OutgoingEventDispatchers.ts +0 -94
  80. package/harmony/gesture_handler/src/main/ets/rnoh/RNGHRootViewController.ts +0 -196
  81. package/harmony/gesture_handler/src/main/ets/rnoh/RNGHView.ts +0 -89
  82. package/harmony/gesture_handler/src/main/ets/rnoh/RNGHViewController.ts +0 -255
  83. package/harmony/gesture_handler/src/main/ets/rnoh/RNGHViewRegistry.ts +0 -19
  84. package/harmony/gesture_handler/src/main/ets/rnoh/RNGestureHandlerModule.ts +0 -267
  85. package/harmony/gesture_handler/src/main/ets/rnoh/RNOHGestureResponder.ts +0 -15
  86. package/harmony/gesture_handler/src/main/ets/rnoh/RNOHScrollLocker.ts +0 -25
  87. package/harmony/gesture_handler/src/main/ets/rnoh/types.ts +0 -25
  88. package/harmony/gesture_handler/src/main/module.json5 +0 -9
  89. package/harmony/gesture_handler/src/main/resources/base/element/color.json +0 -8
  90. package/harmony/gesture_handler/src/main/resources/base/element/string.json +0 -16
  91. package/harmony/gesture_handler/src/main/resources/base/media/icon.png +0 -0
  92. package/harmony/gesture_handler/src/main/resources/base/profile/main_pages.json +0 -5
  93. package/harmony/gesture_handler/src/main/resources/en_US/element/string.json +0 -16
  94. package/harmony/gesture_handler/src/main/resources/zh_CN/element/string.json +0 -16
  95. package/harmony/gesture_handler/ts.ts +0 -2
@@ -1,739 +0,0 @@
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
- }