Skip to content

Commit 256074d

Browse files
committed
fix native gesture ios
1 parent 5dcb9a0 commit 256074d

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

packages/react-native-gesture-handler/apple/RNGestureHandlerDetector.mm

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
@interface RNGestureHandlerDetector () <RCTRNGestureHandlerDetectorViewProtocol>
1515

16-
@property (nonatomic, nonnull) NSMutableSet *nativeHandlersToAttach;
16+
@property (nonatomic, nonnull) NSMutableSet *attachedNativeHandlers;
1717
@property (nonatomic, nonnull) NSMutableSet *attachedHandlers;
1818

1919
@end
@@ -41,7 +41,7 @@ - (instancetype)initWithFrame:(CGRect)frame
4141
static const auto defaultProps = std::make_shared<const RNGestureHandlerDetectorProps>();
4242
_props = defaultProps;
4343
_moduleId = -1;
44-
_nativeHandlersToAttach = [NSMutableSet set];
44+
_attachedNativeHandlers = [NSMutableSet set];
4545
_attachedHandlers = [NSMutableSet set];
4646
}
4747

@@ -94,11 +94,13 @@ - (BOOL)shouldAttachGestureToSubview:(NSNumber *)handlerTag
9494
return [[[handlerManager registry] handlerWithTag:handlerTag] wantsToAttachDirectlyToView];
9595
}
9696

97-
- (void)addSubview:(UIView *)view
97+
- (void)didAddSubview:(UIView *)view
9898
{
99-
[super addSubview:view];
99+
for (const id handlerTag : _attachedNativeHandlers) {
100+
[self tryAttachHandlerToChildView:handlerTag];
101+
}
100102

101-
[self tryAttachHandlerToChildView];
103+
[super didAddSubview:view];
102104
}
103105

104106
- (void)willRemoveSubview:(UIView *)subview
@@ -152,7 +154,8 @@ - (void)updateProps:(const Props::Shared &)propsBase oldProps:(const Props::Shar
152154

153155
if (handlerChange.second == RNGestureHandlerMutationAttach) {
154156
if ([self shouldAttachGestureToSubview:handlerTag]) {
155-
[_nativeHandlersToAttach addObject:handlerTag];
157+
[_attachedNativeHandlers addObject:handlerTag];
158+
[self tryAttachHandlerToChildView:handlerTag];
156159
} else {
157160
[handlerManager.registry attachHandlerWithTag:handlerTag
158161
toView:self
@@ -163,29 +166,23 @@ - (void)updateProps:(const Props::Shared &)propsBase oldProps:(const Props::Shar
163166
} else if (handlerChange.second == RNGestureHandlerMutationDetach) {
164167
[handlerManager.registry detachHandlerWithTag:handlerTag];
165168
[_attachedHandlers removeObject:handlerTag];
169+
[_attachedNativeHandlers removeObject:handlerTag];
166170
}
167-
168-
[self tryAttachHandlerToChildView];
169171
}
170172

171173
[super updateProps:propsBase oldProps:oldPropsBase];
172174
// Override to force hittesting to work outside bounds
173175
self.clipsToBounds = NO;
174176
}
175177

176-
- (void)tryAttachHandlerToChildView
178+
- (void)tryAttachHandlerToChildView:(NSNumber *)handlerTag
177179
{
178180
RNGestureHandlerManager *handlerManager = [RNGestureHandlerModule handlerManagerForModuleId:_moduleId];
181+
[handlerManager.registry attachHandlerWithTag:handlerTag
182+
toView:self.subviews[0]
183+
withActionType:RNGestureHandlerActionTypeNativeDetector];
179184

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];
189186
}
190187

191188
- (void)detachNativeGestureHandlers

0 commit comments

Comments
 (0)