Commit 1deab0dd authored by Gauthier Ambard's avatar Gauthier Ambard Committed by Commit Bot

Modify the constraints priority in CleanToolbar

This CL changes the priority of the constraints in the Clean Toolbar to
ensure the width of the toolbar is respected.

Bug: 788663
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: Ic6e750a4f6227ec3571dd41336c696a14d9b3807
Reviewed-on: https://chromium-review.googlesource.com/800638Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#520573}
parent 0a4c8b94
...@@ -183,10 +183,18 @@ ...@@ -183,10 +183,18 @@
} }
- (void)setConstraints { - (void)setConstraints {
// Top anchor so Toolbar content never overlaps with the Status Bar.
NSLayoutYAxisAnchor* topAnchor;
if (@available(iOS 11, *)) {
topAnchor = self.view.safeAreaLayoutGuide.topAnchor;
} else {
topAnchor = self.topLayoutGuide.bottomAnchor;
}
self.view.translatesAutoresizingMaskIntoConstraints = NO; self.view.translatesAutoresizingMaskIntoConstraints = NO;
NSArray* constraints = @[ NSArray* constraints = @[
[self.stackView.topAnchor constraintEqualToAnchor:self.view.topAnchor [self.stackView.heightAnchor
constant:kVerticalMargin], constraintEqualToConstant:kToolbarHeight - 2 * kVerticalMargin],
[self.stackView.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor [self.stackView.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor
constant:-kVerticalMargin], constant:-kVerticalMargin],
[self.stackView.leadingAnchor [self.stackView.leadingAnchor
...@@ -211,27 +219,11 @@ ...@@ -211,27 +219,11 @@
constraintEqualToAnchor:self.locationBarContainer.trailingAnchor], constraintEqualToAnchor:self.locationBarContainer.trailingAnchor],
[self.bookmarkButton.trailingAnchor [self.bookmarkButton.trailingAnchor
constraintEqualToAnchor:self.voiceSearchButton.leadingAnchor], constraintEqualToAnchor:self.voiceSearchButton.leadingAnchor],
[self.view.bottomAnchor constraintEqualToAnchor:topAnchor
constant:kToolbarHeight],
]; ];
// Constraint so Toolbar stackview never overlaps with the Status Bar. [NSLayoutConstraint activateConstraints:constraints];
NSLayoutYAxisAnchor* topAnchor;
if (@available(iOS 11, *)) {
topAnchor = self.view.safeAreaLayoutGuide.topAnchor;
} else {
topAnchor = self.topLayoutGuide.topAnchor;
}
[self.stackView.topAnchor
constraintGreaterThanOrEqualToAnchor:topAnchor
constant:kVerticalMargin]
.active = YES;
[self.view.bottomAnchor constraintEqualToAnchor:topAnchor
constant:kToolbarHeight]
.active = YES;
// Set the constraints priority to UILayoutPriorityDefaultHigh so these are
// not broken when the views are hidden or the VC's view size is 0.
[self activateConstraints:constraints
withPriority:UILayoutPriorityDefaultHigh];
} }
#pragma mark - Components Setup #pragma mark - Components Setup
...@@ -351,10 +343,7 @@ ...@@ -351,10 +343,7 @@
self.buttonUpdater.forwardButton = self.forwardButton; self.buttonUpdater.forwardButton = self.forwardButton;
self.buttonUpdater.voiceSearchButton = self.voiceSearchButton; self.buttonUpdater.voiceSearchButton = self.voiceSearchButton;
// Set the button constraint priority to UILayoutPriorityDefaultHigh so [NSLayoutConstraint activateConstraints:buttonConstraints];
// these are not broken when being hidden by the StackView.
[self activateConstraints:buttonConstraints
withPriority:UILayoutPriorityDefaultHigh];
} }
- (void)setUpLocationBarContainer { - (void)setUpLocationBarContainer {
...@@ -557,15 +546,6 @@ ...@@ -557,15 +546,6 @@
[self.voiceSearchButton updateHiddenInCurrentSizeClass]; [self.voiceSearchButton updateHiddenInCurrentSizeClass];
} }
// Sets the priority for an array of constraints and activates them.
- (void)activateConstraints:(NSArray*)constraintsArray
withPriority:(UILayoutPriority)priority {
for (NSLayoutConstraint* constraint in constraintsArray) {
constraint.priority = priority;
}
[NSLayoutConstraint activateConstraints:constraintsArray];
}
#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