Skip to content

Commit

Permalink
[fabric] Add conditional coordinate space conversion for native view …
Browse files Browse the repository at this point in the history
…hit testing

Summary:
Native views use the AppKit api for hit testing which requires the point to be in the superview coordinate system.

This diff updates the hit testing in `RCTViewComponentView` to conditionally converts the point to the target view coordinate system only if the tested view is a react view.

Test Plan:
Run Zeratul with Fabric and select text inside message bubbles. The scroll view being a native view, the hit testing does not require a point conversion. With this change, the text selection works as expected.

| Before | After |
|--|
|  https://pxl.cl/3Mlpb  |  https://pxl.cl/3MllN  |

Reviewers: shawndempsey, #rn-desktop

Reviewed By: shawndempsey

Differential Revision: https://phabricator.intern.facebook.com/D51129375

Tags: uikit-diff
  • Loading branch information
Nick Lefever authored and Saadnajmi committed Nov 29, 2024
1 parent 22b7063 commit 96881d7
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#import <React/RCTCursor.h> // [macOS]
#import <React/RCTLocalizedString.h>
#import <react/featureflags/ReactNativeFeatureFlags.h>
#import <React/RCTView.h> // [macOS]
#import <react/renderer/components/view/ViewComponentDescriptor.h>
#import <react/renderer/components/view/ViewEventEmitter.h>
#import <react/renderer/components/view/ViewProps.h>
Expand Down Expand Up @@ -669,7 +670,16 @@ - (RCTUIView *)betterHitTest:(CGPoint)point withEvent:(UIEvent *)event // [macOS
}

for (RCTUIView *subview in [self.subviews reverseObjectEnumerator]) { // [macOS]
RCTUIView *hitView = [subview hitTest:[subview convertPoint:point fromView:self] withEvent:event]; // [macOS]
// Native macOS views require the point to be in the super view coordinate space for hit testing. [macOS]
CGPoint hitTestPoint = point;
#if TARGET_OS_OSX // [macOS
// Paper and Fabric components use the target view coordinate space for hit testing
if ([subview isKindOfClass:[RCTView class]] || [subview isKindOfClass:[RCTViewComponentView class]]) {
hitTestPoint = [subview convertPoint:point fromView:self];
}
#endif // macOS]

RCTUIView *hitView = [subview hitTest:hitTestPoint withEvent:event]; // [macOS]
if (hitView) {
return hitView;
}
Expand Down

0 comments on commit 96881d7

Please sign in to comment.