-
-
Notifications
You must be signed in to change notification settings - Fork 514
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(iOS, Fabric): add missing logic for finding touch handler #2193
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we're keeping in this file only TouchHandler-specific code, I would call this file as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I used already existing category name - RNSUtility (we have already introduced this one), and I think it is better suited for future, as putting any more utility methods in |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#import <Foundation/Foundation.h> | ||
|
||
#ifdef RCT_NEW_ARCH_ENABLED | ||
#import <React/RCTSurfaceTouchHandler.h> | ||
#else | ||
#import <React/RCTTouchHandler.h> | ||
#endif // RCT_NEW_ARCH_ENABLED | ||
|
||
#ifdef RCT_NEW_ARCH_ENABLED | ||
#define RNS_TOUCH_HANDLER_ARCH_TYPE RCTSurfaceTouchHandler | ||
#else | ||
#define RNS_TOUCH_HANDLER_ARCH_TYPE RCTTouchHandler | ||
Comment on lines
+10
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried using |
||
#endif // RCT_NEW_ARCH_ENABLED | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface UIView (RNSUtility) | ||
|
||
- (nullable RNS_TOUCH_HANDLER_ARCH_TYPE *)rnscreens_findTouchHandlerInAncestorChain; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
|
||
#import "UIView+RNSUtility.h" | ||
|
||
#ifdef RCT_NEW_ARCH_ENABLED | ||
#import <React/RCTSurfaceView.h> | ||
#endif | ||
|
||
@implementation UIView (RNSUtility) | ||
|
||
- (nullable RNS_TOUCH_HANDLER_ARCH_TYPE *)rnscreens_findTouchHandlerInAncestorChain | ||
{ | ||
UIView *parent = self; | ||
|
||
#ifdef RCT_NEW_ARCH_ENABLED | ||
// On Fabric there is no view that exposes touchHandler above us in the view hierarchy, however it is still | ||
// utilised. `RCTSurfaceView` should be present above us, which hosts `RCTFabricSurface` instance, which in turn | ||
// hosts `RCTSurfaceTouchHandler` as a private field. When initialised, `RCTSurfaceTouchHandler` is attached to the | ||
// surface view as a gestureRecognizer <- and this is where we can lay our hands on it. | ||
|
||
while (parent != nil && ![parent isKindOfClass:RCTSurfaceView.class]) { | ||
parent = parent.superview; | ||
} | ||
|
||
// This could be possible in modal context | ||
if (parent == nil) { | ||
return nil; | ||
} | ||
|
||
// Experimentation shows that RCTSurfaceTouchHandler is the only gestureRecognizer registered here, | ||
// so we should not be afraid of any performance hit here. | ||
for (UIGestureRecognizer *recognizer in parent.gestureRecognizers) { | ||
if ([recognizer isKindOfClass:RCTSurfaceTouchHandler.class]) { | ||
return static_cast<RNS_TOUCH_HANDLER_ARCH_TYPE *>(recognizer); | ||
} | ||
} | ||
|
||
#else | ||
|
||
// On Paper we can access touchHandler hosted by `RCTRootContentView` which should be above ScreenStack | ||
// in view hierarchy. | ||
while (parent != nil && ![parent respondsToSelector:@selector(touchHandler)]) { | ||
parent = parent.superview; | ||
} | ||
|
||
if (parent != nil) { | ||
RCTTouchHandler *touchHandler = [parent performSelector:@selector(touchHandler)]; | ||
return static_cast<RNS_TOUCH_HANDLER_ARCH_TYPE *>(touchHandler); | ||
} | ||
|
||
#endif // RCT_NEW_ARCH_ENABLED | ||
|
||
return nil; | ||
} | ||
|
||
@end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we do something like:
to improve readability?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find it quite opposite 😄 I'm mean the redundant variable strikes me => I'll stay by current version as this is taste related, but thanks.