@@ -25,7 +25,7 @@ const HostGestureDetector = (props: GestureHandlerDetectorProps) => {
25
25
const attachedHandlerTags = useRef < Set < number > > ( new Set < number > ( ) ) ;
26
26
const attachedNativeHandlerTags = useRef < Set < number > > ( new Set < number > ( ) ) ;
27
27
28
- const logicChildren = useRef < Map < LogicDetectorProps , LogicChild > > ( new Map ( ) ) ;
28
+ const logicChildren = useRef < Map < number , LogicChild > > ( new Map ( ) ) ;
29
29
30
30
const detachHandlers = (
31
31
oldHandlerTags : Set < number > ,
@@ -103,18 +103,29 @@ const HostGestureDetector = (props: GestureHandlerDetectorProps) => {
103
103
attachedHandlerTags . current ,
104
104
attachedNativeHandlerTags . current
105
105
) ;
106
+ } , [ handlerTags , children ] ) ;
107
+
108
+ useEffect ( ( ) => {
109
+ const shouldKeepLogicChild : Map < number , boolean > = new Map ( ) ;
106
110
107
- props . logicChildren ?. forEach ( ( child ) => {
108
- if ( ! logicChildren . current . has ( child ) ) {
109
- logicChildren . current . set ( child , {
111
+ for ( const key of logicChildren . current . keys ( ) ) {
112
+ shouldKeepLogicChild . set ( key , false ) ;
113
+ }
114
+
115
+ props . logicChildren ?. forEach ( ( child , key ) => {
116
+ if ( ! logicChildren . current . has ( child . viewTag ) ) {
117
+ logicChildren . current . set ( child . viewTag , {
110
118
attachedHandlerTags : new Set ( ) ,
111
119
attachedNativeHandlerTags : new Set ( ) ,
112
120
} ) ;
113
121
}
114
- const attachedHandlerTags =
115
- logicChildren . current . get ( child ) ?. attachedHandlerTags ;
116
- const attachedNativeHandlerTags =
117
- logicChildren . current . get ( child ) ?. attachedNativeHandlerTags ;
122
+ shouldKeepLogicChild . set ( key . viewTag , true ) ;
123
+ const attachedHandlerTags = logicChildren . current . get (
124
+ child . viewTag
125
+ ) ?. attachedHandlerTags ;
126
+ const attachedNativeHandlerTags = logicChildren . current . get (
127
+ child . viewTag
128
+ ) ?. attachedNativeHandlerTags ;
118
129
if ( attachedHandlerTags && attachedNativeHandlerTags ) {
119
130
attachHandlers (
120
131
child . viewRef ,
@@ -126,27 +137,37 @@ const HostGestureDetector = (props: GestureHandlerDetectorProps) => {
126
137
) ;
127
138
}
128
139
} ) ;
129
- } , [ handlerTags , children ] ) ;
130
140
131
- useEffect ( ( ) => {
132
- return ( ) => {
133
- detachHandlers (
134
- attachedHandlerTags . current ,
135
- attachedHandlerTags . current ,
136
- attachedNativeHandlerTags . current
137
- ) ;
138
- props . logicChildren ?. forEach ( ( child ) => {
141
+ shouldKeepLogicChild . forEach ( ( value , key ) => {
142
+ if ( value ) {
139
143
const attachedHandlerTags =
140
- logicChildren . current . get ( child ) ?. attachedHandlerTags ;
144
+ logicChildren . current . get ( key ) ?. attachedHandlerTags ;
141
145
const attachedNativeHandlerTags =
142
- logicChildren . current . get ( child ) ?. attachedNativeHandlerTags ;
146
+ logicChildren . current . get ( key ) ?. attachedNativeHandlerTags ;
143
147
if ( attachedHandlerTags && attachedNativeHandlerTags ) {
144
148
detachHandlers (
145
149
attachedHandlerTags ,
146
150
attachedHandlerTags ,
147
151
attachedNativeHandlerTags
148
152
) ;
149
153
}
154
+ }
155
+ } ) ;
156
+ } , [ props . logicChildren ] ) ;
157
+
158
+ useEffect ( ( ) => {
159
+ return ( ) => {
160
+ detachHandlers (
161
+ attachedHandlerTags . current ,
162
+ attachedHandlerTags . current ,
163
+ attachedNativeHandlerTags . current
164
+ ) ;
165
+ logicChildren ?. current . forEach ( ( child ) => {
166
+ detachHandlers (
167
+ child . attachedHandlerTags ,
168
+ child . attachedHandlerTags ,
169
+ child . attachedNativeHandlerTags
170
+ ) ;
150
171
} ) ;
151
172
} ;
152
173
} , [ ] ) ;
0 commit comments