@@ -40,7 +40,8 @@ export default abstract class GestureHandler implements IGestureHandler {
40
40
private viewRef : number | null = null ;
41
41
private propsRef : React . RefObject < PropsRef > | null = null ;
42
42
private actionType : ActionType | null = null ;
43
- private dispatchesAnimatedEvents : boolean = false ;
43
+ private forAnimated : boolean = false ;
44
+ private forReanimated : boolean = false ;
44
45
private _handlerTag ! : number ;
45
46
46
47
private hitSlop ?: HitSlop = undefined ;
@@ -97,7 +98,8 @@ export default abstract class GestureHandler implements IGestureHandler {
97
98
this . viewRef = null ;
98
99
this . actionType = null ;
99
100
this . state = State . UNDETERMINED ;
100
- this . dispatchesAnimatedEvents = false ;
101
+ this . forAnimated = false ;
102
+ this . forReanimated = false ;
101
103
102
104
this . delegate . detach ( ) ;
103
105
}
@@ -381,21 +383,28 @@ export default abstract class GestureHandler implements IGestureHandler {
381
383
return ;
382
384
}
383
385
this . ensurePropsRef ( ) ;
384
- const { onGestureHandlerEvent, onGestureHandlerTouchEvent } : PropsRef =
385
- this . propsRef ! . current ;
386
+ const {
387
+ onGestureHandlerEvent,
388
+ onGestureHandlerTouchEvent,
389
+ onGestureHandlerReanimatedTouchEvent,
390
+ } : PropsRef = this . propsRef ! . current ;
386
391
387
392
const touchEvent : ResultEvent < GestureTouchEvent > | undefined =
388
393
this . transformTouchEvent ( event ) ;
389
394
390
- if ( touchEvent ) {
391
- if (
392
- onGestureHandlerTouchEvent &&
393
- usesNativeOrLogicDetector ( this . actionType )
394
- ) {
395
- invokeNullableMethod ( onGestureHandlerTouchEvent , touchEvent ) ;
396
- } else {
397
- invokeNullableMethod ( onGestureHandlerEvent , touchEvent ) ;
398
- }
395
+ if ( ! touchEvent ) {
396
+ return ;
397
+ }
398
+
399
+ if ( usesNativeOrLogicDetector ( this . actionType ) ) {
400
+ invokeNullableMethod (
401
+ this . forReanimated
402
+ ? onGestureHandlerReanimatedTouchEvent
403
+ : onGestureHandlerTouchEvent ,
404
+ touchEvent
405
+ ) ;
406
+ } else {
407
+ invokeNullableMethod ( onGestureHandlerEvent , touchEvent ) ;
399
408
}
400
409
}
401
410
@@ -408,6 +417,8 @@ export default abstract class GestureHandler implements IGestureHandler {
408
417
onGestureHandlerEvent,
409
418
onGestureHandlerStateChange,
410
419
onGestureHandlerAnimatedEvent,
420
+ onGestureHandlerReanimatedEvent,
421
+ onGestureHandlerReanimatedStateChange,
411
422
} : PropsRef = this . propsRef ! . current ;
412
423
413
424
const resultEvent : ResultEvent = ! usesNativeOrLogicDetector ( this . actionType )
@@ -422,18 +433,27 @@ export default abstract class GestureHandler implements IGestureHandler {
422
433
// However, this may cause trouble in the future (but for now we don't know that)
423
434
if ( this . lastSentState !== newState ) {
424
435
this . lastSentState = newState ;
425
- invokeNullableMethod ( onGestureHandlerStateChange , resultEvent ) ;
436
+ invokeNullableMethod (
437
+ this . forReanimated
438
+ ? onGestureHandlerReanimatedStateChange
439
+ : onGestureHandlerStateChange ,
440
+ resultEvent
441
+ ) ;
426
442
}
427
443
if ( this . state === State . ACTIVE ) {
428
444
if ( ! usesNativeOrLogicDetector ( this . actionType ) ) {
429
445
( resultEvent . nativeEvent as GestureHandlerNativeEvent ) . oldState =
430
446
undefined ;
431
447
}
432
- if ( onGestureHandlerAnimatedEvent && this . dispatchesAnimatedEvents ) {
433
- invokeNullableMethod ( onGestureHandlerAnimatedEvent , resultEvent ) ;
434
- }
435
448
436
- invokeNullableMethod ( onGestureHandlerEvent , resultEvent ) ;
449
+ invokeNullableMethod (
450
+ this . forReanimated
451
+ ? onGestureHandlerReanimatedEvent
452
+ : this . forAnimated
453
+ ? onGestureHandlerAnimatedEvent
454
+ : onGestureHandlerEvent ,
455
+ resultEvent
456
+ ) ;
437
457
}
438
458
} ;
439
459
@@ -638,9 +658,22 @@ export default abstract class GestureHandler implements IGestureHandler {
638
658
timeStamp : Date . now ( ) ,
639
659
} ;
640
660
641
- const { onGestureHandlerEvent } : PropsRef = this . propsRef ! . current ;
661
+ const {
662
+ onGestureHandlerEvent,
663
+ onGestureHandlerReanimatedTouchEvent,
664
+ onGestureHandlerTouchEvent,
665
+ } : PropsRef = this . propsRef ! . current ;
642
666
643
- invokeNullableMethod ( onGestureHandlerEvent , cancelEvent ) ;
667
+ if ( this . actionType === ActionType . NATIVE_DETECTOR ) {
668
+ invokeNullableMethod (
669
+ this . forReanimated
670
+ ? onGestureHandlerReanimatedTouchEvent
671
+ : onGestureHandlerTouchEvent ,
672
+ cancelEvent
673
+ ) ;
674
+ } else {
675
+ invokeNullableMethod ( onGestureHandlerEvent , cancelEvent ) ;
676
+ }
644
677
}
645
678
646
679
private ensurePropsRef ( ) : void {
@@ -692,7 +725,11 @@ export default abstract class GestureHandler implements IGestureHandler {
692
725
}
693
726
694
727
if ( config . dispatchesAnimatedEvents !== undefined ) {
695
- this . dispatchesAnimatedEvents = config . dispatchesAnimatedEvents ;
728
+ this . forAnimated = config . dispatchesAnimatedEvents ;
729
+ }
730
+
731
+ if ( config . shouldUseReanimated !== undefined ) {
732
+ this . forReanimated = config . shouldUseReanimated ;
696
733
}
697
734
698
735
if ( config . manualActivation !== undefined ) {
@@ -875,7 +912,8 @@ export default abstract class GestureHandler implements IGestureHandler {
875
912
this . mouseButton = undefined ;
876
913
this . hitSlop = undefined ;
877
914
this . needsPointerData = false ;
878
- this . dispatchesAnimatedEvents = false ;
915
+ this . forAnimated = false ;
916
+ this . forReanimated = false ;
879
917
this . enableContextMenu = false ;
880
918
this . _activeCursor = undefined ;
881
919
this . _touchAction = undefined ;
@@ -992,7 +1030,9 @@ function invokeNullableMethod(
992
1030
method :
993
1031
| ( ( event : ResultEvent ) => void )
994
1032
| { __getHandler : ( ) => ( event : ResultEvent ) => void }
995
- | { __nodeConfig : { argMapping : unknown [ ] } } ,
1033
+ | { __nodeConfig : { argMapping : unknown [ ] } }
1034
+ | null
1035
+ | undefined ,
996
1036
event : ResultEvent
997
1037
) : void {
998
1038
if ( ! method ) {
0 commit comments