@@ -25,7 +25,7 @@ const HostGestureDetector = (props: GestureHandlerDetectorProps) => {
2525 const attachedHandlerTags = useRef < Set < number > > ( new Set < number > ( ) ) ;
2626 const attachedNativeHandlerTags = useRef < Set < number > > ( new Set < number > ( ) ) ;
2727
28- const logicChildren = useRef < Map < LogicDetectorProps , LogicChild > > ( new Map ( ) ) ;
28+ const logicChildren = useRef < Map < number , LogicChild > > ( new Map ( ) ) ;
2929
3030 const detachHandlers = (
3131 oldHandlerTags : Set < number > ,
@@ -103,18 +103,29 @@ const HostGestureDetector = (props: GestureHandlerDetectorProps) => {
103103 attachedHandlerTags . current ,
104104 attachedNativeHandlerTags . current
105105 ) ;
106+ } , [ handlerTags , children ] ) ;
107+
108+ useEffect ( ( ) => {
109+ const shouldKeepLogicChild : Map < number , boolean > = new Map ( ) ;
106110
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 , {
110118 attachedHandlerTags : new Set ( ) ,
111119 attachedNativeHandlerTags : new Set ( ) ,
112120 } ) ;
113121 }
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 ;
118129 if ( attachedHandlerTags && attachedNativeHandlerTags ) {
119130 attachHandlers (
120131 child . viewRef ,
@@ -126,27 +137,37 @@ const HostGestureDetector = (props: GestureHandlerDetectorProps) => {
126137 ) ;
127138 }
128139 } ) ;
129- } , [ handlerTags , children ] ) ;
130140
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 ) {
139143 const attachedHandlerTags =
140- logicChildren . current . get ( child ) ?. attachedHandlerTags ;
144+ logicChildren . current . get ( key ) ?. attachedHandlerTags ;
141145 const attachedNativeHandlerTags =
142- logicChildren . current . get ( child ) ?. attachedNativeHandlerTags ;
146+ logicChildren . current . get ( key ) ?. attachedNativeHandlerTags ;
143147 if ( attachedHandlerTags && attachedNativeHandlerTags ) {
144148 detachHandlers (
145149 attachedHandlerTags ,
146150 attachedHandlerTags ,
147151 attachedNativeHandlerTags
148152 ) ;
149153 }
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+ ) ;
150171 } ) ;
151172 } ;
152173 } , [ ] ) ;
0 commit comments