Commit c15023d8 authored by Jérôme Lebel's avatar Jérôme Lebel Committed by Commit Bot

[iOS] Moving up buttons in sign-in and first-run views inside the safe area

The sign-in/firstrun buttons is moved inside the safe area (related to
the iPhone X like).
The patch has been tested with rotation.

  ** Before **
 - First run:
https://drive.google.com/open?id=1Ig3SCaKTeCZkf3KfCnRHfPpAA9mZdLSB
 - Sign-in with first run:
https://drive.google.com/open?id=1arrBQ44c9kj7_R8xIykEfxLcJZjfTlZT
 - Sign-in portrait:
https://drive.google.com/open?id=17UlTFkc416iU72LeMFgg9PoEG-gRVXCc
 - Sign-in landscape:
https://drive.google.com/open?id=1pqC00vqx6AtHDJHXSxc_0yZ2Qr_1O66l

  ** After **
 - First run:
https://drive.google.com/open?id=1c6rJtftJInGlNgLTj19jmsbzgRf3hQZv
 - Sign-in with first run:
https://drive.google.com/open?id=19GRHlX6HdyO5HnPkVDzKCbxfcwSsyFyn
 - Sign-in portrait:
https://drive.google.com/open?id=187VDZsNLMzI50q4RLi2eAaLsXs7aZ6Zm
 - Sign-in landscape:
https://drive.google.com/open?id=1Q_WCYA8-JMI5cRtshLKAjFIXk9vLaNEn

Bug: 864225
Cq-Include-Trybots: luci.chromium.try:ios-simulator-cronet;luci.chromium.try:ios-simulator-full-configs
Change-Id: I33478974bbb0de2180ab842eb07321dcf5140ed0
Reviewed-on: https://chromium-review.googlesource.com/c/1286659Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Reviewed-by: default avatarKurt Horimoto <kkhorimoto@chromium.org>
Commit-Queue: Jérôme Lebel <jlebel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#601082}
parent 394e4873
......@@ -69,11 +69,6 @@ namespace {
// Default animation duration.
const CGFloat kAnimationDuration = 0.5f;
enum LayoutType {
LAYOUT_REGULAR,
LAYOUT_COMPACT,
};
// Minimum duration of the pending state in milliseconds.
const int64_t kMinimunPendingStateDurationMs = 300;
......@@ -381,6 +376,38 @@ enum AuthenticationState {
_embeddedView = nil;
}
- (void)updateLayout {
AuthenticationViewConstants constants;
if ([self.traitCollection horizontalSizeClass] ==
UIUserInterfaceSizeClassRegular) {
constants = kRegularConstants;
} else {
constants = kCompactConstants;
}
[self layoutButtons:constants];
CGSize viewSize = self.view.bounds.size;
CGFloat collectionViewHeight =
_primaryButton.frame.origin.y - constants.ButtonTopPadding;
CGRect collectionViewFrame =
CGRectMake(0, 0, viewSize.width, collectionViewHeight);
[_embeddedView setFrame:collectionViewFrame];
// Layout the gradient view right above the buttons.
CGFloat gradientOriginY = _primaryButton.frame.origin.y -
constants.ButtonTopPadding -
constants.GradientHeight;
[_gradientView setFrame:CGRectMake(0, gradientOriginY, viewSize.width,
constants.GradientHeight)];
[_gradientLayer setFrame:[_gradientView bounds]];
// Layout the activity indicator in the center of the view.
CGRect bounds = self.view.bounds;
[_activityIndicator
setCenter:CGPointMake(CGRectGetMidX(bounds), CGRectGetMidY(bounds))];
}
#pragma mark - Accessibility
- (BOOL)accessibilityPerformEscape {
......@@ -883,6 +910,11 @@ enum AuthenticationState {
}
}
- (void)viewSafeAreaInsetsDidChange {
[super viewSafeAreaInsetsDidChange];
[self updateLayout];
}
#pragma mark - Events
- (void)onPrimaryButtonPressed:(id)sender {
......@@ -990,38 +1022,7 @@ enum AuthenticationState {
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
AuthenticationViewConstants constants;
if ([self.traitCollection horizontalSizeClass] ==
UIUserInterfaceSizeClassRegular) {
constants = kRegularConstants;
} else {
constants = kCompactConstants;
}
[self layoutButtons:constants];
CGSize viewSize = self.view.bounds.size;
CGFloat collectionViewHeight =
viewSize.height - _primaryButton.frame.size.height -
constants.ButtonBottomPadding - constants.ButtonTopPadding;
CGRect collectionViewFrame =
CGRectMake(0, 0, viewSize.width, collectionViewHeight);
[_embeddedView setFrame:collectionViewFrame];
// Layout the gradient view right above the buttons.
CGFloat gradientOriginY = CGRectGetHeight(self.view.bounds) -
constants.ButtonBottomPadding -
constants.ButtonTopPadding -
constants.ButtonHeight - constants.GradientHeight;
[_gradientView setFrame:CGRectMake(0, gradientOriginY, viewSize.width,
constants.GradientHeight)];
[_gradientLayer setFrame:[_gradientView bounds]];
// Layout the activity indicator in the center of the view.
CGRect bounds = self.view.bounds;
[_activityIndicator
setCenter:CGPointMake(CGRectGetMidX(bounds), CGRectGetMidY(bounds))];
[self updateLayout];
}
- (void)layoutButtons:(const AuthenticationViewConstants&)constants {
......@@ -1040,6 +1041,9 @@ enum AuthenticationState {
primaryButtonLayout.position.originY = CGRectGetHeight(self.view.bounds) -
constants.ButtonBottomPadding -
constants.ButtonHeight;
if (@available(iOS 11.0, *)) {
primaryButtonLayout.position.originY -= self.view.safeAreaInsets.bottom;
}
primaryButtonLayout.size.height = constants.ButtonHeight;
[_primaryButton setFrame:LayoutRectGetRect(primaryButtonLayout)];
......
......@@ -320,6 +320,11 @@ const char kPrivacyNoticeUrl[] = "internal://privacy-notice";
[self configureSubviews];
}
- (void)safeAreaInsetsDidChange {
[super safeAreaInsetsDidChange];
[self layoutOKButton];
}
- (void)layoutSubviews {
[super layoutSubviews];
[self layoutTitleLabel];
......@@ -494,10 +499,15 @@ const char kPrivacyNoticeUrl[] = "internal://privacy-notice";
CGFloat OKButtonBottomPadding =
kOKButtonBottomPadding[self.cr_widthSizeClass];
CGSize OKButtonSize = self.OKButton.bounds.size;
self.OKButton.frame = AlignRectOriginAndSizeToPixels(CGRectMake(
(CGRectGetWidth(self.bounds) - OKButtonSize.width) / 2.0,
CGRectGetMaxY(self.bounds) - OKButtonSize.height - OKButtonBottomPadding,
OKButtonSize.width, OKButtonSize.height));
CGFloat bottomSafeArea = 0;
if (@available(iOS 11.0, *)) {
bottomSafeArea = self.safeAreaInsets.bottom;
}
self.OKButton.frame = AlignRectOriginAndSizeToPixels(
CGRectMake((CGRectGetWidth(self.bounds) - OKButtonSize.width) / 2.0,
CGRectGetMaxY(self.bounds) - OKButtonSize.height -
OKButtonBottomPadding - bottomSafeArea,
OKButtonSize.width, OKButtonSize.height));
}
- (void)traitCollectionDidChange:
......
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