Browse Source

Prefer use of view controller hierarchy to display lightbox (#1439)

This fixes issues with other React Native views which rely on the view controller hierarchy.
Eli Perkins 7 years ago
parent
commit
9d8b392f55
1 changed files with 7 additions and 13 deletions
  1. 7
    13
      ios/RCCLightBox.m

+ 7
- 13
ios/RCCLightBox.m View File

@@ -3,6 +3,7 @@
3 3
 #import <React/RCTRootView.h>
4 4
 #import <React/RCTRootViewDelegate.h>
5 5
 #import <React/RCTConvert.h>
6
+#import <React/RCTUtils.h>
6 7
 #import "RCTHelpers.h"
7 8
 #import <objc/runtime.h>
8 9
 
@@ -214,31 +215,24 @@ const NSInteger kLightBoxTag = 0x101010;
214 215
 
215 216
 @implementation RCCLightBox
216 217
 
217
-+(UIWindow*)getWindow
218
-{
219
-    UIApplication *app = [UIApplication sharedApplication];
220
-    UIWindow *window = (app.keyWindow != nil) ? app.keyWindow : app.windows[0];
221
-    return window;
222
-}
223
-
224 218
 +(void)showWithParams:(NSDictionary*)params
225 219
 {
226
-    UIWindow *window = [RCCLightBox getWindow];
227
-    if ([window viewWithTag:kLightBoxTag] != nil)
220
+    UIViewController *viewController = RCTPresentedViewController();
221
+    if ([viewController.view viewWithTag:kLightBoxTag] != nil)
228 222
     {
229 223
         return;
230 224
     }
231
-    
225
+
232 226
     RCCLightBoxView *lightBox = [[RCCLightBoxView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height) params:params];
233 227
     lightBox.tag = kLightBoxTag;
234
-    [window addSubview:lightBox];
228
+    [viewController.view addSubview:lightBox];
235 229
     [lightBox showAnimated];
236 230
 }
237 231
 
238 232
 +(void)dismiss
239 233
 {
240
-    UIWindow *window = [RCCLightBox getWindow];
241
-    RCCLightBoxView *lightBox = [window viewWithTag:kLightBoxTag];
234
+    UIViewController *viewController = RCTPresentedViewController();
235
+    RCCLightBoxView *lightBox = [viewController.view viewWithTag:kLightBoxTag];
242 236
     if (lightBox != nil)
243 237
     {
244 238
         [lightBox dismissAnimated];