Commit 8d88e198 authored by Moe Ahmadi's avatar Moe Ahmadi Committed by Commit Bot

[IOS][AF] Fixes save card infobar crash on iPhone X

Currently to fix a layout issue in the save card infobar in iPhone X,
|-setFrame:| is overridden to call |-layoutIfNeeded| in order to update the
layout of subviews immediately. |-setFrame:| won't be required to be
overridden if the logic to adjust the layout constraints is moved from
|-sizeThatFits:| to |-layoutSubviews|. The existing logic is likely to be
wrong as the layout should not get updated in calls to |-sizeThatFits|.

This is likely the root cause for the crash in crbug.com/892144

Bug: 862688,892144
Cq-Include-Trybots: luci.chromium.try:ios-simulator-cronet;luci.chromium.try:ios-simulator-full-configs
Change-Id: Iee81a30afa14581f304813512b84b86fc5c6feb5
Reviewed-on: https://chromium-review.googlesource.com/c/1262087
Commit-Queue: Moe Ahmadi <mahmadi@chromium.org>
Reviewed-by: default avatarOlivier Robin <olivierrobin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#598784}
parent 3726b217
......@@ -155,33 +155,23 @@ UIFont* InfoBarMessageFont() {
}
- (void)layoutSubviews {
[super layoutSubviews];
[self.sizingDelegate didSetInfoBarTargetHeight:CGRectGetHeight(self.frame)];
}
- (void)setFrame:(CGRect)frame {
[super setFrame:frame];
// Updates layout of subviews immediately, if layout updates are pending,
// rather than waiting for the next update cycle. Otherwise, the layout breaks
// on iPhone X.
// TODO(crbug.com/862688): Investigate why this is happening.
[self layoutIfNeeded];
}
- (CGSize)sizeThatFits:(CGSize)size {
// 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.
// TODO(crbug.com/894449): This won't update the infobar's position after the
// secondary toolbar reappears. Consider adding a constraint to the
// |layoutGuide| in |didMoveToSuperview|.
NamedGuide* layoutGuide =
[NamedGuide guideWithName:kSecondaryToolbarGuide view:self];
CGFloat bottomSafeAreaInset = SafeAreaInsetsForView(self).bottom;
self.footerViewBottomAnchorConstraint.constant =
layoutGuide.constrained
? layoutGuide.layoutFrame.size.height - bottomSafeAreaInset
: 0;
layoutGuide.layoutFrame.size.height;
[super layoutSubviews];
[self.sizingDelegate didSetInfoBarTargetHeight:CGRectGetHeight(self.frame)];
}
- (CGSize)sizeThatFits:(CGSize)size {
CGSize computedSize = [self systemLayoutSizeFittingSize:size];
return CGSizeMake(size.width, computedSize.height);
}
......@@ -326,8 +316,8 @@ UIFont* InfoBarMessageFont() {
UIEdgeInsetsMake(kButtonsTopPadding, kPadding, kPadding, kPadding);
[self addSubview:footerView];
self.footerViewBottomAnchorConstraint = [safeAreaLayoutGuide.bottomAnchor
constraintEqualToAnchor:footerView.bottomAnchor];
self.footerViewBottomAnchorConstraint =
[self.bottomAnchor constraintEqualToAnchor:footerView.bottomAnchor];
[NSLayoutConstraint activateConstraints:@[
[safeAreaLayoutGuide.leadingAnchor
constraintEqualToAnchor:footerView.leadingAnchor],
......
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