1// Copyright 2015-present 650 Industries. All rights reserved.
2
3#import "EXKernel.h"
4#import "EXScreenOrientationManager.h"
5#import "EXViewController.h"
6#import "EXShellManager.h"
7
8@interface EXViewController ()
9
10@end
11
12@implementation EXViewController
13
14- (void)viewDidLoad
15{
16  [super viewDidLoad];
17  self.view.backgroundColor = [UIColor whiteColor];
18  [self createRootAppAndMakeVisible];
19}
20
21- (void)viewWillLayoutSubviews
22{
23  [super viewWillLayoutSubviews];
24  if (_contentViewController) {
25    _contentViewController.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
26  }
27}
28
29- (UIRectEdge)edgesForExtendedLayout
30{
31  return UIRectEdgeNone;
32}
33
34- (BOOL)extendedLayoutIncludesOpaqueBars
35{
36  return YES;
37}
38
39- (void)createRootAppAndMakeVisible
40{
41  NSURL *standaloneAppUrl = [NSURL URLWithString:[EXShellManager sharedInstance].shellManifestUrl];
42  EXKernelAppRecord *appRecord = [[EXKernel sharedInstance] createNewAppWithUrl:standaloneAppUrl 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- (BOOL)shouldAutorotate
58{
59  return YES;
60}
61
62- (UIInterfaceOrientationMask)supportedInterfaceOrientations
63{
64  return [[EXKernel sharedInstance].serviceRegistry.screenOrientationManager supportedInterfaceOrientationsForVisibleApp];
65}
66
67@end
68