[RCTScrollView] Make ScrollView detect taps on sticky headers

Summary:
As per discussion with @nicklockwood in #875, make `RCTScrollView` check its sticky headers for hitTests first.

Closes https://github.com/facebook/react-native/pull/1415
Github Author: Brent Vatne <brent.vatne@madriska.com>

Test Plan:
 Have a sticky header in a ScrollView with a Touchable onPress action, scroll a bit after it docks and try tapping, should respond to tap.
This commit is contained in:
Brent Vatne 2015-05-26 18:27:03 -07:00
parent 76ea00483d
commit 95517fca41
1 changed files with 18 additions and 0 deletions

View File

@ -223,6 +223,24 @@ CGFloat const ZINDEX_STICKY_HEADER = 50;
}
}
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
__block UIView *stickyHeader;
[_stickyHeaderIndices enumerateIndexesWithOptions:0 usingBlock:^(NSUInteger idx, BOOL *stop) {
stickyHeader = [self contentView].reactSubviews[idx];
CGPoint convertedPoint = [stickyHeader convertPoint:point fromView:self];
if ([stickyHeader hitTest:convertedPoint withEvent:event]) {
*stop = YES;
} else {
stickyHeader = nil;
}
}];
return stickyHeader ?: [super hitTest:point withEvent:event];
}
@end
@implementation RCTScrollView