Commit 49199136 authored by Moe Ahmadi's avatar Moe Ahmadi Committed by Commit Bot

[AF][IOS] Takes secondary toolbar into account in credit card save infobar

Bug: 849433
Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: Ief1cca17a562786a6d838b9bdf27778918232dff
Reviewed-on: https://chromium-review.googlesource.com/1104969Reviewed-by: default avatarKurt Horimoto <kkhorimoto@chromium.org>
Commit-Queue: Moe Ahmadi <mahmadi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#568873}
parent 8906bfd6
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#import "ios/chrome/browser/ui/uikit_ui_util.h" #import "ios/chrome/browser/ui/uikit_ui_util.h"
#import "ios/chrome/browser/ui/util/constraints_ui_util.h" #import "ios/chrome/browser/ui/util/constraints_ui_util.h"
#import "ios/chrome/browser/ui/util/label_link_controller.h" #import "ios/chrome/browser/ui/util/label_link_controller.h"
#import "ios/chrome/browser/ui/util/named_guide.h"
#import "ios/third_party/material_components_ios/src/components/Buttons/src/MaterialButtons.h" #import "ios/third_party/material_components_ios/src/components/Buttons/src/MaterialButtons.h"
#import "ios/third_party/material_components_ios/src/components/Typography/src/MaterialTypography.h" #import "ios/third_party/material_components_ios/src/components/Typography/src/MaterialTypography.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
...@@ -82,6 +83,9 @@ UIFont* InfoBarMessageFont() { ...@@ -82,6 +83,9 @@ UIFont* InfoBarMessageFont() {
// Allows styled and clickable links in the legal message label. May be nil. // Allows styled and clickable links in the legal message label. May be nil.
@property(nonatomic, strong) LabelLinkController* legalMessageLinkController; @property(nonatomic, strong) LabelLinkController* legalMessageLinkController;
// Constraint used to add bottom margin to the view.
@property(nonatomic) NSLayoutConstraint* footerViewBottomAnchorConstraint;
// Creates and adds subviews. // Creates and adds subviews.
- (void)setupSubviews; - (void)setupSubviews;
...@@ -137,12 +141,14 @@ UIFont* InfoBarMessageFont() { ...@@ -137,12 +141,14 @@ UIFont* InfoBarMessageFont() {
@synthesize confirmButtonTitle = _confirmButtonTitle; @synthesize confirmButtonTitle = _confirmButtonTitle;
@synthesize messageLinkController = _messageLinkController; @synthesize messageLinkController = _messageLinkController;
@synthesize legalMessageLinkController = _legalMessageLinkController; @synthesize legalMessageLinkController = _legalMessageLinkController;
@synthesize footerViewBottomAnchorConstraint =
_footerViewBottomAnchorConstraint;
#pragma mark - UIView #pragma mark - UIView
- (void)willMoveToSuperview:(UIView*)newSuperview { - (void)willMoveToSuperview:(UIView*)newSuperview {
// Create and add subviews the first time this moves to a superview. // Create and add subviews the first time this moves to a superview.
if (newSuperview && self.subviews.count == 0) { if (newSuperview && !self.subviews.count) {
[self setupSubviews]; [self setupSubviews];
} }
} }
...@@ -150,6 +156,21 @@ UIFont* InfoBarMessageFont() { ...@@ -150,6 +156,21 @@ UIFont* InfoBarMessageFont() {
- (void)layoutSubviews { - (void)layoutSubviews {
[super layoutSubviews]; [super layoutSubviews];
// Return early if no subviews have been added yet.
if (!self.subviews.count)
return;
// Set a bottom margin equal to the height of the secondary toolbar, if any.
// Deduct the bottom safe area inset as it is already included in the height
// of the secondary toolbar.
NamedGuide* layoutGuide =
[NamedGuide guideWithName:kSecondaryToolbar view:self];
CGFloat bottomSafeAreaInset = SafeAreaInsetsForView(self).bottom;
self.footerViewBottomAnchorConstraint.constant =
layoutGuide.constrained
? layoutGuide.layoutFrame.size.height - bottomSafeAreaInset
: 0;
[self.sizingDelegate didSetInfoBarTargetHeight:CGRectGetHeight(self.frame)]; [self.sizingDelegate didSetInfoBarTargetHeight:CGRectGetHeight(self.frame)];
} }
...@@ -318,14 +339,16 @@ UIFont* InfoBarMessageFont() { ...@@ -318,14 +339,16 @@ UIFont* InfoBarMessageFont() {
footerView.layoutMargins = footerView.layoutMargins =
UIEdgeInsetsMake(kButtonsTopPadding, kPadding, kPadding, kPadding); UIEdgeInsetsMake(kButtonsTopPadding, kPadding, kPadding, kPadding);
[self addSubview:footerView]; [self addSubview:footerView];
self.footerViewBottomAnchorConstraint = [safeAreaLayoutGuide.bottomAnchor
constraintEqualToAnchor:footerView.bottomAnchor];
[NSLayoutConstraint activateConstraints:@[ [NSLayoutConstraint activateConstraints:@[
[safeAreaLayoutGuide.leadingAnchor [safeAreaLayoutGuide.leadingAnchor
constraintEqualToAnchor:footerView.leadingAnchor], constraintEqualToAnchor:footerView.leadingAnchor],
[safeAreaLayoutGuide.trailingAnchor [safeAreaLayoutGuide.trailingAnchor
constraintEqualToAnchor:footerView.trailingAnchor], constraintEqualToAnchor:footerView.trailingAnchor],
[contentView.bottomAnchor constraintEqualToAnchor:footerView.topAnchor], [contentView.bottomAnchor constraintEqualToAnchor:footerView.topAnchor],
[safeAreaLayoutGuide.bottomAnchor self.footerViewBottomAnchorConstraint
constraintEqualToAnchor:footerView.bottomAnchor],
]]; ]];
// Dummy view that expands so that the action buttons are aligned to the // Dummy view that expands so that the action buttons are aligned to the
......
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