From 95517fca413bf84231b63f10bc680a1c6fe917c2 Mon Sep 17 00:00:00 2001 From: Brent Vatne Date: Tue, 26 May 2015 18:27:03 -0700 Subject: [PATCH] [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 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. --- React/Views/RCTScrollView.m | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/React/Views/RCTScrollView.m b/React/Views/RCTScrollView.m index d4a2ad5e9..d64a583af 100644 --- a/React/Views/RCTScrollView.m +++ b/React/Views/RCTScrollView.m @@ -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