OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import "ios/chrome/browser/ui/authentication/signin_promo_view.h" | 5 #import "ios/chrome/browser/ui/authentication/signin_promo_view.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" | 8 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" |
9 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h" | 9 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h" |
10 #import "ios/chrome/browser/ui/commands/show_signin_command.h" | 10 #import "ios/chrome/browser/ui/commands/show_signin_command.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 // Horizontal padding for label and buttons. | 22 // Horizontal padding for label and buttons. |
23 const CGFloat kHorizontalPadding = 40; | 23 const CGFloat kHorizontalPadding = 40; |
24 // Vertical padding for the image and the label. | 24 // Vertical padding for the image and the label. |
25 const CGFloat kVerticalPadding = 12; | 25 const CGFloat kVerticalPadding = 12; |
26 // Vertical padding for buttons. | 26 // Vertical padding for buttons. |
27 const CGFloat kButtonVerticalPadding = 6; | 27 const CGFloat kButtonVerticalPadding = 6; |
28 // Image size for warm state. | 28 // Image size for warm state. |
29 const CGFloat kProfileImageFixedSize = 48; | 29 const CGFloat kProfileImageFixedSize = 48; |
30 // Button height. | 30 // Button height. |
31 const CGFloat kButtonHeight = 36; | 31 const CGFloat kButtonHeight = 36; |
| 32 // Dismiss button size. |
| 33 const CGFloat kDismissButtonSize = 24; |
32 } | 34 } |
33 | 35 |
34 @implementation SigninPromoView { | 36 @implementation SigninPromoView { |
35 NSArray<NSLayoutConstraint*>* _coldStateConstraints; | 37 NSArray<NSLayoutConstraint*>* _coldStateConstraints; |
36 NSArray<NSLayoutConstraint*>* _warmStateConstraints; | 38 NSArray<NSLayoutConstraint*>* _warmStateConstraints; |
37 } | 39 } |
38 | 40 |
39 @synthesize mode = _mode; | 41 @synthesize mode = _mode; |
40 @synthesize imageView = _imageView; | 42 @synthesize imageView = _imageView; |
41 @synthesize textLabel = _textLabel; | 43 @synthesize textLabel = _textLabel; |
42 @synthesize primaryButton = _primaryButton; | 44 @synthesize primaryButton = _primaryButton; |
43 @synthesize secondaryButton = _secondaryButton; | 45 @synthesize secondaryButton = _secondaryButton; |
| 46 @synthesize dismissButton = _dismissButton; |
44 @synthesize sendChromeCommand = _sendChromeCommand; | 47 @synthesize sendChromeCommand = _sendChromeCommand; |
45 | 48 |
46 - (instancetype)initWithFrame:(CGRect)frame { | 49 - (instancetype)initWithFrame:(CGRect)frame { |
47 self = [super initWithFrame:frame]; | 50 self = [super initWithFrame:frame]; |
48 if (self) { | 51 if (self) { |
49 self.isAccessibilityElement = YES; | 52 self.isAccessibilityElement = YES; |
50 | 53 |
51 // Adding subviews. | 54 // Adding subviews. |
52 self.clipsToBounds = YES; | 55 self.clipsToBounds = YES; |
53 _imageView = [[UIImageView alloc] init]; | 56 _imageView = [[UIImageView alloc] init]; |
(...skipping 14 matching lines...) Expand all Loading... |
68 [self addSubview:_primaryButton]; | 71 [self addSubview:_primaryButton]; |
69 | 72 |
70 _secondaryButton = [[MDCFlatButton alloc] init]; | 73 _secondaryButton = [[MDCFlatButton alloc] init]; |
71 _secondaryButton.translatesAutoresizingMaskIntoConstraints = NO; | 74 _secondaryButton.translatesAutoresizingMaskIntoConstraints = NO; |
72 _secondaryButton.accessibilityIdentifier = @"signin_promo_secondary_button"; | 75 _secondaryButton.accessibilityIdentifier = @"signin_promo_secondary_button"; |
73 [_secondaryButton addTarget:self | 76 [_secondaryButton addTarget:self |
74 action:@selector(onSecondaryButtonAction:) | 77 action:@selector(onSecondaryButtonAction:) |
75 forControlEvents:UIControlEventTouchUpInside]; | 78 forControlEvents:UIControlEventTouchUpInside]; |
76 [self addSubview:_secondaryButton]; | 79 [self addSubview:_secondaryButton]; |
77 | 80 |
| 81 _dismissButton = [[UIButton alloc] |
| 82 initWithFrame:CGRectMake(0, 0, kDismissButtonSize, kDismissButtonSize)]; |
| 83 _dismissButton.translatesAutoresizingMaskIntoConstraints = NO; |
| 84 _dismissButton.hidden = YES; |
| 85 [self addSubview:_dismissButton]; |
| 86 |
78 // Adding style. | 87 // Adding style. |
79 _imageView.contentMode = UIViewContentModeCenter; | 88 _imageView.contentMode = UIViewContentModeCenter; |
80 _imageView.layer.masksToBounds = YES; | 89 _imageView.layer.masksToBounds = YES; |
81 _imageView.contentMode = UIViewContentModeScaleAspectFit; | 90 _imageView.contentMode = UIViewContentModeScaleAspectFit; |
82 | 91 |
83 _textLabel.font = [MDCTypography buttonFont]; | 92 _textLabel.font = [MDCTypography buttonFont]; |
84 _textLabel.textColor = [[MDCPalette greyPalette] tint900]; | 93 _textLabel.textColor = [[MDCPalette greyPalette] tint900]; |
85 _textLabel.numberOfLines = 0; | 94 _textLabel.numberOfLines = 0; |
86 _textLabel.textAlignment = NSTextAlignmentCenter; | 95 _textLabel.textAlignment = NSTextAlignmentCenter; |
87 | 96 |
88 [_primaryButton setBackgroundColor:[[MDCPalette cr_bluePalette] tint500] | 97 [_primaryButton setBackgroundColor:[[MDCPalette cr_bluePalette] tint500] |
89 forState:UIControlStateNormal]; | 98 forState:UIControlStateNormal]; |
90 _primaryButton.customTitleColor = [UIColor whiteColor]; | 99 _primaryButton.customTitleColor = [UIColor whiteColor]; |
91 _primaryButton.inkColor = [UIColor colorWithWhite:1 alpha:0.2]; | 100 _primaryButton.inkColor = [UIColor colorWithWhite:1 alpha:0.2]; |
92 | 101 |
93 _secondaryButton.customTitleColor = [[MDCPalette cr_bluePalette] tint500]; | 102 _secondaryButton.customTitleColor = [[MDCPalette cr_bluePalette] tint500]; |
94 _secondaryButton.uppercaseTitle = NO; | 103 _secondaryButton.uppercaseTitle = NO; |
95 | 104 |
| 105 [_dismissButton setImage:[UIImage imageNamed:@"signin_promo_dismiss_gray"] |
| 106 forState:UIControlStateNormal]; |
| 107 |
96 // Adding constraints. | 108 // Adding constraints. |
97 NSDictionary* metrics = @{ | 109 NSDictionary* metrics = @{ |
98 @"kButtonHeight" : @(kButtonHeight), | 110 @"kButtonHeight" : @(kButtonHeight), |
99 @"kButtonVerticalPadding" : @(kButtonVerticalPadding), | 111 @"kButtonVerticalPadding" : @(kButtonVerticalPadding), |
100 @"kButtonVerticalPaddingx2" : @(kButtonVerticalPadding * 2), | 112 @"kButtonVerticalPaddingx2" : @(kButtonVerticalPadding * 2), |
101 @"kHorizontalPadding" : @(kHorizontalPadding), | 113 @"kHorizontalPadding" : @(kHorizontalPadding), |
102 @"kVerticalPadding" : @(kVerticalPadding), | 114 @"kVerticalPadding" : @(kVerticalPadding), |
103 @"kVerticalPaddingx2" : @(kVerticalPadding * 2), | 115 @"kVerticalPaddingx2" : @(kVerticalPadding * 2), |
104 @"kVerticalPaddingkButtonVerticalPadding" : | 116 @"kVerticalPaddingkButtonVerticalPadding" : |
105 @(kVerticalPadding + kButtonVerticalPadding), | 117 @(kVerticalPadding + kButtonVerticalPadding), |
106 }; | 118 }; |
107 NSDictionary* views = @{ | 119 NSDictionary* views = @{ |
| 120 @"dismissButton" : _dismissButton, |
108 @"imageView" : _imageView, | 121 @"imageView" : _imageView, |
109 @"primaryButton" : _primaryButton, | 122 @"primaryButton" : _primaryButton, |
110 @"secondaryButton" : _secondaryButton, | 123 @"secondaryButton" : _secondaryButton, |
111 @"textLabel" : _textLabel, | 124 @"textLabel" : _textLabel, |
112 }; | 125 }; |
113 | 126 |
114 // Constraints shared between modes. | 127 // Constraints shared between modes. |
115 NSString* sharedVerticalConstraints = | 128 NSString* sharedVerticalConstraints = |
116 @"V:|-kVerticalPaddingx2-[imageView]-kVerticalPadding-[textLabel]-" | 129 @"V:|-kVerticalPaddingx2-[imageView]-kVerticalPadding-[textLabel]-" |
117 @"kVerticalPaddingkButtonVerticalPadding-[primaryButton(kButtonHeight)" | 130 @"kVerticalPaddingkButtonVerticalPadding-[primaryButton(kButtonHeight)" |
(...skipping 16 matching lines...) Expand all Loading... |
134 NSString* warmStateVerticalConstraints = | 147 NSString* warmStateVerticalConstraints = |
135 @"V:[primaryButton]-kButtonVerticalPaddingx2-[secondaryButton(" | 148 @"V:[primaryButton]-kButtonVerticalPaddingx2-[secondaryButton(" |
136 @"kButtonHeight)]-kVerticalPaddingkButtonVerticalPadding-|"; | 149 @"kButtonHeight)]-kVerticalPaddingkButtonVerticalPadding-|"; |
137 NSArray* warmStateVisualConstraints = @[ | 150 NSArray* warmStateVisualConstraints = @[ |
138 warmStateVerticalConstraints, | 151 warmStateVerticalConstraints, |
139 @"H:|-kHorizontalPadding-[secondaryButton]-kHorizontalPadding-|", | 152 @"H:|-kHorizontalPadding-[secondaryButton]-kHorizontalPadding-|", |
140 ]; | 153 ]; |
141 _warmStateConstraints = VisualConstraintsWithMetrics( | 154 _warmStateConstraints = VisualConstraintsWithMetrics( |
142 warmStateVisualConstraints, views, metrics); | 155 warmStateVisualConstraints, views, metrics); |
143 | 156 |
| 157 // Constraints for the dismiss button. |
| 158 NSArray* buttonVisualConstraints = |
| 159 @[ @"H:[dismissButton]-|", @"V:|-[dismissButton]" ]; |
| 160 ApplyVisualConstraints(buttonVisualConstraints, views); |
| 161 |
144 _mode = SigninPromoViewModeColdState; | 162 _mode = SigninPromoViewModeColdState; |
145 [self activateColdMode]; | 163 [self activateColdMode]; |
146 } | 164 } |
147 return self; | 165 return self; |
148 } | 166 } |
149 | 167 |
150 - (void)setMode:(SigninPromoViewMode)mode { | 168 - (void)setMode:(SigninPromoViewMode)mode { |
151 if (mode == _mode) { | 169 if (mode == _mode) { |
152 return; | 170 return; |
153 } | 171 } |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 target:self | 277 target:self |
260 selector:@selector(accessibilitySecondaryAction:)]; | 278 selector:@selector(accessibilitySecondaryAction:)]; |
261 return @[ primaryCustomAction, secondaryCustomAction ]; | 279 return @[ primaryCustomAction, secondaryCustomAction ]; |
262 } | 280 } |
263 | 281 |
264 - (NSString*)accessibilityLabel { | 282 - (NSString*)accessibilityLabel { |
265 return _textLabel.text; | 283 return _textLabel.text; |
266 } | 284 } |
267 | 285 |
268 @end | 286 @end |
OLD | NEW |