Commit 89a796a9 authored by sczs's avatar sczs Committed by Commit Bot

[ios] Uses StackView for CleanToolbar locationBarContainer contents.

Moves locationBarContainterView contents into a StackView.
This way we don't need to juggle constraints related to iPad only Buttons
,Expanded toolbar buttons or locationBarView conditional constraints.


Bug: 791203
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: If04b58731c3042e450d0e2516917f89afae4698f
Reviewed-on: https://chromium-review.googlesource.com/804940Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Commit-Queue: Sergio Collazos <sczs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#521627}
parent 5794352d
...@@ -45,6 +45,7 @@ ...@@ -45,6 +45,7 @@
@property(nonatomic, strong) ToolbarButton* contractButton; @property(nonatomic, strong) ToolbarButton* contractButton;
@property(nonatomic, assign) BOOL voiceSearchEnabled; @property(nonatomic, assign) BOOL voiceSearchEnabled;
@property(nonatomic, strong) MDCProgressView* progressBar; @property(nonatomic, strong) MDCProgressView* progressBar;
@property(nonatomic, strong) UIStackView* locationBarContainerStackView;
// Background view, used to display the incognito NTP background color on the // Background view, used to display the incognito NTP background color on the
// toolbar. // toolbar.
@property(nonatomic, strong) UIView* backgroundView; @property(nonatomic, strong) UIView* backgroundView;
...@@ -85,6 +86,7 @@ ...@@ -85,6 +86,7 @@
@synthesize contractButton = _contractButton; @synthesize contractButton = _contractButton;
@synthesize voiceSearchEnabled = _voiceSearchEnabled; @synthesize voiceSearchEnabled = _voiceSearchEnabled;
@synthesize progressBar = _progressBar; @synthesize progressBar = _progressBar;
@synthesize locationBarContainerStackView = _locationBarContainerStackView;
@synthesize expandedToolbarConstraints = _expandedToolbarConstraints; @synthesize expandedToolbarConstraints = _expandedToolbarConstraints;
@synthesize topSafeAnchor = _topSafeAnchor; @synthesize topSafeAnchor = _topSafeAnchor;
@synthesize regularToolbarConstraints = _regularToolbarConstraints; @synthesize regularToolbarConstraints = _regularToolbarConstraints;
...@@ -188,7 +190,7 @@ ...@@ -188,7 +190,7 @@
[self.buttonFactory.toolbarConfiguration backgroundColor]; [self.buttonFactory.toolbarConfiguration backgroundColor];
[self setUpToolbarStackView]; [self setUpToolbarStackView];
[self setUpToolbarContainerView]; [self setUpLocationBarContainerView];
[self.view addSubview:self.stackView]; [self.view addSubview:self.stackView];
[self.view addSubview:self.progressBar]; [self.view addSubview:self.progressBar];
[self setConstraints]; [self setConstraints];
...@@ -213,42 +215,27 @@ ...@@ -213,42 +215,27 @@
self.stackView.distribution = UIStackViewDistributionFill; self.stackView.distribution = UIStackViewDistributionFill;
} }
// Sets up the LocationContainerView. This contains the locationBarView, and // Sets up the LocationContainerView. Which contains a StackView containing the
// other buttons like Voice Search, Bookmarks and Contract Toolbar. // locationBarView, and other buttons like Voice Search, Bookmarks and Contract
- (void)setUpToolbarContainerView { // Toolbar.
if (self.locationBarView) { - (void)setUpLocationBarContainerView {
[self.locationBarContainer addSubview:self.locationBarView]; self.locationBarContainerStackView =
[[UIStackView alloc] initWithArrangedSubviews:@[ self.locationBarView ]];
// Bookmarks and Voice Search buttons will only be part of the Toolbar on self.locationBarContainerStackView.translatesAutoresizingMaskIntoConstraints =
// iPad. On the other hand the contract button is only needed on non iPad NO;
// devices, since iPad doesn't animate, thus it doesn't need to contract. self.locationBarContainerStackView.spacing = kStackViewSpacing;
if (IsIPadIdiom()) { self.locationBarContainerStackView.distribution = UIStackViewDistributionFill;
[self.locationBarContainer addSubview:self.bookmarkButton]; // Bookmarks and Voice Search buttons will only be part of the Toolbar on
[self.locationBarContainer addSubview:self.voiceSearchButton]; // iPad. On the other hand the contract button is only needed on non iPad
} else { // devices, since iPad doesn't animate, thus it doesn't need to contract.
[self.locationBarContainer addSubview:self.contractButton]; if (IsIPadIdiom()) {
} [self.locationBarContainerStackView addArrangedSubview:self.bookmarkButton];
[self.locationBarContainerStackView
// LocationBarView constraints. addArrangedSubview:self.voiceSearchButton];
NSLayoutConstraint* locationBarViewTrailingConstraint = } else {
[self.locationBarView.trailingAnchor [self.locationBarContainerStackView addArrangedSubview:self.contractButton];
constraintEqualToAnchor:self.locationBarContainer.trailingAnchor];
NSLayoutConstraint* locationBarViewTopConstraint =
[self.locationBarView.topAnchor
constraintEqualToAnchor:self.locationBarContainer.topAnchor];
[self.regularToolbarConstraints addObjectsFromArray:@[
locationBarViewTopConstraint, locationBarViewTrailingConstraint
]];
NSArray* locationBarViewConstraints = @[
[self.locationBarView.leadingAnchor
constraintEqualToAnchor:self.locationBarContainer.leadingAnchor],
[self.locationBarView.bottomAnchor
constraintEqualToAnchor:self.locationBarContainer.bottomAnchor],
locationBarViewTrailingConstraint,
locationBarViewTopConstraint,
];
[NSLayoutConstraint activateConstraints:locationBarViewConstraints];
} }
[self.locationBarContainer addSubview:self.locationBarContainerStackView];
} }
- (void)setConstraints { - (void)setConstraints {
...@@ -270,7 +257,7 @@ ...@@ -270,7 +257,7 @@
]; ];
[NSLayoutConstraint activateConstraints:progressBarConstraints]; [NSLayoutConstraint activateConstraints:progressBarConstraints];
// StackView constraints. // StackView constraints. The main Toolbar StackView.
NSArray* stackViewConstraints = @[ NSArray* stackViewConstraints = @[
[self.stackView.heightAnchor [self.stackView.heightAnchor
constraintEqualToConstant:kToolbarHeight - 2 * kVerticalMargin], constraintEqualToConstant:kToolbarHeight - 2 * kVerticalMargin],
...@@ -286,34 +273,23 @@ ...@@ -286,34 +273,23 @@
[self.regularToolbarConstraints addObjectsFromArray:stackViewConstraints]; [self.regularToolbarConstraints addObjectsFromArray:stackViewConstraints];
[NSLayoutConstraint activateConstraints:stackViewConstraints]; [NSLayoutConstraint activateConstraints:stackViewConstraints];
// LocationBarContainer Buttons constraints. // LocationBarStackView constraints. The StackView inside the
NSArray* locationBarButtonConstraints; // LocationBarContainer View.
if (IsIPadIdiom()) { NSLayoutConstraint* locationBarContainerStackViewTopConstraint =
locationBarButtonConstraints = @[ [self.locationBarContainerStackView.topAnchor
[self.bookmarkButton.centerYAnchor constraintEqualToAnchor:self.locationBarContainer.topAnchor];
constraintEqualToAnchor:self.locationBarContainer.centerYAnchor], NSArray* locationBarViewStackViewConstraints = @[
[self.voiceSearchButton.centerYAnchor [self.locationBarContainerStackView.bottomAnchor
constraintEqualToAnchor:self.locationBarContainer.centerYAnchor], constraintEqualToAnchor:self.locationBarContainer.bottomAnchor],
[self.voiceSearchButton.trailingAnchor [self.locationBarContainerStackView.leadingAnchor
constraintEqualToAnchor:self.locationBarContainer.trailingAnchor], constraintEqualToAnchor:self.locationBarContainer.leadingAnchor],
[self.bookmarkButton.trailingAnchor [self.locationBarContainerStackView.trailingAnchor
constraintEqualToAnchor:self.voiceSearchButton.leadingAnchor], constraintEqualToAnchor:self.locationBarContainer.trailingAnchor],
]; locationBarContainerStackViewTopConstraint,
} else { ];
NSLayoutConstraint* contractButtonTrailingConstraint = [self.regularToolbarConstraints
[self.contractButton.trailingAnchor addObject:locationBarContainerStackViewTopConstraint];
constraintEqualToAnchor:self.locationBarContainer.trailingAnchor [NSLayoutConstraint activateConstraints:locationBarViewStackViewConstraints];
constant:-2 * kTrailingMargin];
[self.regularToolbarConstraints addObject:contractButtonTrailingConstraint];
locationBarButtonConstraints = @[
[self.contractButton.topAnchor constraintEqualToAnchor:self.topSafeAnchor
constant:kVerticalMargin],
[self.contractButton.bottomAnchor
constraintEqualToAnchor:self.locationBarContainer.bottomAnchor],
contractButtonTrailingConstraint,
];
}
[NSLayoutConstraint activateConstraints:locationBarButtonConstraints];
} }
#pragma mark - Components Setup #pragma mark - Components Setup
...@@ -446,7 +422,6 @@ ...@@ -446,7 +422,6 @@
self.buttonUpdater.forwardButton = self.forwardButton; self.buttonUpdater.forwardButton = self.forwardButton;
self.buttonUpdater.voiceSearchButton = self.voiceSearchButton; self.buttonUpdater.voiceSearchButton = self.voiceSearchButton;
[self.regularToolbarConstraints addObjectsFromArray:buttonConstraints];
[NSLayoutConstraint activateConstraints:buttonConstraints]; [NSLayoutConstraint activateConstraints:buttonConstraints];
} }
...@@ -504,20 +479,6 @@ ...@@ -504,20 +479,6 @@
[viewController didMoveToParentViewController:self]; [viewController didMoveToParentViewController:self];
} }
- (void)setLocationBarView:(UIView*)view {
if (_locationBarView == view) {
return;
}
view.translatesAutoresizingMaskIntoConstraints = NO;
if ([self isViewLoaded]) {
[_locationBarView removeFromSuperview];
[self.locationBarContainer addSubview:view];
AddSameConstraints(self.locationBarContainer, view);
}
_locationBarView = view;
}
#pragma mark - Trait Collection Changes #pragma mark - Trait Collection Changes
- (void)traitCollectionDidChange:(UITraitCollection*)previousTraitCollection { - (void)traitCollectionDidChange:(UITraitCollection*)previousTraitCollection {
...@@ -681,19 +642,35 @@ ...@@ -681,19 +642,35 @@
constraintEqualToAnchor:self.view.leadingAnchor], constraintEqualToAnchor:self.view.leadingAnchor],
[self.locationBarContainer.trailingAnchor [self.locationBarContainer.trailingAnchor
constraintEqualToAnchor:self.view.trailingAnchor], constraintEqualToAnchor:self.view.trailingAnchor],
[self.locationBarView.topAnchor constraintEqualToAnchor:self.topSafeAnchor [self.locationBarContainerStackView.topAnchor
constant:kVerticalMargin], constraintEqualToAnchor:self.topSafeAnchor
[self.locationBarView.trailingAnchor constant:kVerticalMargin],
constraintEqualToAnchor:self.contractButton.leadingAnchor
constant:-kTrailingMargin],
[self.contractButton.trailingAnchor
constraintEqualToAnchor:self.locationBarContainer.trailingAnchor
constant:-kTrailingMargin],
]; ];
} }
return _expandedToolbarConstraints; return _expandedToolbarConstraints;
} }
- (UIView*)locationBarView {
if (!_locationBarView) {
_locationBarView = [[UIView alloc] initWithFrame:CGRectZero];
_locationBarView.translatesAutoresizingMaskIntoConstraints = NO;
[_locationBarView
setContentHuggingPriority:UILayoutPriorityDefaultLow
forAxis:UILayoutConstraintAxisHorizontal];
}
return _locationBarView;
}
- (void)setLocationBarView:(UIView*)view {
if (_locationBarView == view) {
return;
}
view.translatesAutoresizingMaskIntoConstraints = NO;
[view setContentHuggingPriority:UILayoutPriorityDefaultLow
forAxis:UILayoutConstraintAxisHorizontal];
_locationBarView = view;
}
#pragma mark - Private #pragma mark - Private
// Sets the progress of the progressBar to 1 then hides it. // Sets the progress of the progressBar to 1 then hides it.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment