From 659a5820aa3c7bc8cb61d66e9e7d00e2db333d1f Mon Sep 17 00:00:00 2001 From: jlebel Date: Wed, 13 Oct 2021 15:16:41 +0000 Subject: [PATCH] [iOS] Fix background color for IdentityButtonControl MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Related to: crrev.com/c/3067351 Fixed: 1238293 Change-Id: I2b5ba57703e672e7180b2cc279c7276a651698e8 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3220793 Commit-Queue: Jérôme Commit-Queue: Nohemi Fernandez Auto-Submit: Jérôme Reviewed-by: Nohemi Fernandez Cr-Commit-Position: refs/heads/main@{#931063} --- ...istency_default_account_view_controller.mm | 2 -- .../views/identity_button_control.mm | 24 +++++++++++++++---- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/ios/chrome/browser/ui/authentication/signin/consistency_promo_signin/consistency_default_account/consistency_default_account_view_controller.mm b/ios/chrome/browser/ui/authentication/signin/consistency_promo_signin/consistency_default_account/consistency_default_account_view_controller.mm index af27a0b5580839..0e1eeb36a09d63 100644 --- a/ios/chrome/browser/ui/authentication/signin/consistency_promo_signin/consistency_default_account/consistency_default_account_view_controller.mm +++ b/ios/chrome/browser/ui/authentication/signin/consistency_promo_signin/consistency_default_account/consistency_default_account_view_controller.mm @@ -164,8 +164,6 @@ - (void)viewDidLoad { // Add IdentityButtonControl for the default identity. self.identityButtonControl = [[IdentityButtonControl alloc] initWithFrame:CGRectZero]; - self.identityButtonControl.backgroundColor = - [UIColor colorNamed:kGroupedSecondaryBackgroundColor]; self.identityButtonControl.arrowDirection = IdentityButtonControlArrowRight; self.identityButtonControl.identityViewStyle = IdentityViewStyleConsistency; [self.identityButtonControl addTarget:self diff --git a/ios/chrome/browser/ui/authentication/views/identity_button_control.mm b/ios/chrome/browser/ui/authentication/views/identity_button_control.mm index 1308ac2b0139a2..d502460e7f228e 100644 --- a/ios/chrome/browser/ui/authentication/views/identity_button_control.mm +++ b/ios/chrome/browser/ui/authentication/views/identity_button_control.mm @@ -44,7 +44,7 @@ - (instancetype)initWithFrame:(CGRect)frame { if (self) { self.accessibilityIdentifier = kIdentityButtonControlIdentifier; self.layer.cornerRadius = kIdentityButtonControlRadius; - self.backgroundColor = [UIColor colorNamed:kSecondaryBackgroundColor]; + [self setUnhighlightedBackgroundColor]; // Adding view elements inside. // Down or right arrow. @@ -116,6 +116,8 @@ - (void)setArrowDirection:(IdentityButtonControlArrowDirection)arrowDirection { - (void)setIdentityViewStyle:(IdentityViewStyle)style { self.identityView.style = style; + if (!self.highlighted) + [self setUnhighlightedBackgroundColor]; } - (IdentityViewStyle)identityViewStyle { @@ -124,6 +126,21 @@ - (IdentityViewStyle)identityViewStyle { #pragma mark - Private +// Sets the background color when not highlighted. +- (void)setUnhighlightedBackgroundColor { + DCHECK(!self.highlighted); + switch (self.identityView.style) { + case IdentityViewStyleDefault: + case IdentityViewStyleIdentityChooser: + self.backgroundColor = [UIColor colorNamed:kSecondaryBackgroundColor]; + break; + case IdentityViewStyleConsistency: + self.backgroundColor = + [UIColor colorNamed:kGroupedSecondaryBackgroundColor]; + break; + } +} + - (CGPoint)locationFromTouches:(NSSet*)touches { UITouch* touch = [touches anyObject]; return [touch locationInView:self]; @@ -153,9 +170,8 @@ - (void)setHighlighted:(BOOL)highlighted { if (highlighted) { self.backgroundColor = [UIColor colorNamed:kGrey300Color]; - } else if (self.identityViewStyle != IdentityViewStyleConsistency) { - // Background color for the consistency web sign-in is reset manually. - self.backgroundColor = [UIColor colorNamed:kSecondaryBackgroundColor]; + } else { + [self setUnhighlightedBackgroundColor]; } }