MainViewController.m 2.13 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#import "MainViewController.h"

#import "AppDelegate.h"
#import "FullScreenViewController.h"

@interface MainViewController ()

@property(nonatomic, strong) UIStackView* stackView;

@end


@implementation MainViewController

- (void)viewDidLoad {
  [super viewDidLoad];

  [self.view setFrame:self.view.window.bounds];
  self.title = @"Flutter iOS Demos";
  self.view.backgroundColor = UIColor.whiteColor;

  self.stackView = [[UIStackView alloc] initWithFrame:self.view.frame];
  self.stackView.axis = UILayoutConstraintAxisVertical;
  self.stackView.distribution = UIStackViewDistributionEqualSpacing;
  self.stackView.alignment = UIStackViewAlignmentCenter;
  self.stackView.autoresizingMask =
      UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  self.stackView.layoutMargins = UIEdgeInsetsMake(0, 0, 50, 0);
  self.stackView.layoutMarginsRelativeArrangement = YES;
  [self.view addSubview:_stackView];

  [self addButton:@"Full Screen (Cold)" action:@selector(showFullScreenCold)];
}

- (void)showFullScreenCold {
  FlutterEngine *engine =
      [(AppDelegate *)[[UIApplication sharedApplication] delegate] engine];

  FullScreenViewController *flutterViewController =
      [[FullScreenViewController alloc] initWithEngine:engine
                                               nibName:nil
                                                bundle:nil];
  [self.navigationController
      pushViewController:flutterViewController
                animated:NO]; // Animating this is janky because of
                              // transitions with header on the native side.
                              // It's especially bad with a cold engine.
}

- (void)addButton:(NSString *)title action:(SEL)action {
  UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
  [button setTitle:title forState:UIControlStateNormal];
  [button addTarget:self
                action:action
      forControlEvents:UIControlEventTouchUpInside];
  [self.stackView addArrangedSubview:button];
}

@end