Commit 1d795f5f authored by Nohemi Fernandez's avatar Nohemi Fernandez Committed by Commit Bot

[iOS] Implement add account and more button press actions.

Add button press actions for two of the four button styles for the
UserSigninViewController. The sign-in operations will be added in a
follow-up patch.

See go/chrome-ios-signin-migration for more information.

Bug: 971989
Change-Id: Id669d2a788dd85849b13e1c27021fc7442e6a63d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2064945
Commit-Queue: Nohemi Fernandez <fernandex@chromium.org>
Reviewed-by: default avatarJérôme Lebel <jlebel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#743517}
parent 57ef6fb6
......@@ -69,19 +69,6 @@ using signin_metrics::PromoAction;
[self.unifiedConsentCoordinator start];
self.addAccountSigninCoordinator = [SigninCoordinator
addAccountCoordinatorWithBaseViewController:self.viewController
browser:self.browser
accessPoint:self.accessPoint];
__weak UserSigninCoordinator* weakSelf = self;
self.addAccountSigninCoordinator.signinCompletion =
^(SigninCoordinatorResult signinResult, ChromeIdentity* identity) {
if (signinResult == SigninCoordinatorResultSuccess) {
weakSelf.defaultIdentity = identity;
}
};
// Display UnifiedConsentViewController within the host.
self.viewController.unifiedConsentViewController =
self.unifiedConsentCoordinator.viewController;
......@@ -113,7 +100,7 @@ using signin_metrics::PromoAction;
- (void)unifiedConsentCoordinatorDidTapOnAddAccount:
(UnifiedConsentCoordinator*)coordinator {
DCHECK_EQ(self.unifiedConsentCoordinator, coordinator);
[self.addAccountSigninCoordinator start];
[self userSigninViewControllerDidTapOnAddAccount];
}
- (void)unifiedConsentCoordinatorNeedPrimaryButtonUpdate:
......@@ -128,4 +115,26 @@ using signin_metrics::PromoAction;
return self.unifiedConsentCoordinator.selectedIdentity != nil;
}
- (void)userSigninViewControllerDidTapOnAddAccount {
self.addAccountSigninCoordinator = [SigninCoordinator
addAccountCoordinatorWithBaseViewController:self.viewController
browser:self.browser
accessPoint:self.accessPoint];
__weak UserSigninCoordinator* weakSelf = self;
self.addAccountSigninCoordinator.signinCompletion =
^(SigninCoordinatorResult signinResult, ChromeIdentity* identity) {
if (signinResult == SigninCoordinatorResultSuccess) {
weakSelf.unifiedConsentCoordinator.selectedIdentity = identity;
[weakSelf.addAccountSigninCoordinator stop];
weakSelf.addAccountSigninCoordinator = nil;
}
};
[self.addAccountSigninCoordinator start];
}
- (void)userSigninViewControllerDidScrollOnUnifiedConsent {
[self.unifiedConsentCoordinator scrollToBottom];
}
@end
......@@ -9,9 +9,17 @@
// Delegate that interacts with the user sign-in coordinator.
@protocol UserSigninViewControllerDelegate
// Returns whether the user has selected an identity from the unified consent
// screen.
- (BOOL)unifiedConsentCoordinatorHasIdentity;
// Performs add account operation.
- (void)userSigninViewControllerDidTapOnAddAccount;
// Performs scroll operation on unified consent screen.
- (void)userSigninViewControllerDidScrollOnUnifiedConsent;
@end
// View controller used to show sign-in UI.
......
......@@ -44,7 +44,14 @@ const AuthenticationViewConstants kRegularConstants = {
32, // ButtonTopPadding
32, // ButtonBottomPadding
};
}
// The style applied to a button type.
enum AuthenticationButtonType {
AuthenticationButtonTypeMore,
AuthenticationButtonTypeAddAccount,
AuthenticationButtonTypeConfirmation,
};
} // namespace
@interface UserSigninViewController ()
......@@ -80,16 +87,22 @@ const AuthenticationViewConstants kRegularConstants = {
[self.confirmationButton setTitle:self.addAccountButtonTitle
forState:UIControlStateNormal];
[self setConfirmationStylingWithButton:self.confirmationButton];
self.confirmationButton.tag = AuthenticationButtonTypeAddAccount;
} else if (!self.hasUnifiedConsentScreenReachedBottom) {
// User has not scrolled to the bottom of the user consent screen.
// Display 'more' button.
[self updateButtonAsMoreButton:self.confirmationButton];
self.confirmationButton.tag = AuthenticationButtonTypeMore;
} else {
// By default display 'Yes I'm in' button.
[self.confirmationButton setTitle:self.confirmationButtonTitle
forState:UIControlStateNormal];
[self setConfirmationStylingWithButton:self.confirmationButton];
self.confirmationButton.tag = AuthenticationButtonTypeConfirmation;
}
[self.confirmationButton addTarget:self
action:@selector(onConfirmationButtonPressed:)
forControlEvents:UIControlEventTouchUpInside];
}
#pragma mark - UIViewController
......@@ -203,18 +216,16 @@ const AuthenticationViewConstants kRegularConstants = {
[self.skipSigninButton setTitle:self.skipSigninButtonTitle
forState:UIControlStateNormal];
[self setSkipSigninStylingWithButton:self.skipSigninButton];
[self.skipSigninButton addTarget:self
action:@selector(onSkipSigninButtonPressed:)
forControlEvents:UIControlEventTouchUpInside];
}
// Sets up button properties and adds it to view.
- (void)addSubviewWithButton:(UIButton*)button {
button.titleLabel.font =
[UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline];
[self.view addSubview:button];
[button addTarget:self
action:@selector(onButtonPressed:)
forControlEvents:UIControlEventTouchUpInside];
button.translatesAutoresizingMaskIntoConstraints = NO;
}
......@@ -245,9 +256,28 @@ const AuthenticationViewConstants kRegularConstants = {
#pragma mark - Events
- (void)onButtonPressed:(id)sender {
- (void)onSkipSigninButtonPressed:(id)sender {
// TODO(crbug.com/971989): Populate action.
NOTIMPLEMENTED();
}
- (void)onConfirmationButtonPressed:(id)sender {
DCHECK_EQ(self.confirmationButton, sender);
switch (self.confirmationButton.tag) {
case AuthenticationButtonTypeMore: {
[self.delegate userSigninViewControllerDidScrollOnUnifiedConsent];
break;
}
case AuthenticationButtonTypeAddAccount: {
[self.delegate userSigninViewControllerDidTapOnAddAccount];
break;
}
case AuthenticationButtonTypeConfirmation: {
// TODO(crbug.com/971989): Populate action.
NOTIMPLEMENTED();
break;
}
}
}
@end
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