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 @@ ...@@ -18,12 +18,19 @@
@interface UnifiedConsentCoordinator ()<IdentityChooserCoordinatorDelegate, @interface UnifiedConsentCoordinator ()<IdentityChooserCoordinatorDelegate,
UnifiedConsentViewControllerDelegate> UnifiedConsentViewControllerDelegate>
// Unified consent mediator.
@property(nonatomic, strong) UnifiedConsentMediator* unifiedConsentMediator; @property(nonatomic, strong) UnifiedConsentMediator* unifiedConsentMediator;
@property(nonatomic, strong, readwrite) // Unified consent view controller.
@property(nonatomic, strong)
UnifiedConsentViewController* unifiedConsentViewController; 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) @property(nonatomic, strong)
IdentityChooserCoordinator* identityChooserCoordinator; IdentityChooserCoordinator* identityChooserCoordinator;
// YES if no default identity as been set before starting the coordinator.
@property(nonatomic, assign) BOOL shouldOpenIdentityChooserDialogWhenAppearing;
@end @end
@implementation UnifiedConsentCoordinator @implementation UnifiedConsentCoordinator
...@@ -34,6 +41,8 @@ ...@@ -34,6 +41,8 @@
@synthesize settingsLinkWasTapped = _settingsLinkWasTapped; @synthesize settingsLinkWasTapped = _settingsLinkWasTapped;
@synthesize interactable = _interactable; @synthesize interactable = _interactable;
@synthesize identityChooserCoordinator = _identityChooserCoordinator; @synthesize identityChooserCoordinator = _identityChooserCoordinator;
@synthesize shouldOpenIdentityChooserDialogWhenAppearing =
_shouldOpenIdentityChooserDialogWhenAppearing;
- (instancetype)init { - (instancetype)init {
self = [super init]; self = [super init];
...@@ -48,6 +57,11 @@ ...@@ -48,6 +57,11 @@
- (void)start { - (void)start {
self.unifiedConsentViewController.interactable = self.interactable; 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]; [self.unifiedConsentMediator start];
} }
...@@ -79,8 +93,30 @@ ...@@ -79,8 +93,30 @@
return self.unifiedConsentViewController.isScrolledToBottom; 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 #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: - (void)unifiedConsentViewControllerDidTapSettingsLink:
(UnifiedConsentViewController*)controller { (UnifiedConsentViewController*)controller {
DCHECK_EQ(self.unifiedConsentViewController, controller); DCHECK_EQ(self.unifiedConsentViewController, controller);
...@@ -93,12 +129,7 @@ ...@@ -93,12 +129,7 @@
(UnifiedConsentViewController*)controller (UnifiedConsentViewController*)controller
atPoint:(CGPoint)point { atPoint:(CGPoint)point {
DCHECK_EQ(self.unifiedConsentViewController, controller); DCHECK_EQ(self.unifiedConsentViewController, controller);
self.identityChooserCoordinator = [[IdentityChooserCoordinator alloc] [self showIdentityChooserDialogWithPoint:point];
initWithBaseViewController:self.unifiedConsentViewController];
self.identityChooserCoordinator.delegate = self;
self.identityChooserCoordinator.origin = point;
[self.identityChooserCoordinator start];
self.identityChooserCoordinator.selectedIdentity = self.selectedIdentity;
} }
- (void)unifiedConsentViewControllerDidReachBottom: - (void)unifiedConsentViewControllerDidReachBottom:
......
...@@ -20,9 +20,13 @@ ...@@ -20,9 +20,13 @@
std::unique_ptr<ChromeBrowserProviderObserverBridge> _browserProviderObserver; std::unique_ptr<ChromeBrowserProviderObserverBridge> _browserProviderObserver;
} }
// Unified consent view controller.
@property(nonatomic, weak) @property(nonatomic, weak)
UnifiedConsentViewController* unifiedConsentViewController; UnifiedConsentViewController* unifiedConsentViewController;
// Image for the selected identity avatar.
@property(nonatomic, strong) UIImage* selectedIdentityAvatar; @property(nonatomic, strong) UIImage* selectedIdentityAvatar;
// NO until the mediator is started.
@property(nonatomic, assign) BOOL started;
@end @end
...@@ -31,6 +35,7 @@ ...@@ -31,6 +35,7 @@
@synthesize selectedIdentityAvatar = _selectedIdentityAvatar; @synthesize selectedIdentityAvatar = _selectedIdentityAvatar;
@synthesize selectedIdentity = _selectedIdentity; @synthesize selectedIdentity = _selectedIdentity;
@synthesize unifiedConsentViewController = _unifiedConsentViewController; @synthesize unifiedConsentViewController = _unifiedConsentViewController;
@synthesize started = _started;
- (instancetype)initWithUnifiedConsentViewController: - (instancetype)initWithUnifiedConsentViewController:
(UnifiedConsentViewController*)viewController { (UnifiedConsentViewController*)viewController {
...@@ -41,12 +46,6 @@ ...@@ -41,12 +46,6 @@
std::make_unique<ChromeIdentityServiceObserverBridge>(self); std::make_unique<ChromeIdentityServiceObserverBridge>(self);
_browserProviderObserver = _browserProviderObserver =
std::make_unique<ChromeBrowserProviderObserverBridge>(self); std::make_unique<ChromeBrowserProviderObserverBridge>(self);
NSArray* identities = ios::GetChromeBrowserProvider()
->GetChromeIdentityService()
->GetAllIdentitiesSortedForDisplay();
if (identities.count != 0) {
_selectedIdentity = identities[0];
}
} }
return self; return self;
} }
...@@ -65,14 +64,25 @@ ...@@ -65,14 +64,25 @@
} }
- (void)start { - (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. // Make sure the view is loaded so the mediator can set it up.
[self.unifiedConsentViewController loadViewIfNeeded]; [self.unifiedConsentViewController loadViewIfNeeded];
self.started = YES;
[self updateViewController]; [self updateViewController];
} }
#pragma mark - Private #pragma mark - Private
// Updates the view if the mediator has been started.
- (void)updateViewController { - (void)updateViewController {
// The UI should not be updated before the view is loaded.
if (!self.started)
return;
if (self.selectedIdentity) { if (self.selectedIdentity) {
[self.unifiedConsentViewController [self.unifiedConsentViewController
updateIdentityPickerViewWithUserFullName:self.selectedIdentity updateIdentityPickerViewWithUserFullName:self.selectedIdentity
......
...@@ -325,6 +325,10 @@ NSString* const kSyncCompleteIconName = @"ic_sync_complete"; ...@@ -325,6 +325,10 @@ NSString* const kSyncCompleteIconName = @"ic_sync_complete";
[self updateScrollViewAndImageBackgroundView]; [self updateScrollViewAndImageBackgroundView];
} }
- (void)viewDidAppear:(BOOL)animated {
[self.delegate unifiedConsentViewControllerViewDidAppear:self];
}
// Updates the scroll view content inset, used by pre iOS 11. // Updates the scroll view content inset, used by pre iOS 11.
- (void)viewWillTransitionToSize:(CGSize)size - (void)viewWillTransitionToSize:(CGSize)size
withTransitionCoordinator: withTransitionCoordinator:
......
...@@ -27,6 +27,10 @@ ...@@ -27,6 +27,10 @@
- (void)unifiedConsentViewControllerDidReachBottom: - (void)unifiedConsentViewControllerDidReachBottom:
(UnifiedConsentViewController*)controller; (UnifiedConsentViewController*)controller;
// Called when the view appears.
- (void)unifiedConsentViewControllerViewDidAppear:
(UnifiedConsentViewController*)controller;
@end @end
#endif // IOS_CHROME_BROWSER_UI_AUTHENTICATION_UNIFIED_CONSENT_UNIFIED_CONSENT_VIEW_CONTROLLER_DELEGATE_H_ #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