@@ -19,11 +19,6 @@ export interface LogicDetectorProps {
19
19
viewRef : RefObject < Element | null > ;
20
20
}
21
21
22
- interface LogicChild {
23
- attachedHandlerTags : Set < number > ;
24
- attachedNativeHandlerTags : Set < number > ;
25
- }
26
-
27
22
const HostGestureDetector = ( props : GestureHandlerDetectorProps ) => {
28
23
const { handlerTags, children } = props ;
29
24
@@ -32,16 +27,15 @@ const HostGestureDetector = (props: GestureHandlerDetectorProps) => {
32
27
const attachedHandlerTags = useRef < Set < number > > ( new Set < number > ( ) ) ;
33
28
const attachedNativeHandlerTags = useRef < Set < number > > ( new Set < number > ( ) ) ;
34
29
35
- const logicChildren = useRef < Map < number , LogicChild > > ( new Map ( ) ) ;
30
+ const logicChildren = useRef < Map < number , Set < number > > > ( new Map ( ) ) ;
36
31
37
32
const detachHandlers = (
38
33
oldHandlerTags : Set < number > ,
39
- attachedHandlerTags : Set < number > ,
40
- attachedNativeHandlerTags : Set < number >
34
+ attachedHandlerTags : Set < number >
41
35
) => {
42
36
oldHandlerTags . forEach ( ( tag ) => {
43
37
RNGestureHandlerModule . detachGestureHandler ( tag ) ;
44
- attachedNativeHandlerTags . delete ( tag ) ;
38
+ attachedNativeHandlerTags . current . delete ( tag ) ;
45
39
attachedHandlerTags . delete ( tag ) ;
46
40
} ) ;
47
41
} ;
@@ -51,16 +45,11 @@ const HostGestureDetector = (props: GestureHandlerDetectorProps) => {
51
45
propsRef : RefObject < PropsRef > ,
52
46
currentHandlerTags : Set < number > ,
53
47
attachedHandlerTags : Set < number > ,
54
- attachedNativeHandlerTags : Set < number > ,
55
48
isLogic : boolean
56
49
) => {
57
50
const oldHandlerTags = attachedHandlerTags . difference ( currentHandlerTags ) ;
58
51
const newHandlerTags = currentHandlerTags . difference ( attachedHandlerTags ) ;
59
- detachHandlers (
60
- oldHandlerTags ,
61
- attachedHandlerTags ,
62
- attachedNativeHandlerTags
63
- ) ;
52
+ detachHandlers ( oldHandlerTags , attachedHandlerTags ) ;
64
53
65
54
newHandlerTags . forEach ( ( tag ) => {
66
55
if (
@@ -74,12 +63,12 @@ const HostGestureDetector = (props: GestureHandlerDetectorProps) => {
74
63
ActionType . NATIVE_DETECTOR ,
75
64
propsRef
76
65
) ;
77
- attachedNativeHandlerTags . add ( tag ) ;
66
+ attachedNativeHandlerTags . current . add ( tag ) ;
78
67
} else {
79
68
RNGestureHandlerModule . attachGestureHandler (
80
69
tag ,
81
70
viewRef . current ,
82
- isLogic ? ActionType . LogicDetector : ActionType . NATIVE_DETECTOR ,
71
+ isLogic ? ActionType . LOGIC_DETECTOR : ActionType . NATIVE_DETECTOR ,
83
72
propsRef
84
73
) ;
85
74
}
@@ -90,8 +79,7 @@ const HostGestureDetector = (props: GestureHandlerDetectorProps) => {
90
79
useEffect ( ( ) => {
91
80
detachHandlers (
92
81
attachedNativeHandlerTags . current ,
93
- attachedHandlerTags . current ,
94
- attachedNativeHandlerTags . current
82
+ attachedHandlerTags . current
95
83
) ;
96
84
} , [ children ] ) ;
97
85
@@ -107,74 +95,47 @@ const HostGestureDetector = (props: GestureHandlerDetectorProps) => {
107
95
propsRef ,
108
96
new Set ( handlerTags ) ,
109
97
attachedHandlerTags . current ,
110
- attachedNativeHandlerTags . current ,
111
98
false
112
99
) ;
113
100
} , [ handlerTags , children ] ) ;
114
101
115
102
useEffect ( ( ) => {
116
- const shouldKeepLogicChild : Map < number , boolean > = new Map ( ) ;
103
+ const logicChildrenToDelete : Set < number > = new Set ( ) ;
117
104
118
105
for ( const key of logicChildren . current . keys ( ) ) {
119
- shouldKeepLogicChild . set ( key , false ) ;
106
+ logicChildrenToDelete . add ( key ) ;
120
107
}
121
108
122
- props . logicChildren ?. forEach ( ( child , key ) => {
109
+ props . logicChildren ?. forEach ( ( child ) => {
123
110
if ( ! logicChildren . current . has ( child . viewTag ) ) {
124
- logicChildren . current . set ( child . viewTag , {
125
- attachedHandlerTags : new Set ( ) ,
126
- attachedNativeHandlerTags : new Set ( ) ,
127
- } ) ;
128
- }
129
- shouldKeepLogicChild . set ( key . viewTag , true ) ;
130
- const attachedHandlerTags = logicChildren . current . get (
131
- child . viewTag
132
- ) ?. attachedHandlerTags ;
133
- const attachedNativeHandlerTags = logicChildren . current . get (
134
- child . viewTag
135
- ) ?. attachedNativeHandlerTags ;
136
- if ( attachedHandlerTags && attachedNativeHandlerTags ) {
137
- attachHandlers (
138
- child . viewRef ,
139
- propsRef ,
140
- new Set ( child . handlerTags ) ,
141
- attachedHandlerTags ,
142
- attachedNativeHandlerTags ,
143
- true
144
- ) ;
111
+ logicChildren . current . set ( child . viewTag , new Set ( ) ) ;
145
112
}
113
+ logicChildrenToDelete . delete ( child . viewTag ) ;
114
+ attachHandlers (
115
+ child . viewRef ,
116
+ propsRef ,
117
+ new Set ( child . handlerTags ) ,
118
+ logicChildren . current . get ( child . viewTag ) ! ,
119
+ true
120
+ ) ;
146
121
} ) ;
147
122
148
- shouldKeepLogicChild . forEach ( ( value , key ) => {
149
- if ( value ) {
150
- const attachedHandlerTags =
151
- logicChildren . current . get ( key ) ?. attachedHandlerTags ;
152
- const attachedNativeHandlerTags =
153
- logicChildren . current . get ( key ) ?. attachedNativeHandlerTags ;
154
- if ( attachedHandlerTags && attachedNativeHandlerTags ) {
155
- detachHandlers (
156
- attachedHandlerTags ,
157
- attachedHandlerTags ,
158
- attachedNativeHandlerTags
159
- ) ;
160
- }
123
+ logicChildrenToDelete . forEach ( ( childTag ) => {
124
+ if ( attachedHandlerTags && attachedNativeHandlerTags ) {
125
+ detachHandlers (
126
+ logicChildren . current . get ( childTag ) ! ,
127
+ logicChildren . current . get ( childTag ) !
128
+ ) ;
161
129
}
130
+ logicChildren . current . delete ( childTag ) ;
162
131
} ) ;
163
132
} , [ props . logicChildren ] ) ;
164
133
165
134
useEffect ( ( ) => {
166
135
return ( ) => {
167
- detachHandlers (
168
- attachedHandlerTags . current ,
169
- attachedHandlerTags . current ,
170
- attachedNativeHandlerTags . current
171
- ) ;
136
+ detachHandlers ( attachedHandlerTags . current , attachedHandlerTags . current ) ;
172
137
logicChildren ?. current . forEach ( ( child ) => {
173
- detachHandlers (
174
- child . attachedHandlerTags ,
175
- child . attachedHandlerTags ,
176
- child . attachedNativeHandlerTags
177
- ) ;
138
+ detachHandlers ( child , child ) ;
178
139
} ) ;
179
140
} ;
180
141
} , [ ] ) ;
0 commit comments