Skip to content
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 hitTest for auto #501

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions React/Views/RCTView.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@

static const RCTBorderSide RCTBorderSideCount = 4;

NS_INLINE UIView *RCTViewHitTest(UIView *view, CGPoint point, UIEvent *event)
{
for (UIView *subview in [view.subviews reverseObjectEnumerator]) {
if (!subview.isHidden && subview.isUserInteractionEnabled && subview.alpha > 0) {
CGPoint convertedPoint = [subview convertPoint:point fromView:view];
UIView *subviewHitTestView = [subview hitTest:convertedPoint withEvent:event];
if (subviewHitTestView != nil) {
return subviewHitTestView;
}
}
}
return nil;
}

@implementation UIView (RCTViewUnmounting)

- (void)react_remountAllSubviews
Expand Down Expand Up @@ -120,20 +134,11 @@ - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
case RCTPointerEventsNone:
return nil;
case RCTPointerEventsUnspecified:
return [super hitTest:point withEvent:event];
return RCTViewHitTest(self, point, event) ?: [super hitTest:point withEvent:event];
case RCTPointerEventsBoxOnly:
return [super hitTest:point withEvent:event] ? self: nil;
case RCTPointerEventsBoxNone:
for (UIView *subview in [self.subviews reverseObjectEnumerator]) {
if (!subview.isHidden && subview.isUserInteractionEnabled && subview.alpha > 0) {
CGPoint convertedPoint = [subview convertPoint:point fromView:self];
UIView *subviewHitTestView = [subview hitTest:convertedPoint withEvent:event];
if (subviewHitTestView != nil) {
return subviewHitTestView;
}
}
}
return nil;
return RCTViewHitTest(self, point, event);
default:
RCTLogError(@"Invalid pointer-events specified %zd on %@", _pointerEvents, self);
return [super hitTest:point withEvent:event];
Expand Down