@@ -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 ;
@@ -96,7 +97,8 @@ export default abstract class GestureHandler implements IGestureHandler {
96
97
this . viewRef = null ;
97
98
this . actionType = null ;
98
99
this . state = State . UNDETERMINED ;
99
- this . dispatchesAnimatedEvents = false ;
100
+ this . forAnimated = false ;
101
+ this . forReanimated = false ;
100
102
101
103
this . delegate . detach ( ) ;
102
104
}
@@ -380,21 +382,28 @@ export default abstract class GestureHandler implements IGestureHandler {
380
382
return ;
381
383
}
382
384
this . ensurePropsRef ( ) ;
383
- const { onGestureHandlerEvent, onGestureHandlerTouchEvent } : PropsRef =
384
- this . propsRef ! . current ;
385
+ const {
386
+ onGestureHandlerEvent,
387
+ onGestureHandlerTouchEvent,
388
+ onGestureHandlerReanimatedTouchEvent,
389
+ } : PropsRef = this . propsRef ! . current ;
385
390
386
391
const touchEvent : ResultEvent < GestureTouchEvent > | undefined =
387
392
this . transformTouchEvent ( event ) ;
388
393
389
- if ( touchEvent ) {
390
- if (
391
- onGestureHandlerTouchEvent &&
392
- this . actionType === ActionType . NATIVE_DETECTOR
393
- ) {
394
- invokeNullableMethod ( onGestureHandlerTouchEvent , touchEvent ) ;
395
- } else {
396
- invokeNullableMethod ( onGestureHandlerEvent , touchEvent ) ;
397
- }
394
+ if ( ! touchEvent ) {
395
+ return ;
396
+ }
397
+
398
+ if ( this . actionType === ActionType . NATIVE_DETECTOR ) {
399
+ invokeNullableMethod (
400
+ this . forReanimated
401
+ ? onGestureHandlerReanimatedTouchEvent
402
+ : onGestureHandlerTouchEvent ,
403
+ touchEvent
404
+ ) ;
405
+ } else {
406
+ invokeNullableMethod ( onGestureHandlerEvent , touchEvent ) ;
398
407
}
399
408
}
400
409
@@ -407,6 +416,8 @@ export default abstract class GestureHandler implements IGestureHandler {
407
416
onGestureHandlerEvent,
408
417
onGestureHandlerStateChange,
409
418
onGestureHandlerAnimatedEvent,
419
+ onGestureHandlerReanimatedEvent,
420
+ onGestureHandlerReanimatedStateChange,
410
421
} : PropsRef = this . propsRef ! . current ;
411
422
const resultEvent : ResultEvent =
412
423
this . actionType !== ActionType . NATIVE_DETECTOR
@@ -422,17 +433,27 @@ export default abstract class GestureHandler implements IGestureHandler {
422
433
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 ( this . actionType !== ActionType . NATIVE_DETECTOR ) {
429
445
( resultEvent . nativeEvent as GestureHandlerNativeEvent ) . oldState =
430
446
undefined ;
431
447
}
432
- if ( onGestureHandlerAnimatedEvent && this . dispatchesAnimatedEvents ) {
433
- invokeNullableMethod ( onGestureHandlerAnimatedEvent , resultEvent ) ;
434
- }
435
- invokeNullableMethod ( onGestureHandlerEvent , resultEvent ) ;
448
+
449
+ invokeNullableMethod (
450
+ this . forReanimated
451
+ ? onGestureHandlerReanimatedEvent
452
+ : this . forAnimated
453
+ ? onGestureHandlerAnimatedEvent
454
+ : onGestureHandlerEvent ,
455
+ resultEvent
456
+ ) ;
436
457
}
437
458
} ;
438
459
@@ -637,9 +658,22 @@ export default abstract class GestureHandler implements IGestureHandler {
637
658
timeStamp : Date . now ( ) ,
638
659
} ;
639
660
640
- const { onGestureHandlerEvent } : PropsRef = this . propsRef ! . current ;
661
+ const {
662
+ onGestureHandlerEvent,
663
+ onGestureHandlerReanimatedTouchEvent,
664
+ onGestureHandlerTouchEvent,
665
+ } : PropsRef = this . propsRef ! . current ;
641
666
642
- 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
+ }
643
677
}
644
678
645
679
private ensurePropsRef ( ) : void {
@@ -691,7 +725,11 @@ export default abstract class GestureHandler implements IGestureHandler {
691
725
}
692
726
693
727
if ( config . dispatchesAnimatedEvents !== undefined ) {
694
- this . dispatchesAnimatedEvents = config . dispatchesAnimatedEvents ;
728
+ this . forAnimated = config . dispatchesAnimatedEvents ;
729
+ }
730
+
731
+ if ( config . shouldUseReanimated !== undefined ) {
732
+ this . forReanimated = config . shouldUseReanimated ;
695
733
}
696
734
697
735
if ( config . manualActivation !== undefined ) {
@@ -874,7 +912,8 @@ export default abstract class GestureHandler implements IGestureHandler {
874
912
this . mouseButton = undefined ;
875
913
this . hitSlop = undefined ;
876
914
this . needsPointerData = false ;
877
- this . dispatchesAnimatedEvents = false ;
915
+ this . forAnimated = false ;
916
+ this . forReanimated = false ;
878
917
this . enableContextMenu = false ;
879
918
this . _activeCursor = undefined ;
880
919
this . _touchAction = undefined ;
@@ -991,7 +1030,9 @@ function invokeNullableMethod(
991
1030
method :
992
1031
| ( ( event : ResultEvent ) => void )
993
1032
| { __getHandler : ( ) => ( event : ResultEvent ) => void }
994
- | { __nodeConfig : { argMapping : unknown [ ] } } ,
1033
+ | { __nodeConfig : { argMapping : unknown [ ] } }
1034
+ | null
1035
+ | undefined ,
995
1036
event : ResultEvent
996
1037
) : void {
997
1038
if ( ! method ) {
0 commit comments