Commit 45c1a3f1 authored by Nohemi Fernandez's avatar Nohemi Fernandez Committed by Commit Bot

[iOS] Improve readability of UserSigninViewController.

It was difficult to understand the current constraint layout of the
"Turn on Sync" page due to the inconsistencies in the view manipulation.
This patch attempts to make the layout and styling of the views and
buttons more straightforward.

Bug: 1105853
Change-Id: I0c0bca5aa1be5200d3be414804976efc8ed7ef22
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2312556
Commit-Queue: Nohemi Fernandez <fernandex@chromium.org>
Reviewed-by: default avatarJérôme Lebel <jlebel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#791778}
parent 6e87a86b
...@@ -219,7 +219,7 @@ const CGFloat kFadeOutAnimationDuration = 0.16f; ...@@ -219,7 +219,7 @@ const CGFloat kFadeOutAnimationDuration = 0.16f;
- (void)unifiedConsentCoordinatorNeedPrimaryButtonUpdate: - (void)unifiedConsentCoordinatorNeedPrimaryButtonUpdate:
(UnifiedConsentCoordinator*)coordinator { (UnifiedConsentCoordinator*)coordinator {
DCHECK_EQ(self.unifiedConsentCoordinator, coordinator); DCHECK_EQ(self.unifiedConsentCoordinator, coordinator);
[self.viewController updatePrimaryButtonStyle]; [self.viewController setConfirmationButtonProperties];
} }
#pragma mark - UserSigninViewControllerDelegate #pragma mark - UserSigninViewControllerDelegate
...@@ -330,7 +330,7 @@ const CGFloat kFadeOutAnimationDuration = 0.16f; ...@@ -330,7 +330,7 @@ const CGFloat kFadeOutAnimationDuration = 0.16f;
[self.unifiedConsentCoordinator resetSettingLinkTapped]; [self.unifiedConsentCoordinator resetSettingLinkTapped];
self.unifiedConsentCoordinator.uiDisabled = NO; self.unifiedConsentCoordinator.uiDisabled = NO;
[self.viewController signinDidStop]; [self.viewController signinDidStop];
[self.viewController updatePrimaryButtonStyle]; [self.viewController setConfirmationButtonProperties];
} }
#pragma mark - Private #pragma mark - Private
......
...@@ -48,8 +48,10 @@ ...@@ -48,8 +48,10 @@
// of the screen. // of the screen.
- (void)markUnifiedConsentScreenReachedBottom; - (void)markUnifiedConsentScreenReachedBottom;
// Updates the primary button based on the user sign-in state. // Sets the title, styling, and other button properties for the confirmation
- (void)updatePrimaryButtonStyle; // button based on the user consent text that is currently displayed on-screen
// and the whether the user has previously been signed-in.
- (void)setConfirmationButtonProperties;
// Returns the supported orientations for the device type: // Returns the supported orientations for the device type:
// |UIInterfaceOrientationPortrait| orientation on iPhone and all other // |UIInterfaceOrientationPortrait| orientation on iPhone and all other
......
...@@ -113,23 +113,25 @@ enum AuthenticationButtonType { ...@@ -113,23 +113,25 @@ enum AuthenticationButtonType {
// This is the first time the unified consent screen has reached the bottom. // This is the first time the unified consent screen has reached the bottom.
if (self.hasUnifiedConsentScreenReachedBottom == NO) { if (self.hasUnifiedConsentScreenReachedBottom == NO) {
self.hasUnifiedConsentScreenReachedBottom = YES; self.hasUnifiedConsentScreenReachedBottom = YES;
[self updatePrimaryButtonStyle]; [self setConfirmationButtonProperties];
} }
} }
- (void)updatePrimaryButtonStyle { - (void)setConfirmationButtonProperties {
if (![self.delegate unifiedConsentCoordinatorHasIdentity]) { if (![self.delegate unifiedConsentCoordinatorHasIdentity]) {
// User has not added an account. Display 'add account' button. // User has not added an account. Display 'add account' button.
[self.confirmationButton setTitle:self.addAccountButtonTitle [self.confirmationButton setTitle:self.addAccountButtonTitle
forState:UIControlStateNormal]; forState:UIControlStateNormal];
[self setConfirmationStylingWithButton:self.confirmationButton]; [self setBlueBackgroundStylingWithButton:self.confirmationButton];
self.confirmationButton.tag = AuthenticationButtonTypeAddAccount; self.confirmationButton.tag = AuthenticationButtonTypeAddAccount;
self.confirmationButton.accessibilityIdentifier = self.confirmationButton.accessibilityIdentifier =
kAddAccountAccessibilityIdentifier; kAddAccountAccessibilityIdentifier;
} else if (!self.hasUnifiedConsentScreenReachedBottom) { } else if (!self.hasUnifiedConsentScreenReachedBottom) {
// User has not scrolled to the bottom of the user consent screen. // User has not scrolled to the bottom of the user consent screen.
// Display 'more' button. // Display 'more' button.
[self updateButtonAsMoreButton:self.confirmationButton]; [self.confirmationButton setTitle:self.scrollButtonTitle
forState:UIControlStateNormal];
[self setMoreButtonStylingWithButton:self.confirmationButton];
self.confirmationButton.tag = AuthenticationButtonTypeMore; self.confirmationButton.tag = AuthenticationButtonTypeMore;
self.confirmationButton.accessibilityIdentifier = self.confirmationButton.accessibilityIdentifier =
kMoreAccessibilityIdentifier; kMoreAccessibilityIdentifier;
...@@ -137,7 +139,7 @@ enum AuthenticationButtonType { ...@@ -137,7 +139,7 @@ enum AuthenticationButtonType {
// By default display 'Yes I'm in' button. // By default display 'Yes I'm in' button.
[self.confirmationButton setTitle:self.confirmationButtonTitle [self.confirmationButton setTitle:self.confirmationButtonTitle
forState:UIControlStateNormal]; forState:UIControlStateNormal];
[self setConfirmationStylingWithButton:self.confirmationButton]; [self setBlueBackgroundStylingWithButton:self.confirmationButton];
self.confirmationButton.tag = AuthenticationButtonTypeConfirmation; self.confirmationButton.tag = AuthenticationButtonTypeConfirmation;
self.confirmationButton.accessibilityIdentifier = self.confirmationButton.accessibilityIdentifier =
kConfirmationAccessibilityIdentifier; kConfirmationAccessibilityIdentifier;
...@@ -191,23 +193,41 @@ enum AuthenticationButtonType { ...@@ -191,23 +193,41 @@ enum AuthenticationButtonType {
[super viewDidLoad]; [super viewDidLoad];
self.view.backgroundColor = self.systemBackgroundColor; self.view.backgroundColor = self.systemBackgroundColor;
[self addConfirmationButton]; self.containerView = [[UIView alloc] init];
[self addSkipSigninButton]; self.containerView.translatesAutoresizingMaskIntoConstraints = NO;
[self embedUserConsentView]; [self.view addSubview:self.containerView];
self.confirmationButton = [[UIButton alloc] init];
[self setConfirmationButtonProperties];
[self maybeEnablePointerSupportWithButton:self.confirmationButton];
self.confirmationButton.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:self.confirmationButton];
self.skipSigninButton = [[UIButton alloc] init];
[self setSkipSigninButtonProperties];
[self maybeEnablePointerSupportWithButton:self.skipSigninButton];
self.skipSigninButton.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:self.skipSigninButton];
self.unifiedConsentViewController.view
.translatesAutoresizingMaskIntoConstraints = NO;
[self addChildViewController:self.unifiedConsentViewController];
[self.containerView addSubview:self.unifiedConsentViewController.view];
[self.unifiedConsentViewController didMoveToParentViewController:self];
self.gradientView.translatesAutoresizingMaskIntoConstraints = NO;
[self.containerView addSubview:self.gradientView];
[NSLayoutConstraint activateConstraints:@[ [NSLayoutConstraint activateConstraints:@[
// Contraints for the container view. The bottom constraint has to be set // Note that the bottom constraint of the container view and
// according to the size class. // |unifiedConsentViewController.view| is dependent on the selected
// Accessibility options in Settings, e.g. text size. These constraints
// are computed in |setAccessibilityLayoutConstraints|.
[self.containerView.topAnchor constraintEqualToAnchor:self.view.topAnchor], [self.containerView.topAnchor constraintEqualToAnchor:self.view.topAnchor],
[self.containerView.leadingAnchor [self.containerView.leadingAnchor
constraintEqualToAnchor:self.view.leadingAnchor], constraintEqualToAnchor:self.view.leadingAnchor],
[self.containerView.trailingAnchor [self.containerView.trailingAnchor
constraintEqualToAnchor:self.view.trailingAnchor], constraintEqualToAnchor:self.view.trailingAnchor],
]];
[self.containerView addSubview:self.gradientView];
self.gradientView.translatesAutoresizingMaskIntoConstraints = NO;
[NSLayoutConstraint activateConstraints:@[
// The gradient view needs to be attatched to the bottom of the user // The gradient view needs to be attatched to the bottom of the user
// consent view which contains the scroll view. // consent view which contains the scroll view.
[self.gradientView.bottomAnchor [self.gradientView.bottomAnchor
...@@ -222,12 +242,12 @@ enum AuthenticationButtonType { ...@@ -222,12 +242,12 @@ enum AuthenticationButtonType {
[self.gradientView.heightAnchor constraintEqualToConstant:kGradientHeight], [self.gradientView.heightAnchor constraintEqualToConstant:kGradientHeight],
]]; ]];
[self updateViewsAndConstraints]; [self setAccessibilityLayoutConstraints];
} }
- (void)viewDidLayoutSubviews { - (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews]; [super viewDidLayoutSubviews];
[self updateViewsAndConstraints]; [self setAccessibilityLayoutConstraints];
} }
#pragma mark - Constraints #pragma mark - Constraints
...@@ -257,8 +277,9 @@ enum AuthenticationButtonType { ...@@ -257,8 +277,9 @@ enum AuthenticationButtonType {
return constraints; return constraints;
} }
// Updates view sizes and constraints. // Sets the layout constraints depending on the selected text size in the
- (void)updateViewsAndConstraints { // accessibility Settings.
- (void)setAccessibilityLayoutConstraints {
BOOL isRegularSizeClass = IsRegularXRegularSizeClass(self.traitCollection); BOOL isRegularSizeClass = IsRegularXRegularSizeClass(self.traitCollection);
UIFontTextStyle fontStyle; UIFontTextStyle fontStyle;
if (isRegularSizeClass) { if (isRegularSizeClass) {
...@@ -406,82 +427,38 @@ enum AuthenticationButtonType { ...@@ -406,82 +427,38 @@ enum AuthenticationButtonType {
AddSameCenterConstraints(self.confirmationButton, self.activityIndicator); AddSameCenterConstraints(self.confirmationButton, self.activityIndicator);
} }
// Embeds the user consent view in the root view. // Sets the text, styling, and other button properties for the skip sign-in
- (void)embedUserConsentView { // button.
DCHECK(self.confirmationButton); - (void)setSkipSigninButtonProperties {
DCHECK(self.unifiedConsentViewController); DCHECK(self.skipSigninButton);
self.unifiedConsentViewController.view
.translatesAutoresizingMaskIntoConstraints = NO;
self.containerView = [[UIView alloc] init];
self.containerView.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:self.containerView];
[self addChildViewController:self.unifiedConsentViewController];
[self.containerView addSubview:self.unifiedConsentViewController.view];
[self.unifiedConsentViewController didMoveToParentViewController:self];
}
// Sets up confirmation button properties and adds it to the user sign-in view.
- (void)addConfirmationButton {
DCHECK(self.unifiedConsentViewController);
self.confirmationButton = [[UIButton alloc] init];
#if defined(__IPHONE_13_4)
if (@available(iOS 13.4, *)) {
if (base::FeatureList::IsEnabled(kPointerSupport)) {
self.confirmationButton.pointerInteractionEnabled = YES;
// This button can either have an opaque background (i.e., "Add Account"
// or "Yes, I'm in!") or a transparent background (i.e., "More") when
// scrolling is needed to reach the bottom of the screen.
self.confirmationButton.pointerStyleProvider =
CreateOpaqueOrTransparentButtonPointerStyleProvider();
}
}
#endif // defined(__IPHONE_13_4)
[self addSubviewWithButton:self.confirmationButton];
// Note that the button style will depend on the user sign-in state.
[self updatePrimaryButtonStyle];
}
// Sets up skip sign-in button properties and adds it to the user sign-in view.
- (void)addSkipSigninButton {
DCHECK(!self.skipSigninButton);
DCHECK(self.unifiedConsentViewController);
self.skipSigninButton = [[UIButton alloc] init];
self.skipSigninButton.accessibilityIdentifier = self.skipSigninButton.accessibilityIdentifier =
kSkipSigninAccessibilityIdentifier; kSkipSigninAccessibilityIdentifier;
[self addSubviewWithButton:self.skipSigninButton];
[self.skipSigninButton setTitle:self.skipSigninButtonTitle [self.skipSigninButton setTitle:self.skipSigninButtonTitle
forState:UIControlStateNormal]; forState:UIControlStateNormal];
[self setSkipSigninStylingWithButton:self.skipSigninButton]; [self.skipSigninButton setTitleColor:[UIColor colorNamed:kBlueColor]
forState:UIControlStateNormal];
[self.skipSigninButton addTarget:self [self.skipSigninButton addTarget:self
action:@selector(onSkipSigninButtonPressed:) action:@selector(onSkipSigninButtonPressed:)
forControlEvents:UIControlEventTouchUpInside]; forControlEvents:UIControlEventTouchUpInside];
}
#pragma mark - Styling
// Enables pointer support for the button if it is supported on the iOS version.
- (void)maybeEnablePointerSupportWithButton:(UIButton*)button {
DCHECK(button);
#if defined(__IPHONE_13_4) #if defined(__IPHONE_13_4)
if (@available(iOS 13.4, *)) { if (@available(iOS 13.4, *)) {
if (base::FeatureList::IsEnabled(kPointerSupport)) { if (base::FeatureList::IsEnabled(kPointerSupport)) {
self.skipSigninButton.pointerInteractionEnabled = YES; button.pointerInteractionEnabled = YES;
self.skipSigninButton.pointerStyleProvider = button.pointerStyleProvider =
CreateTransparentButtonPointerStyleProvider(); CreateTransparentButtonPointerStyleProvider();
} }
} }
#endif // defined(__IPHONE_13_4) #endif // defined(__IPHONE_13_4)
} }
// Sets up button properties and adds it to view. - (void)setBlueBackgroundStylingWithButton:(UIButton*)button {
- (void)addSubviewWithButton:(UIButton*)button {
[button
setContentCompressionResistancePriority:UILayoutPriorityRequired
forAxis:UILayoutConstraintAxisVertical];
[button setContentHuggingPriority:UILayoutPriorityRequired
forAxis:UILayoutConstraintAxisVertical];
[self.view addSubview:button];
button.translatesAutoresizingMaskIntoConstraints = NO;
}
#pragma mark - Styling
- (void)setConfirmationStylingWithButton:(UIButton*)button {
DCHECK(button); DCHECK(button);
button.backgroundColor = [UIColor colorNamed:kBlueColor]; button.backgroundColor = [UIColor colorNamed:kBlueColor];
button.layer.cornerRadius = kButtonCornerRadius; button.layer.cornerRadius = kButtonCornerRadius;
...@@ -490,18 +467,13 @@ enum AuthenticationButtonType { ...@@ -490,18 +467,13 @@ enum AuthenticationButtonType {
[button setImage:nil forState:UIControlStateNormal]; [button setImage:nil forState:UIControlStateNormal];
} }
- (void)setSkipSigninStylingWithButton:(UIButton*)button { - (void)setMoreButtonStylingWithButton:(UIButton*)button {
DCHECK(button); DCHECK(button);
[button setTitleColor:[UIColor colorNamed:kBlueColor]
forState:UIControlStateNormal];
}
- (void)updateButtonAsMoreButton:(UIButton*)button {
[button setTitle:self.scrollButtonTitle forState:UIControlStateNormal];
UIImage* buttonImage = [[UIImage imageNamed:@"signin_confirmation_more"] UIImage* buttonImage = [[UIImage imageNamed:@"signin_confirmation_more"]
imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
[button setImage:buttonImage forState:UIControlStateNormal]; [button setImage:buttonImage forState:UIControlStateNormal];
[self setSkipSigninStylingWithButton:button]; [button setTitleColor:[UIColor colorNamed:kBlueColor]
forState:UIControlStateNormal];
if (UIApplication.sharedApplication.userInterfaceLayoutDirection == if (UIApplication.sharedApplication.userInterfaceLayoutDirection ==
UIUserInterfaceLayoutDirectionLeftToRight) { UIUserInterfaceLayoutDirectionLeftToRight) {
button.imageEdgeInsets = UIEdgeInsetsMake(0, -kImageInset, 0, 0); button.imageEdgeInsets = UIEdgeInsetsMake(0, -kImageInset, 0, 0);
......
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