Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(382)

Unified Diff: ios/chrome/browser/ui/authentication/signin_promo_view.mm

Issue 2749703003: Adding mediator for Sign-in promo (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ios/chrome/browser/ui/authentication/signin_promo_view.mm
diff --git a/ios/chrome/browser/ui/authentication/signin_promo_view.mm b/ios/chrome/browser/ui/authentication/signin_promo_view.mm
new file mode 100644
index 0000000000000000000000000000000000000000..350c449b98df30a9ed0d2c38e872a9614e75a8b1
--- /dev/null
+++ b/ios/chrome/browser/ui/authentication/signin_promo_view.mm
@@ -0,0 +1,239 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "ios/chrome/browser/ui/authentication/signin_promo_view.h"
+
+#include "base/logging.h"
+#import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h"
+#import "ios/chrome/browser/ui/uikit_ui_util.h"
+#include "ios/chrome/grit/ios_strings.h"
+#import "ios/third_party/material_components_ios/src/components/Buttons/src/MaterialButtons.h"
+#import "ios/third_party/material_components_ios/src/components/Typography/src/MaterialTypography.h"
+
+namespace {
+// Horizontal padding for label and buttons.
+const CGFloat kHorizontalPadding = 40;
+// Vertical padding for the image and the label.
+const CGFloat kVerticalPadding = 12;
+// Vertical padding for buttons.
+const CGFloat kButtonVerticalPadding = 6;
+// Image size for warm start.
+const CGFloat kProfileImageFixedSize = 48;
+// Image size for cold start.
+const CGFloat kChromeImageFixedSize = 24;
+// Button height.
+const CGFloat kButtonHeight = 36;
+}
+
+@implementation SigninPromoView {
msarda 2017/03/16 22:15:31 Louis: May I ask you to do an in-depth review of t
+ SigninPromoViewMode _mode;
+ UIImageView* _imageView;
+ UILabel* _textLabel;
+ MDCFlatButton* _primaryButton;
+ MDCFlatButton* _secondaryButton;
+
+ NSArray<NSLayoutConstraint*>* _coldStartConstraints;
+ NSArray<NSLayoutConstraint*>* _warmStartConstraints;
+}
+
+@synthesize mode = _mode;
+@synthesize imageView = _imageView;
+@synthesize textLabel = _textLabel;
+@synthesize primaryButton = _primaryButton;
+@synthesize secondaryButton = _secondaryButton;
+
+- (instancetype)initWithCoder:(NSCoder*)aDecoder {
+ NOTREACHED();
+ return nil;
+}
+
+- (instancetype)initWithFrame:(CGRect)frame {
+ self = [super initWithFrame:frame];
+ if (self) {
+ self.translatesAutoresizingMaskIntoConstraints = NO;
+ self.isAccessibilityElement = YES;
+ [self addSubviews];
+ [self setDefaultViewStyling];
+ [self setViewConstraints];
+ _mode = SigninPromoViewColdStartMode;
+ [self activateColdMode];
+ }
+ return self;
+}
+
+- (void)addSubviews {
+ self.clipsToBounds = YES;
+
+ _imageView = [[UIImageView alloc] init];
+ _imageView.translatesAutoresizingMaskIntoConstraints = NO;
+ [self addSubview:_imageView];
+
+ _textLabel = [[UILabel alloc] init];
+ _textLabel.translatesAutoresizingMaskIntoConstraints = NO;
+ [self addSubview:_textLabel];
+
+ _primaryButton = [[MDCFlatButton alloc] init];
+ _primaryButton.translatesAutoresizingMaskIntoConstraints = NO;
+ _primaryButton.accessibilityIdentifier = @"signin_promo_primary_button";
+ [self addSubview:_primaryButton];
+
+ _secondaryButton = [[MDCFlatButton alloc] init];
+ _secondaryButton.translatesAutoresizingMaskIntoConstraints = NO;
+ _secondaryButton.accessibilityIdentifier = @"signin_promo_secondary_button";
+ [self addSubview:_secondaryButton];
+}
+
+- (void)setDefaultViewStyling {
+ _imageView.contentMode = UIViewContentModeCenter;
+ _imageView.layer.masksToBounds = YES;
+ _imageView.contentMode = UIViewContentModeScaleAspectFit;
+
+ _textLabel.font = [MDCTypography buttonFont];
+ _textLabel.textColor = [[MDCPalette greyPalette] tint900];
+ _textLabel.numberOfLines = 0;
+ _textLabel.textAlignment = NSTextAlignmentCenter;
+
+ [_primaryButton setBackgroundColor:[[MDCPalette cr_bluePalette] tint500]
+ forState:UIControlStateNormal];
+ _primaryButton.customTitleColor = [UIColor whiteColor];
+ _primaryButton.inkColor = [UIColor colorWithWhite:1 alpha:0.2];
+
+ _secondaryButton.customTitleColor = [[MDCPalette cr_bluePalette] tint500];
+ _secondaryButton.uppercaseTitle = NO;
+}
+
+- (void)setViewConstraints {
+ [NSLayoutConstraint activateConstraints:@[
+ // Set vertical anchors.
+ [_imageView.topAnchor constraintEqualToAnchor:self.topAnchor
msarda 2017/03/16 22:15:31 I have to say I find this constraints code very ha
jlebel 2017/03/21 17:22:29 Done.
+ constant:kVerticalPadding * 2],
+ [_textLabel.topAnchor constraintEqualToAnchor:_imageView.bottomAnchor
+ constant:kVerticalPadding],
+ [_primaryButton.topAnchor
+ constraintEqualToAnchor:_textLabel.bottomAnchor
+ constant:kVerticalPadding + kButtonVerticalPadding],
+
+ // Set horizontal anchors.
+ [_imageView.centerXAnchor constraintEqualToAnchor:self.centerXAnchor],
+ [_textLabel.centerXAnchor constraintEqualToAnchor:self.centerXAnchor],
+ [_primaryButton.centerXAnchor constraintEqualToAnchor:self.centerXAnchor],
+ [_primaryButton.leadingAnchor constraintEqualToAnchor:self.leadingAnchor
+ constant:kHorizontalPadding],
+ [self.trailingAnchor constraintEqualToAnchor:_primaryButton.trailingAnchor
+ constant:kHorizontalPadding],
+
+ // Fix width and height.
+ [_primaryButton.heightAnchor constraintEqualToConstant:kButtonHeight],
+ ]];
+ _coldStartConstraints = @[
+ // Set vertical anchors.
+ [self.bottomAnchor
+ constraintEqualToAnchor:_primaryButton.bottomAnchor
+ constant:kVerticalPadding + kButtonVerticalPadding],
+
+ // Fix width and height.
+ [_imageView.widthAnchor constraintEqualToConstant:kChromeImageFixedSize],
+ [_imageView.heightAnchor constraintEqualToConstant:kChromeImageFixedSize],
+ ];
+ _warmStartConstraints = @[
+ // Set vertical anchors.
+ [_secondaryButton.topAnchor
+ constraintEqualToAnchor:_primaryButton.bottomAnchor
+ constant:kButtonVerticalPadding * 2],
+ [self.bottomAnchor
+ constraintEqualToAnchor:_secondaryButton.bottomAnchor
+ constant:kVerticalPadding + kButtonVerticalPadding],
+
+ // Set horizontal anchors.
+ [self.trailingAnchor constraintEqualToAnchor:_secondaryButton.trailingAnchor
+ constant:kHorizontalPadding],
+ [_secondaryButton.centerXAnchor constraintEqualToAnchor:self.centerXAnchor],
+ [_secondaryButton.leadingAnchor constraintEqualToAnchor:self.leadingAnchor
+ constant:kHorizontalPadding],
+
+ // Fix width and height.
+ [_imageView.widthAnchor constraintEqualToConstant:kProfileImageFixedSize],
+ [_imageView.heightAnchor constraintEqualToConstant:kProfileImageFixedSize],
+ [_secondaryButton.heightAnchor constraintEqualToConstant:kButtonHeight],
+ ];
+ [NSLayoutConstraint deactivateConstraints:_coldStartConstraints];
msarda 2017/03/16 22:15:31 Why is this needed?
jlebel 2017/03/21 17:22:29 Done.
+ _mode = SigninPromoViewWarmStartMode;
+}
+
+- (void)setMode:(SigninPromoViewMode)mode {
+ if (mode == _mode) {
+ return;
+ }
+ _mode = mode;
+ switch (_mode) {
+ case SigninPromoViewColdStartMode:
+ [self activateColdMode];
+ return;
+ case SigninPromoViewWarmStartMode:
+ [self activateWarmMode];
+ return;
+ }
+ NOTREACHED();
+}
+
+- (void)activateColdMode {
+ // TODO(jlebel) Needs to set the chrome/chromium icon in |imageView|.
+ [NSLayoutConstraint deactivateConstraints:_warmStartConstraints];
+ [NSLayoutConstraint activateConstraints:_coldStartConstraints];
+ _secondaryButton.hidden = YES;
+}
+
+- (void)activateWarmMode {
+ [NSLayoutConstraint deactivateConstraints:_coldStartConstraints];
+ [NSLayoutConstraint activateConstraints:_warmStartConstraints];
+ _secondaryButton.hidden = NO;
+}
+
+- (void)setProfileImage:(UIImage*)image {
+ if (SigninPromoViewColdStartMode == _mode) {
+ return;
+ }
+ _imageView.image = CircularImageFromImage(image, kProfileImageFixedSize);
+}
+
+- (void)accessibilityPrimaryAction:(id)unused {
+ [_primaryButton sendActionsForControlEvents:UIControlEventTouchUpInside];
+}
+
+- (void)accessibilitySecondaryAction:(id)unused {
+ [_secondaryButton sendActionsForControlEvents:UIControlEventTouchUpInside];
+}
+
+- (CGFloat)horizontalPadding {
+ return kHorizontalPadding;
+}
+
+#pragma mark - NSObject(Accessibility)
+
+- (NSArray<UIAccessibilityCustomAction*>*)accessibilityCustomActions {
+ NSString* primaryActionName =
+ [_primaryButton titleForState:UIControlStateNormal];
+ UIAccessibilityCustomAction* primaryCustomAction =
+ [[UIAccessibilityCustomAction alloc]
+ initWithName:primaryActionName
+ target:self
+ selector:@selector(accessibilityPrimaryAction:)];
+ if (_mode == SigninPromoViewColdStartMode) {
+ return @[ primaryCustomAction ];
+ }
+ NSString* secondaryActionName =
+ [_secondaryButton titleForState:UIControlStateNormal];
+ UIAccessibilityCustomAction* secondaryCustomAction =
+ [[UIAccessibilityCustomAction alloc]
+ initWithName:secondaryActionName
+ target:self
+ selector:@selector(accessibilitySecondaryAction:)];
+ return @[ primaryCustomAction, secondaryCustomAction ];
+}
+
+- (NSString*)accessibilityLabel {
+ return _textLabel.text;
+}
+
+@end

Powered by Google App Engine
This is Rietveld 408576698