OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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/collection_view/cells/collection_view_text_item.h " | 5 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h " |
6 | 6 |
7 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_cell.h " | 7 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_cell.h " |
8 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat erialPalettes.h" | |
9 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF ontLoader.h" | |
10 | 8 |
11 #if !defined(__has_feature) || !__has_feature(objc_arc) | 9 #if !defined(__has_feature) || !__has_feature(objc_arc) |
12 #error "This file requires ARC support." | 10 #error "This file requires ARC support." |
13 #endif | 11 #endif |
14 | 12 |
15 @implementation CollectionViewTextItem | 13 @implementation CollectionViewTextItem |
16 | 14 |
17 @synthesize accessoryType = _accessoryType; | 15 @synthesize accessoryType = _accessoryType; |
18 @synthesize text = _text; | 16 @synthesize text = _text; |
19 @synthesize detailText = _detailText; | 17 @synthesize detailText = _detailText; |
20 @synthesize textFont = _textFont; | |
21 @synthesize textColor = _textColor; | |
22 @synthesize numberOfTextLines = _numberOfTextLines; | 18 @synthesize numberOfTextLines = _numberOfTextLines; |
23 @synthesize detailTextFont = _detailTextFont; | |
24 @synthesize detailTextColor = _detailTextColor; | |
25 @synthesize numberOfDetailTextLines = _numberOfDetailTextLines; | 19 @synthesize numberOfDetailTextLines = _numberOfDetailTextLines; |
26 | 20 |
27 - (instancetype)initWithType:(NSInteger)type { | 21 - (instancetype)initWithType:(NSInteger)type { |
28 self = [super initWithType:type]; | 22 self = [super initWithType:type]; |
29 if (self) { | 23 if (self) { |
30 self.cellClass = [CollectionViewTextCell class]; | 24 self.cellClass = [CollectionViewTextCell class]; |
31 _numberOfTextLines = 1; | 25 _numberOfTextLines = 1; |
32 _numberOfDetailTextLines = 1; | 26 _numberOfDetailTextLines = 1; |
33 } | 27 } |
34 return self; | 28 return self; |
35 } | 29 } |
36 | 30 |
37 - (UIFont*)textFont { | |
38 if (!_textFont) { | |
39 _textFont = [[MDFRobotoFontLoader sharedInstance] mediumFontOfSize:14]; | |
lpromero
2017/04/13 17:44:26
Instead of moving these defaults in all the View C
Moe
2017/04/13 18:48:58
If the VCs only override the properties, don't we
Moe
2017/04/13 19:33:38
Done.
lpromero
2017/04/13 20:24:55
It's sort of the point of having the default be li
| |
40 } | |
41 return _textFont; | |
42 } | |
43 | |
44 - (UIColor*)textColor { | |
45 if (!_textColor) { | |
46 _textColor = [[MDCPalette greyPalette] tint900]; | |
47 } | |
48 return _textColor; | |
49 } | |
50 | |
51 - (UIFont*)detailTextFont { | |
52 if (!_detailTextFont) { | |
53 _detailTextFont = | |
54 [[MDFRobotoFontLoader sharedInstance] regularFontOfSize:14]; | |
55 } | |
56 return _detailTextFont; | |
57 } | |
58 | |
59 - (UIColor*)detailTextColor { | |
60 if (!_detailTextColor) { | |
61 _detailTextColor = [[MDCPalette greyPalette] tint500]; | |
62 } | |
63 return _detailTextColor; | |
64 } | |
65 | |
66 #pragma mark CollectionViewItem | 31 #pragma mark CollectionViewItem |
67 | 32 |
68 - (void)configureCell:(CollectionViewTextCell*)cell { | 33 - (void)configureCell:(CollectionViewTextCell*)cell { |
69 [super configureCell:cell]; | 34 [super configureCell:cell]; |
70 cell.accessoryType = self.accessoryType; | 35 cell.accessoryType = self.accessoryType; |
71 cell.textLabel.text = self.text; | 36 cell.textLabel.text = self.text; |
72 cell.detailTextLabel.text = self.detailText; | 37 cell.detailTextLabel.text = self.detailText; |
73 cell.isAccessibilityElement = YES; | 38 cell.isAccessibilityElement = YES; |
74 if (self.detailText.length == 0) { | 39 if (self.detailText.length == 0) { |
75 cell.accessibilityLabel = self.text; | 40 cell.accessibilityLabel = self.text; |
76 } else { | 41 } else { |
77 cell.accessibilityLabel = | 42 cell.accessibilityLabel = |
78 [NSString stringWithFormat:@"%@, %@", self.text, self.detailText]; | 43 [NSString stringWithFormat:@"%@, %@", self.text, self.detailText]; |
79 } | 44 } |
80 | 45 |
81 // Styling. | 46 // Styling. |
82 cell.textLabel.font = self.textFont; | |
83 cell.textLabel.textColor = self.textColor; | |
84 cell.textLabel.numberOfLines = self.numberOfTextLines; | 47 cell.textLabel.numberOfLines = self.numberOfTextLines; |
85 cell.detailTextLabel.font = self.detailTextFont; | |
86 cell.detailTextLabel.textColor = self.detailTextColor; | |
87 cell.detailTextLabel.numberOfLines = self.numberOfDetailTextLines; | 48 cell.detailTextLabel.numberOfLines = self.numberOfDetailTextLines; |
88 } | 49 } |
89 | 50 |
90 @end | 51 @end |
OLD | NEW |