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