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

@@ -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) {