Skip to content

Commit 9938977

Browse files
authored
[iOS] Fix hooks API not cancelling JS Responder (#4261)
## Description Fixes #4258 JS-responder cancellation relies on `RNRootViewGestureRecognizer` being installed on the surface view. The legacy path installs it in maybeBindHandler via `registerViewWithGestureRecognizerAttachedIfNeeded`, but the hook-API detector attached handlers straight to the registry and skipped that step, so activation could never cancel the JS responder. This PR adds `attachHandlerForDetectorWithTag:toView:withActionType:withHostDetector:` on `RNGestureHandlerManager` which handles that. ## Test plan Tested on the issue reproducer
1 parent a96cf17 commit 9938977

3 files changed

Lines changed: 20 additions & 6 deletions

File tree

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -254,14 +254,14 @@ - (void)attachReadyHandler:(RNGestureHandler *)handler
254254
withHostDetector:self];
255255
} else {
256256
// Hierarchy was folded into a single UIView.
257-
[manager.registry attachHandlerWithTag:handler.tag toView:self withActionType:actionType withHostDetector:self];
257+
[manager attachHandlerForDetectorWithTag:handler.tag toView:self withActionType:actionType withHostDetector:self];
258258
handler.virtualViewTag = @(viewTag);
259259
}
260260
[_attachedHandlers addObject:handler.tag];
261261
return;
262262
}
263263

264-
[manager.registry attachHandlerWithTag:handler.tag toView:self withActionType:actionType withHostDetector:self];
264+
[manager attachHandlerForDetectorWithTag:handler.tag toView:self withActionType:actionType withHostDetector:self];
265265
[_attachedHandlers addObject:handler.tag];
266266
}
267267

@@ -351,10 +351,10 @@ - (void)tryAttachNativeHandlersToChildView
351351
if ([handlerManager.registry handlerWithTag:handlerTag] == nil) {
352352
continue;
353353
}
354-
[handlerManager.registry attachHandlerWithTag:handlerTag
355-
toView:view
356-
withActionType:RNGestureHandlerActionTypeNativeDetector
357-
withHostDetector:self];
354+
[handlerManager attachHandlerForDetectorWithTag:handlerTag
355+
toView:view
356+
withActionType:RNGestureHandlerActionTypeNativeDetector
357+
withHostDetector:self];
358358
[_attachedHandlers addObject:handlerTag];
359359
}
360360
}

packages/react-native-gesture-handler/apple/RNGestureHandlerManager.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929
withActionType:(RNGestureHandlerActionType)actionType
3030
withHostDetector:(nullable RNGHUIView *)hostDetector;
3131

32+
- (void)attachHandlerForDetectorWithTag:(nonnull NSNumber *)handlerTag
33+
toView:(nonnull RNGHUIView *)view
34+
withActionType:(RNGestureHandlerActionType)actionType
35+
withHostDetector:(nullable RNGHUIView *)hostDetector;
36+
3237
- (void)setGestureHandlerConfig:(nonnull NSNumber *)handlerTag config:(nonnull NSDictionary *)config;
3338

3439
- (void)updateGestureHandlerConfig:(nonnull NSNumber *)handlerTag config:(nonnull NSDictionary *)config;

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,15 @@ - (void)maybeBindHandler:(nonnull NSNumber *)handlerTag
209209
[self registerViewWithGestureRecognizerAttachedIfNeeded:view];
210210
}
211211

212+
- (void)attachHandlerForDetectorWithTag:(nonnull NSNumber *)handlerTag
213+
toView:(nonnull RNGHUIView *)view
214+
withActionType:(RNGestureHandlerActionType)actionType
215+
withHostDetector:(nullable RNGHUIView *)hostDetector
216+
{
217+
[_registry attachHandlerWithTag:handlerTag toView:view withActionType:actionType withHostDetector:hostDetector];
218+
[self registerViewWithGestureRecognizerAttachedIfNeeded:view];
219+
}
220+
212221
- (void)setGestureHandlerConfig:(NSNumber *)handlerTag config:(NSDictionary *)config
213222
{
214223
RNGestureHandler *handler = [_registry handlerWithTag:handlerTag];

0 commit comments

Comments
 (0)