Commit 6a4770b1 authored by sczs's avatar sczs Committed by Commit Bot

[ios] Fixes Discover Feed header alignment issues.

On iPhone the header container view will be hardcoded to
kFeedCardIPhoneWidth in order to match the card width.

Before:
https://drive.google.com/file/d/1IAB3wM6tYx_DhcT3akytx11wJUhofOxf/view?usp=sharing

After:
https://drive.google.com/file/d/1hz5Qq0vrfu6VbUNu1IgDHOH_lBfeqwNv/view?usp=sharing

Bug: 1124870, 1085419
Change-Id: I7a34f87ae227791d25cdc69be5b6137359416ea8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2392938
Commit-Queue: Sergio Collazos <sczs@chromium.org>
Reviewed-by: default avatarGanggui Tang <gogerald@chromium.org>
Cr-Commit-Position: refs/heads/master@{#805126}
parent c775d206
...@@ -18,8 +18,12 @@ ...@@ -18,8 +18,12 @@
#endif #endif
namespace { namespace {
// Leading and trailing margin for label and button. // Leading margin for title label. Its used to align with the Card leading
const CGFloat kHeaderHorizontalMargin = 20; // margin.
const CGFloat kTitleHorizontalMargin = 19;
// Trailing margin for menu button. Its used to align with the Card trailing
// margin.
const CGFloat kMenuButtonHorizontalMargin = 14;
// Font size for label text in header. // Font size for label text in header.
const CGFloat kDiscoverFeedTitleFontSize = 16; const CGFloat kDiscoverFeedTitleFontSize = 16;
// Insets for header menu button. // Insets for header menu button.
...@@ -27,6 +31,9 @@ const CGFloat kHeaderMenuButtonInsetTopAndBottom = 2; ...@@ -27,6 +31,9 @@ const CGFloat kHeaderMenuButtonInsetTopAndBottom = 2;
const CGFloat kHeaderMenuButtonInsetSides = 2; const CGFloat kHeaderMenuButtonInsetSides = 2;
// Duration for the header animation when Discover feed visibility changes. // Duration for the header animation when Discover feed visibility changes.
const CGFloat kHeaderChangeAnimationDuration = 0.3; const CGFloat kHeaderChangeAnimationDuration = 0.3;
// Max width for cards in iPhone, this is used to align the header to the card
// margins. This is currently hard coded by Discover.
const CGFloat kFeedCardIPhoneWidth = 375;
} }
#pragma mark - ContentSuggestionsDiscoverHeaderItem #pragma mark - ContentSuggestionsDiscoverHeaderItem
...@@ -99,19 +106,49 @@ const CGFloat kHeaderChangeAnimationDuration = 0.3; ...@@ -99,19 +106,49 @@ const CGFloat kHeaderChangeAnimationDuration = 0.3;
kHeaderMenuButtonInsetTopAndBottom, kHeaderMenuButtonInsetSides, kHeaderMenuButtonInsetTopAndBottom, kHeaderMenuButtonInsetSides,
kHeaderMenuButtonInsetTopAndBottom, kHeaderMenuButtonInsetSides); kHeaderMenuButtonInsetTopAndBottom, kHeaderMenuButtonInsetSides);
[self.contentView addSubview:_menuButton]; UIView* container = [[UIView alloc] init];
[self.contentView addSubview:_titleLabel]; container.translatesAutoresizingMaskIntoConstraints = NO;
[container addSubview:_menuButton];
[NSLayoutConstraint activateConstraints:@[ [container addSubview:_titleLabel];
[self.contentView addSubview:container];
NSMutableArray* constraintsArray = [[NSMutableArray alloc] init];
[constraintsArray addObjectsFromArray:@[
[container.topAnchor constraintEqualToAnchor:self.contentView.topAnchor],
[container.bottomAnchor
constraintEqualToAnchor:self.contentView.bottomAnchor],
[_titleLabel.leadingAnchor [_titleLabel.leadingAnchor
constraintEqualToAnchor:self.contentView.leadingAnchor constraintEqualToAnchor:container.leadingAnchor
constant:kHeaderHorizontalMargin], constant:kTitleHorizontalMargin],
[_titleLabel.trailingAnchor [_titleLabel.trailingAnchor
constraintLessThanOrEqualToAnchor:_menuButton.leadingAnchor], constraintLessThanOrEqualToAnchor:_menuButton.leadingAnchor],
[_menuButton.trailingAnchor [_menuButton.trailingAnchor
constraintEqualToAnchor:self.contentView.trailingAnchor constraintEqualToAnchor:container.trailingAnchor
constant:-kHeaderHorizontalMargin], constant:-kMenuButtonHorizontalMargin],
[_titleLabel.centerYAnchor
constraintEqualToAnchor:container.centerYAnchor],
[_menuButton.centerYAnchor
constraintEqualToAnchor:container.centerYAnchor],
]]; ]];
// TODO(b/167703449): Once the card width and padding is exposed we should
// stop hardcodnig this for iPhone and use those values instead.
if (IsIPadIdiom()) {
[constraintsArray addObjectsFromArray:@[
[container.leadingAnchor
constraintEqualToAnchor:self.contentView.leadingAnchor],
[container.trailingAnchor
constraintEqualToAnchor:self.contentView.trailingAnchor],
]];
} else {
[constraintsArray addObjectsFromArray:@[
[container.centerXAnchor
constraintEqualToAnchor:self.contentView.centerXAnchor],
[container.widthAnchor constraintEqualToConstant:kFeedCardIPhoneWidth],
]];
}
[NSLayoutConstraint activateConstraints:constraintsArray];
} }
return self; return self;
} }
......
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