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
 #import <React/RCTRootView.h>
3
 #import <React/RCTRootView.h>
4
 #import <React/RCTRootViewDelegate.h>
4
 #import <React/RCTRootViewDelegate.h>
5
 #import <React/RCTConvert.h>
5
 #import <React/RCTConvert.h>
6
+#import <React/RCTUtils.h>
6
 #import "RCTHelpers.h"
7
 #import "RCTHelpers.h"
7
 #import <objc/runtime.h>
8
 #import <objc/runtime.h>
8
 
9
 
214
 
215
 
215
 @implementation RCCLightBox
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
 +(void)showWithParams:(NSDictionary*)params
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
         return;
223
         return;
230
     }
224
     }
231
-    
225
+
232
     RCCLightBoxView *lightBox = [[RCCLightBoxView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height) params:params];
226
     RCCLightBoxView *lightBox = [[RCCLightBoxView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height) params:params];
233
     lightBox.tag = kLightBoxTag;
227
     lightBox.tag = kLightBoxTag;
234
-    [window addSubview:lightBox];
228
+    [viewController.view addSubview:lightBox];
235
     [lightBox showAnimated];
229
     [lightBox showAnimated];
236
 }
230
 }
237
 
231
 
238
 +(void)dismiss
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
     if (lightBox != nil)
236
     if (lightBox != nil)
243
     {
237
     {
244
         [lightBox dismissAnimated];
238
         [lightBox dismissAnimated];