mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00

* Update project.pbxproj files to say Flutter rather than Chromium Also, the templates now have an empty organization so that we don't cause people to give their apps a Flutter copyright. * Update the copyright notice checker to require a standard notice on all files * Update copyrights on Dart files. (This was a mechanical commit.) * Fix weird license headers on Dart files that deviate from our conventions; relicense Shrine. Some were already marked "The Flutter Authors", not clear why. Their dates have been normalized. Some were missing the blank line after the license. Some were randomly different in trivial ways for no apparent reason (e.g. missing the trailing period). * Clean up the copyrights in non-Dart files. (Manual edits.) Also, make sure templates don't have copyrights. * Fix some more ORGANIZATIONNAMEs
145 lines
5.1 KiB
Objective-C
145 lines
5.1 KiB
Objective-C
// 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 "NativeViewController.h"
|
|
|
|
@interface NativeViewController ()
|
|
|
|
@end
|
|
|
|
@implementation NativeViewController {
|
|
int _counter;
|
|
UILabel* _incrementLabel;
|
|
}
|
|
|
|
- (instancetype)initWithDelegate:(id<NativeViewControllerDelegate>)delegate {
|
|
self = [super initWithNibName:nil bundle:nil];
|
|
if (self) {
|
|
self.delegate = delegate;
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (instancetype)initWithCoder:(NSCoder *)aDecoder {
|
|
return [self initWithDelegate:nil];
|
|
}
|
|
|
|
-(instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
|
|
return [self initWithDelegate:nil];
|
|
}
|
|
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
|
|
self.title = @"Native iOS View";
|
|
self.view.backgroundColor = UIColor.lightGrayColor;
|
|
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc]
|
|
initWithTitle:@"Back"
|
|
style:UIBarButtonItemStylePlain
|
|
target:nil
|
|
action:nil];
|
|
|
|
_incrementLabel = [self addIncrementLabel];
|
|
UIStackView* footer = [self addFooter];
|
|
|
|
_incrementLabel.translatesAutoresizingMaskIntoConstraints = false;
|
|
footer.translatesAutoresizingMaskIntoConstraints = false;
|
|
UILayoutGuide* marginsGuide = self.view.layoutMarginsGuide;
|
|
NSMutableArray* array = [[NSMutableArray alloc] init];
|
|
[array addObject:[_incrementLabel.centerXAnchor
|
|
constraintEqualToAnchor:self.view.centerXAnchor]];
|
|
[array addObject:[_incrementLabel.centerYAnchor
|
|
constraintEqualToAnchor:self.view.centerYAnchor]];
|
|
[array addObject:[footer.centerXAnchor
|
|
constraintEqualToAnchor:self.view.centerXAnchor]];
|
|
[array addObject:[footer.widthAnchor
|
|
constraintEqualToAnchor:marginsGuide.widthAnchor]];
|
|
[array addObject:[footer.bottomAnchor
|
|
constraintEqualToAnchor:marginsGuide.bottomAnchor]];
|
|
|
|
[NSLayoutConstraint activateConstraints:array];
|
|
[self updateIncrementLabel];
|
|
}
|
|
|
|
/// Adds a label to the view that will contain the counter text.
|
|
///
|
|
/// - Returns: The new label.
|
|
-(UILabel*) addIncrementLabel {
|
|
UILabel* incrementLabel = [[UILabel alloc] init];
|
|
incrementLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
|
|
incrementLabel.textColor = UIColor.blackColor;
|
|
incrementLabel.accessibilityIdentifier = @"counter_on_iOS";
|
|
[self.view addSubview:incrementLabel];
|
|
return incrementLabel;
|
|
}
|
|
|
|
/// Adds a horizontal stack to the view, anchored to the bottom.
|
|
///
|
|
/// - Returns: The new stack.
|
|
-(UIStackView*) addFooter {
|
|
UILabel* mainLabel = [self createMainLabel];
|
|
UIButton* incrementButton = [self createIncrementButton];
|
|
UIStackView* stackView = [[UIStackView alloc] initWithFrame:self.view.frame];
|
|
[stackView addArrangedSubview:mainLabel];
|
|
[stackView addArrangedSubview:incrementButton];
|
|
stackView.axis = UILayoutConstraintAxisHorizontal;
|
|
stackView.alignment = UIStackViewAlignmentBottom;
|
|
[self.view addSubview:stackView];
|
|
return stackView;
|
|
}
|
|
|
|
/// Creates a label identifying this view. Does not add it to the view.
|
|
///
|
|
/// - Returns: The new label.
|
|
-(UILabel*) createMainLabel {
|
|
UILabel* mainLabel = [[UILabel alloc] init];
|
|
mainLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleTitle1];
|
|
mainLabel.textColor = UIColor.blackColor;
|
|
mainLabel.text = @"Native";
|
|
return mainLabel;
|
|
}
|
|
|
|
/// Creates a button that will increment a counter. Does not add it to the view.
|
|
///
|
|
/// - Returns: The new button.
|
|
-(UIButton*) createIncrementButton {
|
|
UIButton *incrementButton = [UIButton buttonWithType:UIButtonTypeSystem];
|
|
incrementButton.titleLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleTitle2];
|
|
[incrementButton setTitle:@"Add" forState:UIControlStateNormal];
|
|
incrementButton.accessibilityLabel = @"Increment via iOS";
|
|
incrementButton.layer.cornerRadius = 15.0;
|
|
[incrementButton addTarget:self
|
|
action:@selector(handleIncrement:)
|
|
forControlEvents:UIControlEventTouchUpInside];
|
|
return incrementButton;
|
|
}
|
|
|
|
// MARK: - Actions
|
|
|
|
/// Action triggered from tapping on the increment button. Triggers a corresponding event in the
|
|
/// delegate if one is available, otherwise increments our internal counter.
|
|
-(void) handleIncrement:(UIButton*)sender {
|
|
if (self.delegate) {
|
|
[self.delegate didTapIncrementButton];
|
|
} else {
|
|
[self didReceiveIncrement];
|
|
}
|
|
}
|
|
|
|
/// Updates the increment label text to match the increment counter.
|
|
-(void) updateIncrementLabel {
|
|
_incrementLabel.text = [NSString
|
|
stringWithFormat:@"%@ tapped %d %@.",
|
|
self.delegate == nil ? @"Button" : @"Flutter button",
|
|
_counter, _counter == 1 ? @"time" : @"times"];
|
|
}
|
|
|
|
/// Increments our internal counter and updates the view.
|
|
-(void) didReceiveIncrement {
|
|
_counter += 1;
|
|
[self updateIncrementLabel];
|
|
}
|
|
|
|
@end
|