Don't receive touches in RCTRootView

Reviewed By: mmmulani, majak

Differential Revision: D4104319

fbshipit-source-id: 70731b72e087710ccbc32024a596583640b94d04
This commit is contained in:
Pieter De Baets 2016-11-03 09:55:20 -07:00 committed by Facebook Github Bot
parent 68aeffe01f
commit 761e06bf02
2 changed files with 43 additions and 0 deletions

View File

@ -135,6 +135,18 @@ extern NSString *const RCTContentDidAppearNotification;
*/
- (void)cancelTouches;
/**
* When set, any touches on the RCTRootView that are not matched up to any of the child
* views will be passed to siblings of the RCTRootView. See -[UIView hitTest:withEvent:]
* for details on iOS hit testing.
*
* Enable this to support a semi-transparent RN view that occupies the whole screen but
* has visible content below it that the user can interact with.
*
* The default value is NO.
*/
@property (nonatomic, assign) BOOL passThroughTouches;
/**
* Timings for hiding the loading view after the content has loaded. Both of
* these values default to 0.25 seconds.

View File

@ -40,6 +40,7 @@ NSString *const RCTContentDidAppearNotification = @"RCTContentDidAppearNotificat
@property (nonatomic, readonly) BOOL contentHasAppeared;
@property (nonatomic, readonly, strong) RCTTouchHandler *touchHandler;
@property (nonatomic, assign) BOOL passThroughTouches;
- (instancetype)initWithFrame:(CGRect)frame
bridge:(RCTBridge *)bridge
@ -125,6 +126,16 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder)
_contentView.backgroundColor = backgroundColor;
}
- (BOOL)passThroughTouches
{
return _contentView.passThroughTouches;
}
- (void)setPassThroughTouches:(BOOL)passThroughTouches
{
_contentView.passThroughTouches = passThroughTouches;
}
- (UIViewController *)reactViewController
{
return _reactViewController ?: [super reactViewController];
@ -259,6 +270,16 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder)
};
}
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
// The root view itself should never receive touches
UIView *hitView = [super hitTest:point withEvent:event];
if (self.passThroughTouches && hitView == self) {
return nil;
}
return hitView;
}
- (void)setAppProperties:(NSDictionary *)appProperties
{
RCTAssertMainQueue();
@ -382,6 +403,16 @@ RCT_NOT_IMPLEMENTED(-(instancetype)initWithCoder:(nonnull NSCoder *)aDecoder)
return _backgroundColor;
}
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
// The root content view itself should never receive touches
UIView *hitView = [super hitTest:point withEvent:event];
if (_passThroughTouches && hitView == self) {
return nil;
}
return hitView;
}
- (void)invalidate
{
if (self.userInteractionEnabled) {