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
     public String screenId;
4
     public String screenId;
5
     public NavigationParams navigationParams;
5
     public NavigationParams navigationParams;
6
     public StyleParams.Color backgroundColor;
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
 package com.reactnativenavigation.params.parsers;
1
 package com.reactnativenavigation.params.parsers;
2
 
2
 
3
 import android.os.Bundle;
3
 import android.os.Bundle;
4
-
5
 import com.reactnativenavigation.params.LightBoxParams;
4
 import com.reactnativenavigation.params.LightBoxParams;
6
 import com.reactnativenavigation.params.NavigationParams;
5
 import com.reactnativenavigation.params.NavigationParams;
7
 
6
 
20
         result.screenId = params.getString("screenId");
19
         result.screenId = params.getString("screenId");
21
         result.navigationParams = new NavigationParams(params.getBundle("navigationParams"));
20
         result.navigationParams = new NavigationParams(params.getBundle("navigationParams"));
22
         result.backgroundColor = getColor(params, "backgroundColor");
21
         result.backgroundColor = getColor(params, "backgroundColor");
22
+        result.tapBackgroundToDismiss = params.getBoolean("tapBackgroundToDismiss");
23
         return result;
23
         return result;
24
     }
24
     }
25
 }
25
 }

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

54
         lightBox.setBackgroundColor(params.backgroundColor.getColor());
54
         lightBox.setBackgroundColor(params.backgroundColor.getColor());
55
         lightBox.addView(content, lp);
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
         content.setOnDisplayListener(new Screen.OnDisplayListener() {
66
         content.setOnDisplayListener(new Screen.OnDisplayListener() {
58
             @Override
67
             @Override
59
             public void onDisplay() {
68
             public void onDisplay() {
123
         allAnimators.addListener(new AnimatorListenerAdapter() {
132
         allAnimators.addListener(new AnimatorListenerAdapter() {
124
             @Override
133
             @Override
125
             public void onAnimationEnd(Animator animation) {
134
             public void onAnimationEnd(Animator animation) {
126
-                dismiss();
135
+                destroy();
127
             }
136
             }
128
         });
137
         });
129
         allAnimators.start();
138
         allAnimators.start();

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

145
   passProps: {}, // simple serializable object that will pass as props to the lightbox (optional)
145
   passProps: {}, // simple serializable object that will pass as props to the lightbox (optional)
146
   style: {
146
   style: {
147
     backgroundBlur: "dark", // 'dark' / 'light' / 'xlight' / 'none' - the type of blur on the background
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
                 self.visualEffectView.frame = CGRectMake(0, 0, frame.size.width, frame.size.height);
41
                 self.visualEffectView.frame = CGRectMake(0, 0, frame.size.width, frame.size.height);
42
                 [self addSubview:self.visualEffectView];
42
                 [self addSubview:self.visualEffectView];
43
             }
43
             }
44
-            
44
+
45
             if (style[@"backgroundColor"] != nil)
45
             if (style[@"backgroundColor"] != nil)
46
             {
46
             {
47
                 UIColor *backgroundColor = [RCTConvert UIColor:style[@"backgroundColor"]];
47
                 UIColor *backgroundColor = [RCTConvert UIColor:style[@"backgroundColor"]];
51
                     self.overlayColorView.backgroundColor = backgroundColor;
51
                     self.overlayColorView.backgroundColor = backgroundColor;
52
                     self.overlayColorView.alpha = 0;
52
                     self.overlayColorView.alpha = 0;
53
                     [self addSubview:self.overlayColorView];
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
       params.backgroundColor = processColor('transparent');
444
       params.backgroundColor = processColor('transparent');
445
     }
445
     }
446
   }
446
   }
447
+  params.tapBackgroundToDismiss = _.get(params, 'style.tapBackgroundToDismiss') || false;
447
   newPlatformSpecific.showLightBox(params);
448
   newPlatformSpecific.showLightBox(params);
448
 }
449
 }
449
 
450