@@ -19,11 +19,6 @@ export interface LogicDetectorProps {
1919 viewRef : RefObject < Element | null > ;
2020}
2121
22- interface LogicChild {
23- attachedHandlerTags : Set < number > ;
24- attachedNativeHandlerTags : Set < number > ;
25- }
26-
2722const HostGestureDetector = ( props : GestureHandlerDetectorProps ) => {
2823 const { handlerTags, children } = props ;
2924
@@ -32,16 +27,15 @@ const HostGestureDetector = (props: GestureHandlerDetectorProps) => {
3227 const attachedHandlerTags = useRef < Set < number > > ( new Set < number > ( ) ) ;
3328 const attachedNativeHandlerTags = useRef < Set < number > > ( new Set < number > ( ) ) ;
3429
35- const logicChildren = useRef < Map < number , LogicChild > > ( new Map ( ) ) ;
30+ const logicChildren = useRef < Map < number , Set < number > > > ( new Map ( ) ) ;
3631
3732 const detachHandlers = (
3833 oldHandlerTags : Set < number > ,
39- attachedHandlerTags : Set < number > ,
40- attachedNativeHandlerTags : Set < number >
34+ attachedHandlerTags : Set < number >
4135 ) => {
4236 oldHandlerTags . forEach ( ( tag ) => {
4337 RNGestureHandlerModule . detachGestureHandler ( tag ) ;
44- attachedNativeHandlerTags . delete ( tag ) ;
38+ attachedNativeHandlerTags . current . delete ( tag ) ;
4539 attachedHandlerTags . delete ( tag ) ;
4640 } ) ;
4741 } ;
@@ -51,16 +45,11 @@ const HostGestureDetector = (props: GestureHandlerDetectorProps) => {
5145 propsRef : RefObject < PropsRef > ,
5246 currentHandlerTags : Set < number > ,
5347 attachedHandlerTags : Set < number > ,
54- attachedNativeHandlerTags : Set < number > ,
5548 isLogic : boolean
5649 ) => {
5750 const oldHandlerTags = attachedHandlerTags . difference ( currentHandlerTags ) ;
5851 const newHandlerTags = currentHandlerTags . difference ( attachedHandlerTags ) ;
59- detachHandlers (
60- oldHandlerTags ,
61- attachedHandlerTags ,
62- attachedNativeHandlerTags
63- ) ;
52+ detachHandlers ( oldHandlerTags , attachedHandlerTags ) ;
6453
6554 newHandlerTags . forEach ( ( tag ) => {
6655 if (
@@ -74,12 +63,12 @@ const HostGestureDetector = (props: GestureHandlerDetectorProps) => {
7463 ActionType . NATIVE_DETECTOR ,
7564 propsRef
7665 ) ;
77- attachedNativeHandlerTags . add ( tag ) ;
66+ attachedNativeHandlerTags . current . add ( tag ) ;
7867 } else {
7968 RNGestureHandlerModule . attachGestureHandler (
8069 tag ,
8170 viewRef . current ,
82- isLogic ? ActionType . LogicDetector : ActionType . NATIVE_DETECTOR ,
71+ isLogic ? ActionType . LOGIC_DETECTOR : ActionType . NATIVE_DETECTOR ,
8372 propsRef
8473 ) ;
8574 }
@@ -90,8 +79,7 @@ const HostGestureDetector = (props: GestureHandlerDetectorProps) => {
9079 useEffect ( ( ) => {
9180 detachHandlers (
9281 attachedNativeHandlerTags . current ,
93- attachedHandlerTags . current ,
94- attachedNativeHandlerTags . current
82+ attachedHandlerTags . current
9583 ) ;
9684 } , [ children ] ) ;
9785
@@ -107,74 +95,47 @@ const HostGestureDetector = (props: GestureHandlerDetectorProps) => {
10795 propsRef ,
10896 new Set ( handlerTags ) ,
10997 attachedHandlerTags . current ,
110- attachedNativeHandlerTags . current ,
11198 false
11299 ) ;
113100 } , [ handlerTags , children ] ) ;
114101
115102 useEffect ( ( ) => {
116- const shouldKeepLogicChild : Map < number , boolean > = new Map ( ) ;
103+ const logicChildrenToDelete : Set < number > = new Set ( ) ;
117104
118105 for ( const key of logicChildren . current . keys ( ) ) {
119- shouldKeepLogicChild . set ( key , false ) ;
106+ logicChildrenToDelete . add ( key ) ;
120107 }
121108
122- props . logicChildren ?. forEach ( ( child , key ) => {
109+ props . logicChildren ?. forEach ( ( child ) => {
123110 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 ( ) ) ;
145112 }
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+ ) ;
146121 } ) ;
147122
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+ ) ;
161129 }
130+ logicChildren . current . delete ( childTag ) ;
162131 } ) ;
163132 } , [ props . logicChildren ] ) ;
164133
165134 useEffect ( ( ) => {
166135 return ( ) => {
167- detachHandlers (
168- attachedHandlerTags . current ,
169- attachedHandlerTags . current ,
170- attachedNativeHandlerTags . current
171- ) ;
136+ detachHandlers ( attachedHandlerTags . current , attachedHandlerTags . current ) ;
172137 logicChildren ?. current . forEach ( ( child ) => {
173- detachHandlers (
174- child . attachedHandlerTags ,
175- child . attachedHandlerTags ,
176- child . attachedNativeHandlerTags
177- ) ;
138+ detachHandlers ( child , child ) ;
178139 } ) ;
179140 } ;
180141 } , [ ] ) ;
0 commit comments