@@ -10,11 +10,7 @@ import {
10
10
} from '../types' ;
11
11
import { DetectorContext } from './useDetectorContext' ;
12
12
import { Reanimated } from '../../handlers/gestures/reanimatedWrapper' ;
13
- import {
14
- configureRelations ,
15
- getHandlerTag ,
16
- invokeDetectorEvent ,
17
- } from './utils' ;
13
+ import { configureRelations } from './utils' ;
18
14
import { isComposedGesture } from '../hooks/utils/relationUtils' ;
19
15
20
16
export interface NativeDetectorProps {
@@ -77,19 +73,53 @@ export function NativeDetector({ gesture, children }: NativeDetectorProps) {
77
73
78
74
const handleGestureEvent = ( key : keyof GestureEvents < unknown > ) => {
79
75
return ( e : GestureHandlerEvent < unknown > ) => {
80
- const handlerTag = getHandlerTag ( e ) ;
81
-
82
- const method = ! logicMethods . current . has ( handlerTag )
83
- ? gesture . gestureEvents [ key ]
84
- : logicMethods . current . get ( handlerTag ) ?. current ?. [ key ] ;
85
-
86
- invokeDetectorEvent (
87
- method as ( e : GestureHandlerEvent < unknown > ) => void ,
88
- e
89
- ) ;
76
+ if ( gesture . gestureEvents [ key ] ) {
77
+ gesture . gestureEvents [ key ] ( e ) ;
78
+ }
79
+
80
+ logicMethods . current . forEach ( ( ref ) => {
81
+ const method = ref . current ?. [ key ] ;
82
+ if ( method ) {
83
+ method ( e ) ;
84
+ }
85
+ } ) ;
90
86
} ;
91
87
} ;
92
88
89
+ const getHandlers = useCallback (
90
+ ( key : keyof GestureEvents < unknown > ) => {
91
+ const handlers : ( ( e : GestureHandlerEvent < unknown > ) => void ) [ ] = [ ] ;
92
+
93
+ if ( gesture . gestureEvents [ key ] ) {
94
+ handlers . push (
95
+ gesture . gestureEvents [ key ] as (
96
+ e : GestureHandlerEvent < unknown >
97
+ ) => void
98
+ ) ;
99
+ }
100
+
101
+ logicMethods . current . forEach ( ( ref ) => {
102
+ const handler = ref . current ?. [ key ] ;
103
+ if ( handler ) {
104
+ handlers . push ( handler as ( e : GestureHandlerEvent < unknown > ) => void ) ;
105
+ }
106
+ } ) ;
107
+
108
+ return handlers ;
109
+ } ,
110
+ [ logicChildren , gesture . gestureEvents ]
111
+ ) ;
112
+
113
+ const reanimatedEventHandler = Reanimated ?. useComposedEventHandler (
114
+ getHandlers ( 'onReanimatedUpdateEvent' )
115
+ ) ;
116
+ const reanimedStateChangeHandler = Reanimated ?. useComposedEventHandler (
117
+ getHandlers ( 'onReanimatedStateChange' )
118
+ ) ;
119
+ const reanimatedTouchEventHandler = Reanimated ?. useComposedEventHandler (
120
+ getHandlers ( 'onReanimatedTouchEvent' )
121
+ ) ;
122
+
93
123
return (
94
124
< DetectorContext . Provider value = { { register, unregister } } >
95
125
< NativeDetectorComponent
@@ -108,17 +138,11 @@ export function NativeDetector({ gesture, children }: NativeDetectorProps) {
108
138
'onGestureHandlerTouchEvent'
109
139
) }
110
140
// @ts -ignore This is a type mismatch between RNGH types and RN Codegen types
111
- onGestureHandlerReanimatedStateChange = { handleGestureEvent (
112
- 'onReanimatedStateChange'
113
- ) }
141
+ onGestureHandlerReanimatedStateChange = { reanimatedEventHandler }
114
142
// @ts -ignore This is a type mismatch between RNGH types and RN Codegen types
115
- onGestureHandlerReanimatedEvent = { handleGestureEvent (
116
- 'onReanimatedUpdateEvent'
117
- ) }
143
+ onGestureHandlerReanimatedEvent = { reanimedStateChangeHandler }
118
144
// @ts -ignore This is a type mismatch between RNGH types and RN Codegen types
119
- onGestureHandlerReanimatedTouchEvent = { handleGestureEvent (
120
- 'onReanimatedTouchEvent'
121
- ) }
145
+ onGestureHandlerReanimatedTouchEvent = { reanimatedTouchEventHandler }
122
146
moduleId = { globalThis . _RNGH_MODULE_ID }
123
147
handlerTags = { isComposedGesture ( gesture ) ? gesture . tags : [ gesture . tag ] }
124
148
style = { styles . detector }
0 commit comments