From 6b368acde263296667ccf7e0a6668bde092a0ed5 Mon Sep 17 00:00:00 2001 From: Wojciech Lewicki Date: Tue, 6 Sep 2022 13:39:10 +0200 Subject: [PATCH 1/6] fix: try to apply pointer events behaviors in overlay --- ios/RNSFullWindowOverlay.mm | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/ios/RNSFullWindowOverlay.mm b/ios/RNSFullWindowOverlay.mm index 52d1914d0d..17a8be48e8 100644 --- a/ios/RNSFullWindowOverlay.mm +++ b/ios/RNSFullWindowOverlay.mm @@ -4,11 +4,11 @@ #ifdef RN_FABRIC_ENABLED #import +#import #import #import #import #import -#import #else #import #endif // RN_FABRIC_ENABLED @@ -25,6 +25,38 @@ - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event return NO; } +- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event +{ + BOOL canReceiveTouchEvents = ([self isUserInteractionEnabled] && ![self isHidden]); + if (!canReceiveTouchEvents) { + return nil; + } + + // `hitSubview` is the topmost subview which was hit. The hit point can + // be outside the bounds of `view` (e.g., if -clipsToBounds is NO). + UIView *hitSubview = nil; + BOOL isPointInside = [self pointInside:point withEvent:event]; + if (![self clipsToBounds] || isPointInside) { + // Take z-index into account when calculating the touch target. + NSArray *sortedSubviews = [self reactZIndexSortedSubviews]; + + // The default behaviour of UIKit is that if a view does not contain a point, + // then no subviews will be returned from hit testing, even if they contain + // the hit point. By doing hit testing directly on the subviews, we bypass + // the strict containment policy (i.e., UIKit guarantees that every ancestor + // of the hit view will return YES from -pointInside:withEvent:). See: + // - https://developer.apple.com/library/ios/qa/qa2013/qa1812.html + for (UIView *subview in [sortedSubviews reverseObjectEnumerator]) { + CGPoint convertedPoint = [subview convertPoint:point fromView:self]; + hitSubview = [subview hitTest:convertedPoint withEvent:event]; + if (hitSubview != nil) { + break; + } + } + } + return hitSubview; +} + @end @implementation RNSFullWindowOverlay { From b0ca11746aa0e3c90b422a3c6cb62d3f83d59b51 Mon Sep 17 00:00:00 2001 From: Wojciech Lewicki Date: Tue, 6 Sep 2022 13:42:43 +0200 Subject: [PATCH 2/6] feat: make test case show new behavior --- TestsExample/src/Test1096.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/TestsExample/src/Test1096.tsx b/TestsExample/src/Test1096.tsx index 6e6bb1753e..f18b52d31f 100644 --- a/TestsExample/src/Test1096.tsx +++ b/TestsExample/src/Test1096.tsx @@ -34,9 +34,11 @@ function Home({ /> - - -