13
13
14
14
@interface RNGestureHandlerDetector () <RCTRNGestureHandlerDetectorViewProtocol>
15
15
16
- @property (nonatomic , nonnull ) NSMutableSet *nativeHandlersToAttach ;
16
+ @property (nonatomic , nonnull ) NSMutableSet *attachedNativeHandlers ;
17
17
@property (nonatomic , nonnull ) NSMutableSet *attachedHandlers;
18
18
19
19
@end
@@ -41,7 +41,7 @@ - (instancetype)initWithFrame:(CGRect)frame
41
41
static const auto defaultProps = std::make_shared<const RNGestureHandlerDetectorProps>();
42
42
_props = defaultProps;
43
43
_moduleId = -1 ;
44
- _nativeHandlersToAttach = [NSMutableSet set ];
44
+ _attachedNativeHandlers = [NSMutableSet set ];
45
45
_attachedHandlers = [NSMutableSet set ];
46
46
}
47
47
@@ -94,11 +94,13 @@ - (BOOL)shouldAttachGestureToSubview:(NSNumber *)handlerTag
94
94
return [[[handlerManager registry ] handlerWithTag: handlerTag] wantsToAttachDirectlyToView ];
95
95
}
96
96
97
- - (void )addSubview : (UIView *)view
97
+ - (void )didAddSubview : (UIView *)view
98
98
{
99
- [super addSubview: view];
99
+ for (const id handlerTag : _attachedNativeHandlers) {
100
+ [self tryAttachHandlerToChildView: handlerTag];
101
+ }
100
102
101
- [self tryAttachHandlerToChildView ];
103
+ [super didAddSubview: view ];
102
104
}
103
105
104
106
- (void )willRemoveSubview : (UIView *)subview
@@ -152,7 +154,8 @@ - (void)updateProps:(const Props::Shared &)propsBase oldProps:(const Props::Shar
152
154
153
155
if (handlerChange.second == RNGestureHandlerMutationAttach) {
154
156
if ([self shouldAttachGestureToSubview: handlerTag]) {
155
- [_nativeHandlersToAttach addObject: handlerTag];
157
+ [_attachedNativeHandlers addObject: handlerTag];
158
+ [self tryAttachHandlerToChildView: handlerTag];
156
159
} else {
157
160
[handlerManager.registry attachHandlerWithTag: handlerTag
158
161
toView: self
@@ -163,29 +166,23 @@ - (void)updateProps:(const Props::Shared &)propsBase oldProps:(const Props::Shar
163
166
} else if (handlerChange.second == RNGestureHandlerMutationDetach) {
164
167
[handlerManager.registry detachHandlerWithTag: handlerTag];
165
168
[_attachedHandlers removeObject: handlerTag];
169
+ [_attachedNativeHandlers removeObject: handlerTag];
166
170
}
167
-
168
- [self tryAttachHandlerToChildView ];
169
171
}
170
172
171
173
[super updateProps: propsBase oldProps: oldPropsBase];
172
174
// Override to force hittesting to work outside bounds
173
175
self.clipsToBounds = NO ;
174
176
}
175
177
176
- - (void )tryAttachHandlerToChildView
178
+ - (void )tryAttachHandlerToChildView : ( NSNumber *) handlerTag
177
179
{
178
180
RNGestureHandlerManager *handlerManager = [RNGestureHandlerModule handlerManagerForModuleId: _moduleId];
181
+ [handlerManager.registry attachHandlerWithTag: handlerTag
182
+ toView: self .subviews[0 ]
183
+ withActionType: RNGestureHandlerActionTypeNativeDetector];
179
184
180
- for (NSNumber *handlerTag in _nativeHandlersToAttach) {
181
- [handlerManager.registry attachHandlerWithTag: handlerTag
182
- toView: self .subviews[0 ]
183
- withActionType: RNGestureHandlerActionTypeNativeDetector];
184
-
185
- [_attachedHandlers addObject: handlerTag];
186
- }
187
-
188
- [_nativeHandlersToAttach removeAllObjects ];
185
+ [_attachedHandlers addObject: handlerTag];
189
186
}
190
187
191
188
- (void )detachNativeGestureHandlers
0 commit comments