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

Side by Side Diff: ios/chrome/browser/ui/settings/cells/account_signin_item.mm

Issue 2589583003: Upstream Chrome on iOS source code [7/11]. (Closed)
Patch Set: Created 4 years 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #import "ios/chrome/browser/ui/settings/cells/account_signin_item.h"
6
7 #include "ios/chrome/grit/ios_chromium_strings.h"
8 #include "ios/chrome/grit/ios_strings.h"
9 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat erialPalettes.h"
10 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF ontLoader.h"
11 #include "ui/base/l10n/l10n_util.h"
12
13 #if !defined(__has_feature) || !__has_feature(objc_arc)
14 #error "This file requires ARC support."
15 #endif
16
17 namespace {
18 // Padding used on the leading and trailing edges of the cell.
19 const CGFloat kHorizontalPadding = 16;
20
21 // Padding used between the image and text.
22 const CGFloat kHorizontalPaddingBetweenImageAndText = 10;
23
24 // Image fixed horizontal size.
25 const CGFloat kHorizontalImageFixedSize = 40;
26 }
27
28 @implementation AccountSignInItem
29
30 @synthesize image = _image;
31
32 - (instancetype)initWithType:(NSInteger)type {
33 self = [super initWithType:type];
34 if (self) {
35 self.cellClass = [AccountSignInCell class];
36 self.accessibilityTraits |= UIAccessibilityTraitButton;
37 }
38 return self;
39 }
40
41 #pragma mark - CollectionViewItem
42
43 - (void)configureCell:(AccountSignInCell*)cell {
44 [super configureCell:cell];
45 cell.textLabel.text =
46 l10n_util::GetNSString(IDS_IOS_SIGN_IN_TO_CHROME_SETTING_TITLE);
47 cell.detailTextLabel.text =
48 l10n_util::GetNSString(IDS_IOS_SIGN_IN_TO_CHROME_SETTING_SUBTITLE);
49 cell.imageView.image = self.image;
50 }
51
52 @end
53
54 @implementation AccountSignInCell
55
56 @synthesize textLabel = _textLabel;
57 @synthesize detailTextLabel = _detailTextLabel;
58 @synthesize imageView = _imageView;
59
60 - (instancetype)initWithFrame:(CGRect)frame {
61 self = [super initWithFrame:frame];
62 if (self) {
63 self.isAccessibilityElement = YES;
64 [self addSubviews];
65 [self setDefaultViewStyling];
66 [self setViewConstraints];
67 }
68 return self;
69 }
70
71 // Create and add subviews.
72 - (void)addSubviews {
73 UIView* contentView = self.contentView;
74 contentView.clipsToBounds = YES;
75
76 _imageView = [[UIImageView alloc] init];
77 _imageView.translatesAutoresizingMaskIntoConstraints = NO;
78 [contentView addSubview:_imageView];
79
80 _textLabel = [[UILabel alloc] init];
81 _textLabel.translatesAutoresizingMaskIntoConstraints = NO;
82 [contentView addSubview:_textLabel];
83
84 _detailTextLabel = [[UILabel alloc] init];
85 _detailTextLabel.translatesAutoresizingMaskIntoConstraints = NO;
86 [_detailTextLabel setNumberOfLines:3];
87 [contentView addSubview:_detailTextLabel];
88 }
89
90 - (void)setDefaultViewStyling {
91 _imageView.contentMode = UIViewContentModeCenter;
92 _imageView.layer.masksToBounds = YES;
93 _imageView.contentMode = UIViewContentModeScaleAspectFit;
94 _textLabel.font = [[MDFRobotoFontLoader sharedInstance] mediumFontOfSize:14];
95 _textLabel.textColor = [[MDCPalette greyPalette] tint900];
96 _detailTextLabel.font =
97 [[MDFRobotoFontLoader sharedInstance] regularFontOfSize:14];
98 _detailTextLabel.textColor = [[MDCPalette greyPalette] tint500];
99 }
100
101 - (void)setViewConstraints {
102 UIView* contentView = self.contentView;
103
104 // This view is used to center the two leading textLabels.
105 UIView* verticalCenteringView = [[UIView alloc] init];
106 verticalCenteringView.translatesAutoresizingMaskIntoConstraints = NO;
107 [contentView addSubview:verticalCenteringView];
108
109 [NSLayoutConstraint activateConstraints:@[
110 // Set leading anchors.
111 [_imageView.leadingAnchor constraintEqualToAnchor:contentView.leadingAnchor
112 constant:kHorizontalPadding],
113 [_detailTextLabel.leadingAnchor
114 constraintEqualToAnchor:_textLabel.leadingAnchor],
115 [_textLabel.leadingAnchor
116 constraintEqualToAnchor:_imageView.trailingAnchor
117 constant:kHorizontalPaddingBetweenImageAndText],
118
119 // Fix image widths.
120 [_imageView.widthAnchor
121 constraintEqualToConstant:kHorizontalImageFixedSize],
122
123 // Set vertical anchors. This approach assumes the cell height is set by
124 // the view controller. Contents are pinned to centerY, rather than pushing
125 // against the top/bottom boundaries.
126 [_imageView.centerYAnchor
127 constraintEqualToAnchor:contentView.centerYAnchor],
128 [_textLabel.topAnchor
129 constraintEqualToAnchor:verticalCenteringView.topAnchor],
130 [_textLabel.bottomAnchor
131 constraintEqualToAnchor:_detailTextLabel.topAnchor],
132 [_detailTextLabel.bottomAnchor
133 constraintEqualToAnchor:verticalCenteringView.bottomAnchor],
134 [verticalCenteringView.centerYAnchor
135 constraintEqualToAnchor:contentView.centerYAnchor],
136 // Set trailing anchors.
137 [_detailTextLabel.trailingAnchor
138 constraintEqualToAnchor:contentView.trailingAnchor
139 constant:-kHorizontalPadding],
140 [_textLabel.trailingAnchor
141 constraintLessThanOrEqualToAnchor:contentView.trailingAnchor
142 constant:-kHorizontalPadding],
143 ]];
144
145 // This is needed so the image doesn't get pushed out if both text and detail
146 // are long.
147 [_textLabel
148 setContentCompressionResistancePriority:UILayoutPriorityDefaultLow
149 forAxis:UILayoutConstraintAxisHorizontal];
150 [_detailTextLabel
151 setContentCompressionResistancePriority:UILayoutPriorityDefaultLow
152 forAxis:UILayoutConstraintAxisHorizontal];
153 }
154
155 #pragma mark - UICollectionReusableView
156
157 - (void)prepareForReuse {
158 [super prepareForReuse];
159 _imageView.image = nil;
160 self.textLabel.text = nil;
161 self.detailTextLabel.text = nil;
162 }
163
164 #pragma mark - NSObject(Accessibility)
165
166 - (NSString*)accessibilityLabel {
167 return l10n_util::GetNSString(IDS_IOS_SIGN_IN_TO_CHROME_SETTING_TITLE);
168 }
169
170 - (NSString*)accessibilityValue {
171 return [NSString stringWithFormat:@"%@, %@", self.textLabel.text,
172 self.detailTextLabel.text];
173 }
174
175 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698