Browse Source

Added tapBackgroundToDismiss to LightBox screens (#1416)

* Added tapBackgroundToDismiss to LightBox screens

* Updated LightBox readme

* Formatting updates

* Fixed ios selector

* Updated animationEnd hide method
Brendon Sled 7 years ago
parent
commit
3ee0cd1958

+ 1
- 0
android/app/src/main/java/com/reactnativenavigation/params/LightBoxParams.java View File

@@ -4,4 +4,5 @@ public class LightBoxParams {
4 4
     public String screenId;
5 5
     public NavigationParams navigationParams;
6 6
     public StyleParams.Color backgroundColor;
7
+    public boolean tapBackgroundToDismiss;
7 8
 }

+ 1
- 1
android/app/src/main/java/com/reactnativenavigation/params/parsers/LightBoxParamsParser.java View File

@@ -1,7 +1,6 @@
1 1
 package com.reactnativenavigation.params.parsers;
2 2
 
3 3
 import android.os.Bundle;
4
-
5 4
 import com.reactnativenavigation.params.LightBoxParams;
6 5
 import com.reactnativenavigation.params.NavigationParams;
7 6
 
@@ -20,6 +19,7 @@ public class LightBoxParamsParser extends Parser {
20 19
         result.screenId = params.getString("screenId");
21 20
         result.navigationParams = new NavigationParams(params.getBundle("navigationParams"));
22 21
         result.backgroundColor = getColor(params, "backgroundColor");
22
+        result.tapBackgroundToDismiss = params.getBoolean("tapBackgroundToDismiss");
23 23
         return result;
24 24
     }
25 25
 }

+ 10
- 1
android/app/src/main/java/com/reactnativenavigation/views/LightBox.java View File

@@ -54,6 +54,15 @@ public class LightBox extends Dialog implements DialogInterface.OnDismissListene
54 54
         lightBox.setBackgroundColor(params.backgroundColor.getColor());
55 55
         lightBox.addView(content, lp);
56 56
 
57
+        if (params.tapBackgroundToDismiss) {
58
+            lightBox.setOnClickListener(new View.OnClickListener() {
59
+                @Override
60
+                public void onClick(View v) {
61
+                    hide();
62
+                }
63
+            });
64
+        }
65
+
57 66
         content.setOnDisplayListener(new Screen.OnDisplayListener() {
58 67
             @Override
59 68
             public void onDisplay() {
@@ -123,7 +132,7 @@ public class LightBox extends Dialog implements DialogInterface.OnDismissListene
123 132
         allAnimators.addListener(new AnimatorListenerAdapter() {
124 133
             @Override
125 134
             public void onAnimationEnd(Animator animation) {
126
-                dismiss();
135
+                destroy();
127 136
             }
128 137
         });
129 138
         allAnimators.start();

+ 2
- 1
docs/top-level-api.md View File

@@ -145,7 +145,8 @@ Navigation.showLightBox({
145 145
   passProps: {}, // simple serializable object that will pass as props to the lightbox (optional)
146 146
   style: {
147 147
     backgroundBlur: "dark", // 'dark' / 'light' / 'xlight' / 'none' - the type of blur on the background
148
-    backgroundColor: "#ff000080" // tint color for the background, you can specify alpha here (optional)
148
+    backgroundColor: "#ff000080", // tint color for the background, you can specify alpha here (optional)
149
+    tapBackgroundToDismiss: true // dismisses LightBox on background taps (optional)
149 150
   }
150 151
 });
151 152
 ```

+ 7
- 1
ios/RCCLightBox.m View File

@@ -41,7 +41,7 @@ const NSInteger kLightBoxTag = 0x101010;
41 41
                 self.visualEffectView.frame = CGRectMake(0, 0, frame.size.width, frame.size.height);
42 42
                 [self addSubview:self.visualEffectView];
43 43
             }
44
-            
44
+
45 45
             if (style[@"backgroundColor"] != nil)
46 46
             {
47 47
                 UIColor *backgroundColor = [RCTConvert UIColor:style[@"backgroundColor"]];
@@ -51,6 +51,12 @@ 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
+                    }
54 60
                 }
55 61
             }
56 62
         }

+ 1
- 0
src/deprecated/platformSpecificDeprecated.android.js View File

@@ -444,6 +444,7 @@ function showLightBox(params) {
444 444
       params.backgroundColor = processColor('transparent');
445 445
     }
446 446
   }
447
+  params.tapBackgroundToDismiss = _.get(params, 'style.tapBackgroundToDismiss') || false;
447 448
   newPlatformSpecific.showLightBox(params);
448 449
 }
449 450