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

[iOS] Implementation of "Not johndoe@example.com" in the sign-in promo

When the user clicks on	"Not johndoe@example.com", the sign-in dialog is
opened with the identity chooser dialog opened.

Bug: 827072
Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: Ic7aff360ee229ebd83063dfbef5b9bc7fe36d345
Reviewed-on: https://chromium-review.googlesource.com/1186739
Commit-Queue: Jérôme Lebel <jlebel@chromium.org>
Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#585820}
parent 7d5b5728
......@@ -18,12 +18,19 @@
@interface UnifiedConsentCoordinator ()<IdentityChooserCoordinatorDelegate,
UnifiedConsentViewControllerDelegate>
// Unified consent mediator.
@property(nonatomic, strong) UnifiedConsentMediator* unifiedConsentMediator;
@property(nonatomic, strong, readwrite)
// Unified consent view controller.
@property(nonatomic, strong)
UnifiedConsentViewController* unifiedConsentViewController;
@property(nonatomic, readwrite) BOOL settingsLinkWasTapped;
// YES if the user tapped on the setting link.
@property(nonatomic, assign) BOOL settingsLinkWasTapped;
// Identity chooser coordinator.
@property(nonatomic, strong)
IdentityChooserCoordinator* identityChooserCoordinator;
// YES if no default identity as been set before starting the coordinator.
@property(nonatomic, assign) BOOL shouldOpenIdentityChooserDialogWhenAppearing;
@end
@implementation UnifiedConsentCoordinator
......@@ -34,6 +41,8 @@
@synthesize settingsLinkWasTapped = _settingsLinkWasTapped;
@synthesize interactable = _interactable;
@synthesize identityChooserCoordinator = _identityChooserCoordinator;
@synthesize shouldOpenIdentityChooserDialogWhenAppearing =
_shouldOpenIdentityChooserDialogWhenAppearing;
- (instancetype)init {
self = [super init];
......@@ -48,6 +57,11 @@
- (void)start {
self.unifiedConsentViewController.interactable = self.interactable;
// If no selected identity has been set, the identity chooser dialog needs
// to be opened when the view will appear. This test has to be done before
// to start the mediator since it will select a default one on start.
self.shouldOpenIdentityChooserDialogWhenAppearing =
!self.unifiedConsentMediator.selectedIdentity;
[self.unifiedConsentMediator start];
}
......@@ -79,8 +93,30 @@
return self.unifiedConsentViewController.isScrolledToBottom;
}
#pragma mark - Private
// Opens the identity chooser dialog with an animation from |point|.
- (void)showIdentityChooserDialogWithPoint:(CGPoint)point {
self.identityChooserCoordinator = [[IdentityChooserCoordinator alloc]
initWithBaseViewController:self.unifiedConsentViewController];
self.identityChooserCoordinator.delegate = self;
self.identityChooserCoordinator.origin = point;
[self.identityChooserCoordinator start];
self.identityChooserCoordinator.selectedIdentity = self.selectedIdentity;
}
#pragma mark - UnifiedConsentViewControllerDelegate
- (void)unifiedConsentViewControllerViewDidAppear:
(UnifiedConsentViewController*)controller {
if (!self.shouldOpenIdentityChooserDialogWhenAppearing)
return;
CGFloat midX = CGRectGetMidX(self.unifiedConsentViewController.view.bounds);
CGFloat midY = CGRectGetMidY(self.unifiedConsentViewController.view.bounds);
CGPoint point = CGPointMake(midX, midY);
[self showIdentityChooserDialogWithPoint:point];
}
- (void)unifiedConsentViewControllerDidTapSettingsLink:
(UnifiedConsentViewController*)controller {
DCHECK_EQ(self.unifiedConsentViewController, controller);
......@@ -93,12 +129,7 @@
(UnifiedConsentViewController*)controller
atPoint:(CGPoint)point {
DCHECK_EQ(self.unifiedConsentViewController, controller);
self.identityChooserCoordinator = [[IdentityChooserCoordinator alloc]
initWithBaseViewController:self.unifiedConsentViewController];
self.identityChooserCoordinator.delegate = self;
self.identityChooserCoordinator.origin = point;
[self.identityChooserCoordinator start];
self.identityChooserCoordinator.selectedIdentity = self.selectedIdentity;
[self showIdentityChooserDialogWithPoint:point];
}
- (void)unifiedConsentViewControllerDidReachBottom:
......
......@@ -20,9 +20,13 @@
std::unique_ptr<ChromeBrowserProviderObserverBridge> _browserProviderObserver;
}
// Unified consent view controller.
@property(nonatomic, weak)
UnifiedConsentViewController* unifiedConsentViewController;
// Image for the selected identity avatar.
@property(nonatomic, strong) UIImage* selectedIdentityAvatar;
// NO until the mediator is started.
@property(nonatomic, assign) BOOL started;
@end
......@@ -31,6 +35,7 @@
@synthesize selectedIdentityAvatar = _selectedIdentityAvatar;
@synthesize selectedIdentity = _selectedIdentity;
@synthesize unifiedConsentViewController = _unifiedConsentViewController;
@synthesize started = _started;
- (instancetype)initWithUnifiedConsentViewController:
(UnifiedConsentViewController*)viewController {
......@@ -41,12 +46,6 @@
std::make_unique<ChromeIdentityServiceObserverBridge>(self);
_browserProviderObserver =
std::make_unique<ChromeBrowserProviderObserverBridge>(self);
NSArray* identities = ios::GetChromeBrowserProvider()
->GetChromeIdentityService()
->GetAllIdentitiesSortedForDisplay();
if (identities.count != 0) {
_selectedIdentity = identities[0];
}
}
return self;
}
......@@ -65,14 +64,25 @@
}
- (void)start {
NSArray* identities = ios::GetChromeBrowserProvider()
->GetChromeIdentityService()
->GetAllIdentitiesSortedForDisplay();
if (identities.count != 0) {
self.selectedIdentity = identities[0];
}
// Make sure the view is loaded so the mediator can set it up.
[self.unifiedConsentViewController loadViewIfNeeded];
self.started = YES;
[self updateViewController];
}
#pragma mark - Private
// Updates the view if the mediator has been started.
- (void)updateViewController {
// The UI should not be updated before the view is loaded.
if (!self.started)
return;
if (self.selectedIdentity) {
[self.unifiedConsentViewController
updateIdentityPickerViewWithUserFullName:self.selectedIdentity
......
......@@ -325,6 +325,10 @@ NSString* const kSyncCompleteIconName = @"ic_sync_complete";
[self updateScrollViewAndImageBackgroundView];
}
- (void)viewDidAppear:(BOOL)animated {
[self.delegate unifiedConsentViewControllerViewDidAppear:self];
}
// Updates the scroll view content inset, used by pre iOS 11.
- (void)viewWillTransitionToSize:(CGSize)size
withTransitionCoordinator:
......
......@@ -27,6 +27,10 @@
- (void)unifiedConsentViewControllerDidReachBottom:
(UnifiedConsentViewController*)controller;
// Called when the view appears.
- (void)unifiedConsentViewControllerViewDidAppear:
(UnifiedConsentViewController*)controller;
@end
#endif // IOS_CHROME_BROWSER_UI_AUTHENTICATION_UNIFIED_CONSENT_UNIFIED_CONSENT_VIEW_CONTROLLER_DELEGATE_H_
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