Commit 9c25fd77 authored by Eugene But's avatar Eugene But Committed by Commit Bot

Fixed status label width for in-progress download.

Previously status label was resized by calling sizeToFit. sizeToFit does
not play well with autolayout and overrides the existing constraints.

This CL creates statusLabelTrailingConstraint which anchors the label
to close button or to action button (when download is not in progress
and action button is visible).

The test was updated to force the view load, so setting up constrains
do not fail in the test.

Bug: 827641
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: I2d84d6ba041d85bfd7cee9290c76c56a8f68c8b8
Reviewed-on: https://chromium-review.googlesource.com/988750
Commit-Queue: Eugene But <eugenebut@chromium.org>
Reviewed-by: default avataredchin <edchin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#547878}
parent aa4f1763
...@@ -96,6 +96,10 @@ NSString* GetSizeString(long long size_in_bytes) { ...@@ -96,6 +96,10 @@ NSString* GetSizeString(long long size_in_bytes) {
@property(nonatomic) @property(nonatomic)
NSLayoutConstraint* installDriveControlsRowTrailingConstraint; NSLayoutConstraint* installDriveControlsRowTrailingConstraint;
// Represents constraint for self.view.statusLabel, which is either anchored to
// self.closeButton or to self.actionButton (when visible).
@property(nonatomic) NSLayoutConstraint* statusLabelTrailingConstraint;
@end @end
@implementation DownloadManagerViewController @implementation DownloadManagerViewController
...@@ -115,6 +119,7 @@ NSString* GetSizeString(long long size_in_bytes) { ...@@ -115,6 +119,7 @@ NSString* GetSizeString(long long size_in_bytes) {
_installDriveControlsRowLeadingConstraint; _installDriveControlsRowLeadingConstraint;
@synthesize installDriveControlsRowTrailingConstraint = @synthesize installDriveControlsRowTrailingConstraint =
_installDriveControlsRowTrailingConstraint; _installDriveControlsRowTrailingConstraint;
@synthesize statusLabelTrailingConstraint = _statusLabelTrailingConstraint;
#pragma mark - UIViewController overrides #pragma mark - UIViewController overrides
...@@ -227,10 +232,8 @@ NSString* GetSizeString(long long size_in_bytes) { ...@@ -227,10 +232,8 @@ NSString* GetSizeString(long long size_in_bytes) {
constraintEqualToAnchor:downloadRow.centerYAnchor], constraintEqualToAnchor:downloadRow.centerYAnchor],
[statusLabel.leadingAnchor constraintEqualToAnchor:stateIcon.trailingAnchor [statusLabel.leadingAnchor constraintEqualToAnchor:stateIcon.trailingAnchor
constant:kElementMargin], constant:kElementMargin],
[statusLabel.trailingAnchor
constraintLessThanOrEqualToAnchor:actionButton.leadingAnchor
constant:-kElementMargin],
]]; ]];
[self updateStatusLabelTrailingConstraint];
// action button constraints. // action button constraints.
[NSLayoutConstraint activateConstraints:@[ [NSLayoutConstraint activateConstraints:@[
...@@ -336,6 +339,7 @@ NSString* GetSizeString(long long size_in_bytes) { ...@@ -336,6 +339,7 @@ NSString* GetSizeString(long long size_in_bytes) {
[self updateStatusLabel]; [self updateStatusLabel];
[self updateActionButton]; [self updateActionButton];
[self updateProgressView]; [self updateProgressView];
[self updateStatusLabelTrailingConstraint];
} }
} }
...@@ -613,6 +617,28 @@ NSString* GetSizeString(long long size_in_bytes) { ...@@ -613,6 +617,28 @@ NSString* GetSizeString(long long size_in_bytes) {
self.installDriveControlsRowTrailingConstraint.constant = -constant; self.installDriveControlsRowTrailingConstraint.constant = -constant;
} }
// Anchors self.view.statusLabel to self.closeButton or to self.actionButton
// (when download is not in progress and action button is visible).
- (void)updateStatusLabelTrailingConstraint {
if (!self.viewLoaded || !self.view.superview) {
// Constraints can not be set if UI elements do not have a common view.
// This method will be called again when self.view is added to superview.
return;
}
self.statusLabelTrailingConstraint.active = NO;
UIView* secondAnchorElement = _state == kDownloadManagerStateInProgress
? self.closeButton
: self.actionButton;
self.statusLabelTrailingConstraint = [self.statusLabel.trailingAnchor
constraintEqualToAnchor:secondAnchorElement.leadingAnchor
constant:-kElementMargin];
self.statusLabelTrailingConstraint.active = YES;
}
// Updates state icon depending. // Updates state icon depending.
- (void)updateStateIcon { - (void)updateStateIcon {
[self.stateIcon setState:_state animated:YES]; [self.stateIcon setState:_state animated:YES];
...@@ -654,7 +680,6 @@ NSString* GetSizeString(long long size_in_bytes) { ...@@ -654,7 +680,6 @@ NSString* GetSizeString(long long size_in_bytes) {
} }
self.statusLabel.text = statusText; self.statusLabel.text = statusText;
[self.statusLabel sizeToFit];
} }
// Updates title and hidden state for action button depending on |state|. // Updates title and hidden state for action button depending on |state|.
......
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