@react-native-oh-tpl/react-native-gesture-handler 2.14.1-2.14.12 → 2.14.1-2.14.14
Sign up to get free protection for your applications and to get access to all the features.
- package/harmony/gesture_handler/BuildProfile.ets +1 -1
- package/harmony/gesture_handler/index.ets +1 -2
- package/harmony/gesture_handler/oh-package-lock.json5 +1 -1
- package/harmony/gesture_handler/oh-package.json5 +3 -3
- package/harmony/gesture_handler/src/main/cpp/CMakeLists.txt +1 -1
- package/harmony/gesture_handler/src/main/cpp/GestureHandlerPackage.h +9 -18
- package/harmony/gesture_handler/src/main/cpp/RnohReactNativeHarmonyGestureHandlerPackage.cpp +157 -0
- package/harmony/gesture_handler/src/main/cpp/RnohReactNativeHarmonyGestureHandlerPackage.h +21 -0
- package/harmony/gesture_handler/src/main/cpp/componentInstances/RNGestureHandlerButtonComponentInstance.h +16 -16
- package/harmony/gesture_handler/src/main/cpp/componentInstances/RNGestureHandlerRootViewComponentInstance.h +202 -199
- package/harmony/gesture_handler/src/main/ets/RNOHPackage.ets +17 -0
- package/harmony/gesture_handler/src/main/ets/core/GestureHandler.ts +92 -37
- package/harmony/gesture_handler/src/main/ets/core/GestureHandlerOrchestrator.ts +20 -11
- package/harmony/gesture_handler/src/main/ets/core/GestureHandlerRegistry.ts +31 -3
- package/harmony/gesture_handler/src/main/ets/core/InteractionManager.ts +4 -4
- package/harmony/gesture_handler/src/main/ets/core/Multiset.ts +26 -0
- package/harmony/gesture_handler/src/main/ets/core/RNGHLogger.ts +7 -3
- package/harmony/gesture_handler/src/main/ets/core/ViewRegistry.ts +7 -0
- package/harmony/gesture_handler/src/main/ets/core/index.ts +3 -1
- package/harmony/gesture_handler/src/main/ets/gesture-handlers/FlingGestureHandler.ts +12 -4
- package/harmony/gesture_handler/src/main/ets/gesture-handlers/GestureHandlerFactory.ts +8 -5
- package/harmony/gesture_handler/src/main/ets/gesture-handlers/LongPressGestureHandler.ts +14 -2
- package/harmony/gesture_handler/src/main/ets/gesture-handlers/ManualGestureHandler.ts +9 -1
- package/harmony/gesture_handler/src/main/ets/gesture-handlers/NativeViewGestureHandler.ts +13 -4
- package/harmony/gesture_handler/src/main/ets/gesture-handlers/PanGestureHandler.ts +31 -12
- package/harmony/gesture_handler/src/main/ets/gesture-handlers/PinchGestureHandler.ts +145 -130
- package/harmony/gesture_handler/src/main/ets/gesture-handlers/RotationGestureHandler.ts +9 -1
- package/harmony/gesture_handler/src/main/ets/gesture-handlers/TapGestureHandler.ts +15 -5
- package/harmony/gesture_handler/src/main/ets/rnoh/GestureHandlerPackage.ts +7 -4
- package/harmony/gesture_handler/src/main/ets/rnoh/Logger.ts +74 -16
- package/harmony/gesture_handler/src/main/ets/rnoh/OutgoingEventDispatchers.ts +35 -12
- package/harmony/gesture_handler/src/main/ets/rnoh/RNGHRootViewController.ts +182 -0
- package/harmony/gesture_handler/src/main/ets/rnoh/RNGHView.ts +62 -0
- package/harmony/gesture_handler/src/main/ets/rnoh/{GestureHandlerArkUIAdapter.ts → RNGHViewController.ts} +44 -22
- package/harmony/gesture_handler/src/main/ets/rnoh/RNGHViewRegistry.ts +19 -0
- package/harmony/gesture_handler/src/main/ets/rnoh/RNGestureHandlerModule.ts +130 -95
- package/harmony/gesture_handler/src/main/ets/rnoh/RNOHGestureResponder.ts +0 -9
- package/harmony/gesture_handler/src/main/ets/rnoh/RNOHScrollLocker.ts +1 -8
- package/harmony/gesture_handler.har +0 -0
- package/package.json +7 -3
- package/harmony/gesture_handler/src/main/cpp/GestureHandlerPackage.cpp +0 -149
- package/harmony/gesture_handler/src/main/ets/rnoh/RNGHRootTouchHandlerArkTS.ts +0 -108
- package/harmony/gesture_handler/src/main/ets/rnoh/RNGHRootTouchHandlerCAPI.ts +0 -110
- package/harmony/gesture_handler/src/main/ets/rnoh/RNGestureHandlerButton.ets +0 -38
- package/harmony/gesture_handler/src/main/ets/rnoh/RNGestureHandlerRootView.ets +0 -53
- package/harmony/gesture_handler/src/main/ets/rnoh/View.ts +0 -134
- package/harmony/gesture_handler/src/main/ets/rnoh/ViewRegistry.ts +0 -95
@@ -107,11 +107,15 @@ export abstract class GestureHandler<TGestureConfig extends GestureConfig = Gest
|
|
107
107
|
this.orchestrator = deps.orchestrator
|
108
108
|
this.tracker = deps.tracker
|
109
109
|
this.interactionManager = deps.interactionManager
|
110
|
-
this.logger = deps.logger
|
110
|
+
this.logger = deps.logger.cloneAndJoinPrefix("GestureHandler")
|
111
111
|
this.scrollLocker = deps.scrollLocker
|
112
112
|
this.rnGestureResponder = deps.rnGestureResponder
|
113
113
|
}
|
114
114
|
|
115
|
+
public abstract getName(): string;
|
116
|
+
|
117
|
+
public abstract isGestureContinuous(): boolean;
|
118
|
+
|
115
119
|
public setEventDispatcher(eventDispatcher: OutgoingEventDispatcher) {
|
116
120
|
// TurboModule provides info about kind of event dispatcher when attaching GH to a view, not when GH is created.
|
117
121
|
// This method must be called before any other
|
@@ -119,7 +123,7 @@ export abstract class GestureHandler<TGestureConfig extends GestureConfig = Gest
|
|
119
123
|
}
|
120
124
|
|
121
125
|
public onPointerDown(e: IncomingEvent) {
|
122
|
-
this.logger.
|
126
|
+
const stopTracing = this.logger.cloneAndJoinPrefix("onPointerDown").startTracing()
|
123
127
|
this.orchestrator.registerHandlerIfNotPresent(this);
|
124
128
|
this.pointerType = e.pointerType;
|
125
129
|
if (this.pointerType === PointerType.TOUCH) {
|
@@ -128,6 +132,7 @@ export abstract class GestureHandler<TGestureConfig extends GestureConfig = Gest
|
|
128
132
|
if (this.config.needsPointerData) {
|
129
133
|
this.sendTouchEvent(e);
|
130
134
|
}
|
135
|
+
stopTracing()
|
131
136
|
}
|
132
137
|
|
133
138
|
protected sendTouchEvent(e: IncomingEvent) {
|
@@ -137,7 +142,7 @@ export abstract class GestureHandler<TGestureConfig extends GestureConfig = Gest
|
|
137
142
|
|
138
143
|
|
139
144
|
const touchEvent: GestureTouchEvent | undefined =
|
140
|
-
|
145
|
+
this.transformToTouchEvent(e);
|
141
146
|
|
142
147
|
if (touchEvent) {
|
143
148
|
this.eventDispatcher.onGestureHandlerEvent(touchEvent)
|
@@ -238,35 +243,47 @@ export abstract class GestureHandler<TGestureConfig extends GestureConfig = Gest
|
|
238
243
|
}
|
239
244
|
|
240
245
|
public onPointerUp(e: IncomingEvent): void {
|
241
|
-
this.logger.
|
242
|
-
if (this.config.needsPointerData)
|
246
|
+
const stopTracing = this.logger.cloneAndJoinPrefix("onPointerUp").startTracing()
|
247
|
+
if (this.config.needsPointerData) {
|
248
|
+
this.sendTouchEvent(e)
|
249
|
+
}
|
250
|
+
stopTracing()
|
243
251
|
}
|
244
252
|
|
245
253
|
public onAdditionalPointerAdd(e: IncomingEvent): void {
|
246
|
-
this.logger.
|
247
|
-
if (this.config.needsPointerData)
|
254
|
+
const stopTracing = this.logger.cloneAndJoinPrefix("onAdditionalPointerAdd").startTracing()
|
255
|
+
if (this.config.needsPointerData) {
|
256
|
+
this.sendTouchEvent(e)
|
257
|
+
}
|
258
|
+
stopTracing()
|
248
259
|
}
|
249
260
|
|
250
261
|
public onAdditionalPointerRemove(e: IncomingEvent): void {
|
251
|
-
this.logger.
|
252
|
-
if (this.config.needsPointerData)
|
262
|
+
const stopTracing = this.logger.cloneAndJoinPrefix("onAdditionalPointerRemove").startTracing()
|
263
|
+
if (this.config.needsPointerData) {
|
264
|
+
this.sendTouchEvent(e)
|
265
|
+
}
|
266
|
+
stopTracing()
|
253
267
|
}
|
254
268
|
|
255
269
|
public onPointerMove(e: IncomingEvent): void {
|
256
|
-
this.logger.
|
270
|
+
const stopTracing = this.logger.cloneAndJoinPrefix("onPointerMove").startTracing()
|
257
271
|
this.tryToSendMoveEvent(false);
|
258
272
|
if (this.config.needsPointerData) {
|
259
273
|
this.sendTouchEvent(e);
|
260
274
|
}
|
275
|
+
stopTracing()
|
261
276
|
}
|
262
277
|
|
263
278
|
private tryToSendMoveEvent(out: boolean): void {
|
264
|
-
this.logger.
|
279
|
+
const logger = this.logger.cloneAndJoinPrefix(`tryToSendMoveEvent`)
|
280
|
+
const stopTracing = logger.startTracing()
|
281
|
+
logger.debug({
|
265
282
|
out,
|
266
283
|
enabled: this.config.enabled,
|
267
284
|
isActivated: this.isActivated,
|
268
285
|
shouldCancelWhenOutside: this.shouldCancelWhenOutside
|
269
|
-
})
|
286
|
+
})
|
270
287
|
if (
|
271
288
|
this.config.enabled &&
|
272
289
|
this.isActivated &&
|
@@ -274,17 +291,19 @@ export abstract class GestureHandler<TGestureConfig extends GestureConfig = Gest
|
|
274
291
|
) {
|
275
292
|
this.sendEvent({ newState: this.currentState, oldState: this.currentState });
|
276
293
|
}
|
294
|
+
stopTracing()
|
277
295
|
}
|
278
296
|
|
279
297
|
public onPointerEnter(e: IncomingEvent): void {
|
280
|
-
this.logger.
|
298
|
+
const stopTracing = this.logger.cloneAndJoinPrefix("onPointerEnter").startTracing()
|
281
299
|
if (this.config.needsPointerData) {
|
282
300
|
this.sendTouchEvent(e)
|
283
301
|
}
|
302
|
+
stopTracing()
|
284
303
|
}
|
285
304
|
|
286
305
|
public onPointerOut(e: IncomingEvent): void {
|
287
|
-
this.logger.
|
306
|
+
const stopTracing = this.logger.cloneAndJoinPrefix("onPointerOut").startTracing()
|
288
307
|
if (this.shouldCancelWhenOutside) {
|
289
308
|
switch (this.currentState) {
|
290
309
|
case State.ACTIVE:
|
@@ -294,33 +313,38 @@ export abstract class GestureHandler<TGestureConfig extends GestureConfig = Gest
|
|
294
313
|
this.fail();
|
295
314
|
break;
|
296
315
|
}
|
316
|
+
stopTracing()
|
297
317
|
return;
|
298
318
|
}
|
299
319
|
if (this.config.needsPointerData) {
|
300
320
|
this.sendTouchEvent(e);
|
301
321
|
}
|
322
|
+
stopTracing()
|
302
323
|
}
|
303
324
|
|
304
325
|
public onPointerCancel(e: IncomingEvent): void {
|
305
|
-
this.logger.
|
326
|
+
const stopTracing = this.logger.cloneAndJoinPrefix("onPointerCancel").startTracing()
|
306
327
|
if (this.config.needsPointerData) {
|
307
328
|
this.sendTouchEvent(e);
|
308
329
|
}
|
309
330
|
this.cancel();
|
310
331
|
this.reset();
|
332
|
+
stopTracing()
|
311
333
|
}
|
312
334
|
|
313
335
|
public onPointerOutOfBounds(e: IncomingEvent): void {
|
314
|
-
this.logger.
|
336
|
+
const stopTracing = this.logger.cloneAndJoinPrefix("onPointerOutOfBounds").startTracing()
|
315
337
|
this.tryToSendMoveEvent(true);
|
316
338
|
if (this.config.needsPointerData) {
|
317
339
|
this.sendTouchEvent(e);
|
318
340
|
}
|
341
|
+
stopTracing()
|
319
342
|
}
|
320
343
|
|
321
344
|
public onViewAttached(view: View) {
|
322
|
-
this.logger.
|
345
|
+
const stopTracing = this.logger.cloneAndJoinPrefix("onViewAttached").startTracing()
|
323
346
|
this.view = view
|
347
|
+
stopTracing()
|
324
348
|
}
|
325
349
|
|
326
350
|
public getTag(): number {
|
@@ -336,11 +360,15 @@ export abstract class GestureHandler<TGestureConfig extends GestureConfig = Gest
|
|
336
360
|
}
|
337
361
|
|
338
362
|
public begin(): void {
|
339
|
-
this.logger.
|
340
|
-
if (!this.isWithinHitSlop())
|
363
|
+
const stopTracing = this.logger.cloneAndJoinPrefix("begin").startTracing()
|
364
|
+
if (!this.isWithinHitSlop()) {
|
365
|
+
stopTracing()
|
366
|
+
return;
|
367
|
+
}
|
341
368
|
if (this.currentState === State.UNDETERMINED) {
|
342
369
|
this.moveToState(State.BEGAN);
|
343
370
|
}
|
371
|
+
stopTracing()
|
344
372
|
}
|
345
373
|
|
346
374
|
private isWithinHitSlop(): boolean {
|
@@ -413,15 +441,20 @@ export abstract class GestureHandler<TGestureConfig extends GestureConfig = Gest
|
|
413
441
|
}
|
414
442
|
|
415
443
|
public activate(): void {
|
416
|
-
this.logger.
|
417
|
-
if (!this.config.manualActivation || this.currentState === State.UNDETERMINED ||
|
444
|
+
const stopTracing = this.logger.cloneAndJoinPrefix("activate").startTracing()
|
445
|
+
if (!this.config.manualActivation || this.currentState === State.UNDETERMINED ||
|
446
|
+
this.currentState === State.BEGAN) {
|
418
447
|
this.moveToState(State.ACTIVE)
|
419
448
|
}
|
449
|
+
stopTracing()
|
420
450
|
}
|
421
451
|
|
422
452
|
protected moveToState(state: State) {
|
423
|
-
this.logger.
|
424
|
-
if (state === this.currentState)
|
453
|
+
const stopTracing = this.logger.cloneAndJoinPrefix(`moveToState ${getStateName(state)}`).startTracing()
|
454
|
+
if (state === this.currentState) {
|
455
|
+
stopTracing()
|
456
|
+
return;
|
457
|
+
}
|
425
458
|
const oldState = this.currentState
|
426
459
|
this.currentState = state;
|
427
460
|
if (this.tracker.getTrackedPointersCount() > 0 && this.config.needsPointerData && this.isFinished()) {
|
@@ -433,6 +466,7 @@ export abstract class GestureHandler<TGestureConfig extends GestureConfig = Gest
|
|
433
466
|
if (!this.isEnabled() && this.isFinished()) {
|
434
467
|
this.currentState = State.UNDETERMINED;
|
435
468
|
}
|
469
|
+
stopTracing()
|
436
470
|
}
|
437
471
|
|
438
472
|
private isFinished() {
|
@@ -522,7 +556,7 @@ export abstract class GestureHandler<TGestureConfig extends GestureConfig = Gest
|
|
522
556
|
}
|
523
557
|
|
524
558
|
public cancel(): void {
|
525
|
-
this.logger.
|
559
|
+
const stopTracing = this.logger.cloneAndJoinPrefix(`cancel`).startTracing()
|
526
560
|
if (
|
527
561
|
this.currentState === State.ACTIVE ||
|
528
562
|
this.currentState === State.UNDETERMINED ||
|
@@ -531,6 +565,7 @@ export abstract class GestureHandler<TGestureConfig extends GestureConfig = Gest
|
|
531
565
|
this.onCancel();
|
532
566
|
this.moveToState(State.CANCELLED);
|
533
567
|
}
|
568
|
+
stopTracing()
|
534
569
|
}
|
535
570
|
|
536
571
|
protected onCancel(): void {
|
@@ -546,11 +581,14 @@ export abstract class GestureHandler<TGestureConfig extends GestureConfig = Gest
|
|
546
581
|
return this.currentState
|
547
582
|
}
|
548
583
|
|
549
|
-
public sendEvent({newState, oldState}: {
|
584
|
+
public sendEvent({ newState, oldState }: {
|
550
585
|
oldState: State,
|
551
586
|
newState: State
|
552
587
|
}): void {
|
553
|
-
const logger =
|
588
|
+
const logger =
|
589
|
+
this.logger.cloneAndJoinPrefix(`sendEvent`)
|
590
|
+
const stopTracing = logger.startTracing()
|
591
|
+
logger.debug({ tag: this.getTag(), newState, oldState })
|
554
592
|
const stateChangeEvent = this.createStateChangeEvent(newState, oldState);
|
555
593
|
if (this.lastSentState !== newState) {
|
556
594
|
this.lastSentState = newState;
|
@@ -562,6 +600,7 @@ export abstract class GestureHandler<TGestureConfig extends GestureConfig = Gest
|
|
562
600
|
logger.debug("calling onGestureHandlerEvent")
|
563
601
|
this.eventDispatcher.onGestureHandlerEvent(stateChangeEvent);
|
564
602
|
}
|
603
|
+
stopTracing()
|
565
604
|
}
|
566
605
|
|
567
606
|
private createStateChangeEvent(newState: State, oldState: State): GestureStateChangeEvent {
|
@@ -579,8 +618,14 @@ export abstract class GestureHandler<TGestureConfig extends GestureConfig = Gest
|
|
579
618
|
};
|
580
619
|
}
|
581
620
|
|
582
|
-
protected transformNativeEvent() {
|
583
|
-
|
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
|
+
};
|
584
629
|
}
|
585
630
|
|
586
631
|
setAwaiting(isAwaiting: boolean): void {
|
@@ -588,19 +633,21 @@ export abstract class GestureHandler<TGestureConfig extends GestureConfig = Gest
|
|
588
633
|
}
|
589
634
|
|
590
635
|
shouldWaitForHandlerFailure(handler: GestureHandler): boolean {
|
591
|
-
if (handler === this)
|
636
|
+
if (handler === this) {
|
592
637
|
return false;
|
638
|
+
}
|
593
639
|
return this.interactionManager.shouldWaitForHandlerFailure(this, handler);
|
594
640
|
}
|
595
641
|
|
596
642
|
shouldRequireToWaitForFailure(handler: GestureHandler): boolean {
|
597
|
-
if (handler === this)
|
643
|
+
if (handler === this) {
|
598
644
|
return false;
|
645
|
+
}
|
599
646
|
return this.interactionManager.shouldRequireHandlerToWaitForFailure(this, handler);
|
600
647
|
}
|
601
648
|
|
602
649
|
shouldWaitFor(otherHandler: GestureHandler): boolean {
|
603
|
-
const logger = this.logger.
|
650
|
+
const logger = this.logger.cloneAndJoinPrefix(`shouldWaitFor(${otherHandler.getTag()})`)
|
604
651
|
const result = (
|
605
652
|
this !== otherHandler &&
|
606
653
|
(this.shouldWaitForHandlerFailure(otherHandler) ||
|
@@ -611,7 +658,7 @@ export abstract class GestureHandler<TGestureConfig extends GestureConfig = Gest
|
|
611
658
|
}
|
612
659
|
|
613
660
|
reset(): void {
|
614
|
-
this.logger.
|
661
|
+
const stopTracing = this.logger.cloneAndJoinPrefix("reset").startTracing()
|
615
662
|
this.tracker.resetTracker();
|
616
663
|
this.onReset();
|
617
664
|
this.resetProgress();
|
@@ -619,6 +666,7 @@ export abstract class GestureHandler<TGestureConfig extends GestureConfig = Gest
|
|
619
666
|
// manager.resetManager()
|
620
667
|
// );
|
621
668
|
this.currentState = State.UNDETERMINED;
|
669
|
+
stopTracing()
|
622
670
|
}
|
623
671
|
|
624
672
|
isAwaiting(): boolean {
|
@@ -638,7 +686,7 @@ export abstract class GestureHandler<TGestureConfig extends GestureConfig = Gest
|
|
638
686
|
}
|
639
687
|
|
640
688
|
fail(): void {
|
641
|
-
this.logger.
|
689
|
+
const stopTracing = this.logger.cloneAndJoinPrefix('fail').startTracing()
|
642
690
|
if (
|
643
691
|
this.currentState === State.ACTIVE ||
|
644
692
|
this.currentState === State.BEGAN
|
@@ -646,11 +694,13 @@ export abstract class GestureHandler<TGestureConfig extends GestureConfig = Gest
|
|
646
694
|
this.moveToState(State.FAILED);
|
647
695
|
}
|
648
696
|
this.resetProgress();
|
697
|
+
stopTracing()
|
649
698
|
}
|
650
699
|
|
651
700
|
shouldBeCancelledByOther(otherHandler: GestureHandler): boolean {
|
652
|
-
if (otherHandler === this)
|
701
|
+
if (otherHandler === this) {
|
653
702
|
return false;
|
703
|
+
}
|
654
704
|
return this.interactionManager.shouldHandlerBeCancelledBy(this, otherHandler);
|
655
705
|
}
|
656
706
|
|
@@ -659,11 +709,15 @@ export abstract class GestureHandler<TGestureConfig extends GestureConfig = Gest
|
|
659
709
|
}
|
660
710
|
|
661
711
|
shouldRecognizeSimultaneously(otherHandler: GestureHandler): boolean {
|
662
|
-
|
712
|
+
const stopTracing =
|
713
|
+
this.logger.cloneAndJoinPrefix(`shouldRecognizeSimultaneously(${otherHandler.getTag()})`).startTracing()
|
663
714
|
if (otherHandler === this) {
|
715
|
+
stopTracing
|
664
716
|
return true;
|
665
717
|
}
|
666
|
-
|
718
|
+
const result = this.interactionManager.shouldRecognizeSimultaneously(this, otherHandler);
|
719
|
+
stopTracing()
|
720
|
+
return result;
|
667
721
|
}
|
668
722
|
|
669
723
|
public getPointerType(): PointerType {
|
@@ -675,10 +729,11 @@ export abstract class GestureHandler<TGestureConfig extends GestureConfig = Gest
|
|
675
729
|
}
|
676
730
|
|
677
731
|
public end() {
|
678
|
-
this.logger.
|
732
|
+
const stopTracing = this.logger.cloneAndJoinPrefix("end").startTracing()
|
679
733
|
if (this.currentState === State.BEGAN || this.currentState === State.ACTIVE) {
|
680
734
|
this.moveToState(State.END);
|
681
735
|
}
|
682
736
|
this.resetProgress();
|
737
|
+
stopTracing()
|
683
738
|
}
|
684
739
|
}
|
@@ -9,11 +9,15 @@ export class GestureHandlerOrchestrator {
|
|
9
9
|
private handlersToCancel: GestureHandler[] = []
|
10
10
|
private activationIndex: number = 0
|
11
11
|
|
12
|
-
|
12
|
+
private logger: RNGHLogger
|
13
|
+
|
14
|
+
constructor(logger: RNGHLogger) {
|
15
|
+
this.logger = logger.cloneAndJoinPrefix("GestureHandlerOrchestrator")
|
13
16
|
}
|
14
17
|
|
15
18
|
public onHandlerStateChange(handler: GestureHandler, newState: State, oldState: State, sendIfDisabled?: boolean) {
|
16
|
-
const logger =
|
19
|
+
const logger =
|
20
|
+
this.logger.cloneAndJoinPrefix(`onHandlerStateChange(handler=${handler.getTag()}, newState=${getStateName(newState)}, oldState=${getStateName(oldState)})`)
|
17
21
|
logger.debug("start")
|
18
22
|
|
19
23
|
if (!handler.isEnabled() && !sendIfDisabled) {
|
@@ -73,7 +77,7 @@ export class GestureHandlerOrchestrator {
|
|
73
77
|
}
|
74
78
|
|
75
79
|
private tryActivate(handler: GestureHandler): void {
|
76
|
-
const logger = this.logger.
|
80
|
+
const logger = this.logger.cloneAndJoinPrefix(`tryActivate(${handler.getTag()})`)
|
77
81
|
logger.debug({
|
78
82
|
gestureHandlers: this.gestureHandlers.map(gh => gh.getTag()),
|
79
83
|
awaitingHandlers: Array.from(this.awaitingHandlers).map(gh => gh.getTag()),
|
@@ -123,7 +127,7 @@ export class GestureHandlerOrchestrator {
|
|
123
127
|
}
|
124
128
|
|
125
129
|
private hasOtherHandlerToWaitFor(handler: GestureHandler): boolean {
|
126
|
-
const logger = this.logger.
|
130
|
+
const logger = this.logger.cloneAndJoinPrefix(`hasOtherHandlerToWaitFor(handler=${handler.getTag()})`)
|
127
131
|
for (const otherHandler of this.gestureHandlers) {
|
128
132
|
if (otherHandler === handler) {
|
129
133
|
return false
|
@@ -138,7 +142,7 @@ export class GestureHandlerOrchestrator {
|
|
138
142
|
}
|
139
143
|
|
140
144
|
private addAwaitingHandler(handler: GestureHandler) {
|
141
|
-
const logger = this.logger.
|
145
|
+
const logger = this.logger.cloneAndJoinPrefix(`addAwaitingHandler(handlerTag=${handler.getTag()})`)
|
142
146
|
logger.debug({ awaitingHandlers: this.awaitingHandlers })
|
143
147
|
if (!this.awaitingHandlers.has(handler)) {
|
144
148
|
this.awaitingHandlers.add(handler)
|
@@ -156,11 +160,12 @@ export class GestureHandlerOrchestrator {
|
|
156
160
|
return true
|
157
161
|
}
|
158
162
|
|
159
|
-
private shouldHandlerBeCancelledByOtherHandler({handler, otherHandler}: {
|
163
|
+
private shouldHandlerBeCancelledByOtherHandler({ handler, otherHandler }: {
|
160
164
|
handler: GestureHandler,
|
161
165
|
otherHandler: GestureHandler
|
162
166
|
}): boolean {
|
163
|
-
const logger =
|
167
|
+
const logger =
|
168
|
+
this.logger.cloneAndJoinPrefix(`shouldHandlerBeCancelledByOtherHandler(${handler.getTag()}, ${otherHandler.getTag()})`)
|
164
169
|
if (this.canRunSimultaneously(handler, otherHandler)) {
|
165
170
|
logger.debug("false")
|
166
171
|
return false;
|
@@ -176,7 +181,7 @@ export class GestureHandlerOrchestrator {
|
|
176
181
|
}
|
177
182
|
|
178
183
|
private canRunSimultaneously(handlerA: GestureHandler, handlerB: GestureHandler) {
|
179
|
-
const logger = this.logger.
|
184
|
+
const logger = this.logger.cloneAndJoinPrefix("canRunSimultaneously")
|
180
185
|
const result = handlerA === handlerB
|
181
186
|
|| handlerA.shouldRecognizeSimultaneously(handlerB)
|
182
187
|
|| handlerB.shouldRecognizeSimultaneously(handlerA)
|
@@ -275,7 +280,7 @@ export class GestureHandlerOrchestrator {
|
|
275
280
|
}
|
276
281
|
|
277
282
|
private cleanupAwaitingHandlers(handler: GestureHandler): void {
|
278
|
-
const logger = this.logger.
|
283
|
+
const logger = this.logger.cloneAndJoinPrefix(`cleanupAwaitingHandlers(handler=${handler.getTag()})`)
|
279
284
|
logger.debug({ awaitingHandlers: this.awaitingHandlers })
|
280
285
|
for (const awaitingHandler of this.awaitingHandlers) {
|
281
286
|
if (
|
@@ -297,7 +302,9 @@ export class GestureHandlerOrchestrator {
|
|
297
302
|
|
298
303
|
public registerHandlerIfNotPresent(handler: GestureHandler) {
|
299
304
|
this.logger.info(`registerHandlerIfNotPresent(${handler.getTag()})`)
|
300
|
-
if (this.gestureHandlers.includes(handler))
|
305
|
+
if (this.gestureHandlers.includes(handler)) {
|
306
|
+
return;
|
307
|
+
}
|
301
308
|
this.gestureHandlers.push(handler);
|
302
309
|
handler.setActive(false);
|
303
310
|
handler.setAwaiting(false);
|
@@ -315,7 +322,9 @@ export class GestureHandlerOrchestrator {
|
|
315
322
|
public cancelMouseAndPenGestures(currentHandler: GestureHandler): void {
|
316
323
|
this.logger.info("cancelMouseAndPenGestures")
|
317
324
|
this.gestureHandlers.forEach((handler: GestureHandler) => {
|
318
|
-
if (handler.getPointerType() !== PointerType.MOUSE && handler.getPointerType() !== PointerType.PEN)
|
325
|
+
if (handler.getPointerType() !== PointerType.MOUSE && handler.getPointerType() !== PointerType.PEN) {
|
326
|
+
return;
|
327
|
+
}
|
319
328
|
|
320
329
|
if (handler !== currentHandler) {
|
321
330
|
handler.cancel();
|
@@ -1,14 +1,17 @@
|
|
1
1
|
import { GestureHandler } from "./GestureHandler"
|
2
2
|
import { View } from "./View"
|
3
3
|
import { RNGHLogger } from "./RNGHLogger"
|
4
|
+
import { ViewRegistry } from "./ViewRegistry"
|
4
5
|
|
5
6
|
export class GestureHandlerRegistry {
|
6
7
|
private gestureHandlerByHandlerTag: Map<number, GestureHandler> = new Map()
|
7
8
|
private gestureHandlersByViewTag: Map<number, Set<GestureHandler>> = new Map()
|
9
|
+
private viewRegistry: ViewRegistry | undefined
|
8
10
|
private logger: RNGHLogger
|
9
11
|
|
10
|
-
constructor(logger: RNGHLogger) {
|
11
|
-
this.logger = logger.
|
12
|
+
constructor(viewRegistry: ViewRegistry | undefined, logger: RNGHLogger) {
|
13
|
+
this.logger = logger.cloneAndJoinPrefix("GestureHandlerRegistry")
|
14
|
+
this.viewRegistry = viewRegistry
|
12
15
|
}
|
13
16
|
|
14
17
|
public addGestureHandler(gestureHandler: GestureHandler) {
|
@@ -16,7 +19,7 @@ export class GestureHandlerRegistry {
|
|
16
19
|
}
|
17
20
|
|
18
21
|
public bindGestureHandlerWithView(gestureHandlerTag: number, view: View) {
|
19
|
-
this.logger.
|
22
|
+
this.logger.cloneAndJoinPrefix("bindGestureHandlerWithView").debug({gestureHandlerTag, viewTag: view.getTag()})
|
20
23
|
const viewTag = view.getTag()
|
21
24
|
if (!this.gestureHandlersByViewTag.has(viewTag))
|
22
25
|
this.gestureHandlersByViewTag.set(viewTag, new Set())
|
@@ -29,6 +32,31 @@ export class GestureHandlerRegistry {
|
|
29
32
|
return Array.from(this.gestureHandlersByViewTag.get(viewTag) ?? [])
|
30
33
|
}
|
31
34
|
|
35
|
+
public removeGestureHandlerByHandlerTag(handlerTag: number) {
|
36
|
+
const gestureHandler = this.gestureHandlerByHandlerTag.get(handlerTag)
|
37
|
+
if (!gestureHandler) {
|
38
|
+
return;
|
39
|
+
}
|
40
|
+
const viewTag = gestureHandler.getView()?.getTag();
|
41
|
+
if (viewTag) {
|
42
|
+
const gestureHandlers = this.gestureHandlersByViewTag.get(viewTag)
|
43
|
+
if (gestureHandlers) {
|
44
|
+
gestureHandlers.delete(gestureHandler)
|
45
|
+
if (gestureHandlers.size === 0) {
|
46
|
+
this.gestureHandlersByViewTag.delete(viewTag)
|
47
|
+
this.viewRegistry?.deleteByTag(viewTag)
|
48
|
+
}
|
49
|
+
}
|
50
|
+
}
|
51
|
+
if (gestureHandler.getView()) {
|
52
|
+
// Handler is in "prepared" state which means it is registered in the orchestrator and can
|
53
|
+
// receive touch events. This means that before we remove it from the registry we need to
|
54
|
+
// "cancel" it so that orchestrator does no longer keep a reference to it.
|
55
|
+
gestureHandler.cancel()
|
56
|
+
}
|
57
|
+
this.gestureHandlerByHandlerTag.delete(handlerTag)
|
58
|
+
}
|
59
|
+
|
32
60
|
public getGestureHandlerByHandlerTag(handlerTag: number): GestureHandler {
|
33
61
|
return this.gestureHandlerByHandlerTag.get(handlerTag)
|
34
62
|
}
|
@@ -9,7 +9,7 @@ export class InteractionManager {
|
|
9
9
|
private logger: RNGHLogger
|
10
10
|
|
11
11
|
constructor(logger: RNGHLogger) {
|
12
|
-
this.logger = logger.
|
12
|
+
this.logger = logger.cloneAndJoinPrefix("InteractionManager")
|
13
13
|
}
|
14
14
|
|
15
15
|
public configureInteractions(handler: GestureHandler, config: Config) {
|
@@ -60,7 +60,7 @@ export class InteractionManager {
|
|
60
60
|
handler: GestureHandler,
|
61
61
|
otherHandler: GestureHandler
|
62
62
|
): boolean {
|
63
|
-
const logger = this.logger.
|
63
|
+
const logger = this.logger.cloneAndJoinPrefix(`shouldWaitForHandlerFailure(${handler.getTag()}, ${otherHandler.getTag()})`)
|
64
64
|
const waitFor = this.waitForRelations.get(
|
65
65
|
handler.getTag()
|
66
66
|
);
|
@@ -85,7 +85,7 @@ export class InteractionManager {
|
|
85
85
|
handler: GestureHandler,
|
86
86
|
otherHandler: GestureHandler
|
87
87
|
): boolean {
|
88
|
-
const logger = this.logger.
|
88
|
+
const logger = this.logger.cloneAndJoinPrefix(`shouldRecognizeSimultaneously(${handler.getTag()}, ${otherHandler.getTag()})`)
|
89
89
|
const simultaneousHandlers: number[] | undefined =
|
90
90
|
this.simultaneousRelations.get(handler.getTag());
|
91
91
|
if (!simultaneousHandlers) {
|
@@ -122,7 +122,7 @@ export class InteractionManager {
|
|
122
122
|
handler: GestureHandler,
|
123
123
|
otherHandler: GestureHandler
|
124
124
|
): boolean {
|
125
|
-
const logger = this.logger.
|
125
|
+
const logger = this.logger.cloneAndJoinPrefix(`shouldHandlerBeCancelledBy(handler=${handler.getTag()}, otherHandler=${otherHandler.getTag()})`)
|
126
126
|
// We check constructor name instead of using `instanceof` in order do avoid circular dependencies
|
127
127
|
// const isNativeHandler =
|
128
128
|
// otherHandler.constructor.name === 'NativeViewGestureHandler';
|
@@ -0,0 +1,26 @@
|
|
1
|
+
export class Multiset<T> {
|
2
|
+
private multiplicityByElement: Map<T, number> = new Map();
|
3
|
+
private elements: T[] = [];
|
4
|
+
|
5
|
+
add(element: T) {
|
6
|
+
const count = this.multiplicityByElement.get(element) || 0;
|
7
|
+
if (count === 0) {
|
8
|
+
this.elements.push(element);
|
9
|
+
}
|
10
|
+
this.multiplicityByElement.set(element, count + 1);
|
11
|
+
}
|
12
|
+
|
13
|
+
remove(element: T) {
|
14
|
+
const count = this.multiplicityByElement.get(element) || 0;
|
15
|
+
if (count > 1) {
|
16
|
+
this.multiplicityByElement.set(element, count - 1);
|
17
|
+
} else {
|
18
|
+
this.multiplicityByElement.delete(element);
|
19
|
+
this.elements = this.elements.filter(v => v !== element);
|
20
|
+
}
|
21
|
+
}
|
22
|
+
|
23
|
+
getElements() {
|
24
|
+
return this.elements;
|
25
|
+
}
|
26
|
+
}
|
@@ -1,12 +1,16 @@
|
|
1
1
|
export type RNGHLoggerMessage = string | Object
|
2
2
|
|
3
3
|
export interface RNGHLogger {
|
4
|
-
|
5
|
-
|
6
|
-
cloneWithPrefix(prefix: string): RNGHLogger;
|
4
|
+
cloneAndJoinPrefix(prefix: string): RNGHLogger;
|
7
5
|
|
8
6
|
debug(msg: RNGHLoggerMessage);
|
9
7
|
|
8
|
+
info(msg: string): void;
|
9
|
+
|
10
|
+
warn(warn: string);
|
11
|
+
|
10
12
|
error(msg: string);
|
13
|
+
|
14
|
+
startTracing(): () => void
|
11
15
|
}
|
12
16
|
|
@@ -10,4 +10,6 @@ export * from "./InteractionManager"
|
|
10
10
|
export * from "./PointerTracker"
|
11
11
|
export * from "./RNGHError"
|
12
12
|
export * from "./State"
|
13
|
-
export * from "./GestureHandlerRegistry"
|
13
|
+
export * from "./GestureHandlerRegistry"
|
14
|
+
export * from "./ViewRegistry"
|
15
|
+
export * from './Multiset'
|
@@ -28,7 +28,15 @@ const DIAGONAL_DEVIATION_COSINE = coneToDeviation(90 - DEFAULT_ALIGNMENT_CONE);
|
|
28
28
|
|
29
29
|
export class FlingGestureHandler extends GestureHandler {
|
30
30
|
constructor(deps: GestureHandlerDependencies) {
|
31
|
-
super({ ...deps, logger: deps.logger.
|
31
|
+
super({ ...deps, logger: deps.logger.cloneAndJoinPrefix("FlingGestureHandler") })
|
32
|
+
}
|
33
|
+
|
34
|
+
override getName(): string {
|
35
|
+
return "FlingGestureHandler"
|
36
|
+
}
|
37
|
+
|
38
|
+
override isGestureContinuous(): boolean {
|
39
|
+
return true
|
32
40
|
}
|
33
41
|
|
34
42
|
getDefaultConfig() {
|
@@ -65,7 +73,7 @@ export class FlingGestureHandler extends GestureHandler {
|
|
65
73
|
}
|
66
74
|
|
67
75
|
private tryEndFling(): boolean {
|
68
|
-
const logger = this.logger.
|
76
|
+
const logger = this.logger.cloneAndJoinPrefix("tryEndFling")
|
69
77
|
const velocityVector = this.tracker.getVelocity(this.keyPointer);
|
70
78
|
|
71
79
|
const getAlignment = (
|
@@ -154,7 +162,7 @@ export class FlingGestureHandler extends GestureHandler {
|
|
154
162
|
}
|
155
163
|
|
156
164
|
private pointerMoveAction(event: IncomingEvent): void {
|
157
|
-
this.logger.
|
165
|
+
this.logger.cloneAndJoinPrefix("pointerMoveAction").info(JSON.stringify(event))
|
158
166
|
this.tracker.track(event);
|
159
167
|
|
160
168
|
if (this.currentState !== State.BEGAN) {
|
@@ -187,7 +195,7 @@ export class FlingGestureHandler extends GestureHandler {
|
|
187
195
|
}
|
188
196
|
|
189
197
|
private onUp(event: IncomingEvent): void {
|
190
|
-
const logger = this.logger.
|
198
|
+
const logger = this.logger.cloneAndJoinPrefix("onUp")
|
191
199
|
logger.info("start")
|
192
200
|
if (this.currentState === State.BEGAN) {
|
193
201
|
this.endFling();
|