Преглед на файлове

[iOS] Allow lightbox tap to dismiss without background color (#1440)

* Move logic for tap background to dismiss out of background color view

This allows for tapping the background without setting a color here, meaning this feature can be enabled with one less view in the view hierarchy

* Only allow taps on views that aren't the React view

This allows for taps on any background view, visual effect view, color tint view, etc, but not on the content.
Eli Perkins преди 7 години
родител
ревизия
834962bf89
променени са 1 файла, в които са добавени 14 реда и са изтрити 7 реда
  1. 14
    7
      ios/RCCLightBox.m

+ 14
- 7
ios/RCCLightBox.m Целия файл

@@ -8,7 +8,7 @@
8 8
 
9 9
 const NSInteger kLightBoxTag = 0x101010;
10 10
 
11
-@interface RCCLightBoxView : UIView
11
+@interface RCCLightBoxView : UIView<UIGestureRecognizerDelegate>
12 12
 @property (nonatomic, strong) RCTRootView *reactView;
13 13
 @property (nonatomic, strong) UIVisualEffectView *visualEffectView;
14 14
 @property (nonatomic, strong) UIView *overlayColorView;
@@ -51,14 +51,15 @@ const NSInteger kLightBoxTag = 0x101010;
51 51
                     self.overlayColorView.backgroundColor = backgroundColor;
52 52
                     self.overlayColorView.alpha = 0;
53 53
                     [self addSubview:self.overlayColorView];
54
-
55
-                    if (style[@"tapBackgroundToDismiss"] != nil && [RCTConvert BOOL:style[@"tapBackgroundToDismiss"]])
56
-                    {
57
-                        UITapGestureRecognizer *singleTap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissAnimated)];
58
-                        [self.overlayColorView addGestureRecognizer:singleTap];
59
-                    }
60 54
                 }
61 55
             }
56
+
57
+            if (style[@"tapBackgroundToDismiss"] != nil && [RCTConvert BOOL:style[@"tapBackgroundToDismiss"]])
58
+            {
59
+                UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissAnimated)];
60
+                singleTap.delegate = self;
61
+                [self addGestureRecognizer:singleTap];
62
+            }
62 63
         }
63 64
         
64 65
         self.reactView = [[RCTRootView alloc] initWithBridge:[[RCCManager sharedInstance] getBridge] moduleName:self.params[@"component"] initialProperties:passProps];
@@ -76,6 +77,12 @@ const NSInteger kLightBoxTag = 0x101010;
76 77
     return self;
77 78
 }
78 79
 
80
+
81
+-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
82
+{
83
+    return ![touch.view isDescendantOfView:self.reactView];
84
+}
85
+
79 86
 -(void)layoutSubviews
80 87
 {
81 88
     [super layoutSubviews];