Skip to content

Commit

Permalink
Fix hitTest for auto
Browse files Browse the repository at this point in the history
Summary:
- Returns matching subview hitTest or super hitTest if no match found. Should fix #99 .

Closes #501
Github Author: Boopathi Rajaa <me@boopathi.in>

Test Plan: Imported from GitHub, without a `Test Plan:` line.
  • Loading branch information
boopathi authored and oss sync committed Apr 12, 2015
1 parent 09a17b7 commit 2572449
Showing 1 changed file with 16 additions and 11 deletions.
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;

static 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

0 comments on commit 2572449

Please sign in to comment.