1// Copyright 2015-present 650 Industries. All rights reserved. 2 3#import "EXEnvironment.h" 4#import "EXKernel.h" 5#import "EXViewController.h" 6#import "EXAppViewController.h" 7#import "ExpoKit.h" 8#import "EXUtil.h" 9 10@implementation EXViewController 11 12- (void)viewDidLoad 13{ 14 [super viewDidLoad]; 15 self.view.backgroundColor = [UIColor whiteColor]; 16 [self createRootAppAndMakeVisible]; 17} 18 19- (void)viewWillLayoutSubviews 20{ 21 [super viewWillLayoutSubviews]; 22 if (_contentViewController) { 23 _contentViewController.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height); 24 } 25} 26 27- (UIRectEdge)edgesForExtendedLayout 28{ 29 return UIRectEdgeNone; 30} 31 32- (BOOL)extendedLayoutIncludesOpaqueBars 33{ 34 return YES; 35} 36 37- (void)createRootAppAndMakeVisible 38{ 39 NSURL *standaloneAppUrl = [NSURL URLWithString:[EXEnvironment sharedEnvironment].standaloneManifestUrl]; 40 NSDictionary *initialProps = [[EXKernel sharedInstance] initialAppPropsFromLaunchOptions:[ExpoKit sharedInstance].launchOptions]; 41 EXKernelAppRecord *appRecord = [[EXKernel sharedInstance] createNewAppWithUrl:standaloneAppUrl 42 initialProps:initialProps]; 43 44 UIViewController *viewControllerToShow = (UIViewController *)appRecord.viewController; 45 46 [viewControllerToShow willMoveToParentViewController:self]; 47 [self.view addSubview:viewControllerToShow.view]; 48 [viewControllerToShow didMoveToParentViewController:self]; 49 50 _contentViewController = viewControllerToShow; 51 [self.view setNeedsLayout]; 52 if (_delegate) { 53 [_delegate viewController:self didNavigateAppToVisible:appRecord]; 54 } 55} 56 57- (void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^_Nullable)(void))completion 58{ 59 // @tsapeta: some RN's modules try to present modal view controllers on EXRootViewController 60 // but for the correct behavior they should be presented on the innermost controller in EXAppViewController hierarchy, 61 // so we just pass this call to the current controller. 62 if ([viewControllerToPresent isKindOfClass:[UIAlertController class]] 63 || [viewControllerToPresent isKindOfClass:[UIDocumentMenuViewController class]] 64// || [viewControllerToPresent isKindOfClass:[UIImagePickerController class]] // ImagePicker invoked from WebView with this specific logic makes AppController holding WebView to be dismissed 65 || [viewControllerToPresent isKindOfClass:[UIActivityViewController class]] 66 ) { 67 [[[ExpoKit sharedInstance] currentViewController] presentViewController:viewControllerToPresent animated:flag completion:completion]; 68 } else { 69 [super presentViewController:viewControllerToPresent animated:flag completion:completion]; 70 } 71} 72 73@end 74