Permalink
Browse files

Don't receive touches in RCTRootView

Reviewed By: mmmulani, majak

Differential Revision: D4104319

fbshipit-source-id: 70731b72e087710ccbc32024a596583640b94d04
  • Loading branch information...
javache authored and Facebook Github Bot committed Nov 3, 2016
1 parent 68aeffe commit 761e06bf0225b492af37d258041cd87b70d0a549
Showing with 43 additions and 0 deletions.
  1. +12 −0 React/Base/RCTRootView.h
  2. +31 −0 React/Base/RCTRootView.m
View
@@ -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
@@ -40,6 +40,7 @@ @interface RCTRootContentView : RCTView <RCTInvalidating>
@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 @@ - (void)setBackgroundColor:(UIColor *)backgroundColor
_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 @@ - (void)layoutSubviews
};
}
+- (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 @@ - (UIColor *)backgroundColor
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) {

0 comments on commit 761e06b

Please sign in to comment.