Chromium Code Reviews| 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/payments/cells/payments_text_item.h" | 5 #import "ios/chrome/browser/payments/cells/payments_text_item.h" |
| 6 | 6 |
| 7 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat erialPalettes.h" | 7 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat erialPalettes.h" |
| 8 #import "ios/third_party/material_components_ios/src/components/Typography/src/M aterialTypography.h" | 8 #import "ios/third_party/material_components_ios/src/components/Typography/src/M aterialTypography.h" |
| 9 | 9 |
| 10 #if !defined(__has_feature) || !__has_feature(objc_arc) | 10 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 11 #error "This file requires ARC support." | 11 #error "This file requires ARC support." |
| 12 #endif | 12 #endif |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 // Padding of the leading and trailing edges of the cell. | 15 // Padding of the leading and trailing edges of the cell. |
| 16 const CGFloat kHorizontalPadding = 16; | 16 const CGFloat kHorizontalPadding = 16; |
| 17 | 17 |
| 18 // Padding of the top and bottom edges of the cell. | 18 // Padding of the top and bottom edges of the cell. |
| 19 const CGFloat kVerticalPadding = 16; | 19 const CGFloat kVerticalPadding = 16; |
| 20 | 20 |
| 21 // Spacing between the image and the text label. | 21 // Spacing between the image and the text label. |
| 22 const CGFloat kHorizontalSpacingBetweenImageAndLabel = 8; | 22 const CGFloat kHorizontalSpacingBetweenImageAndLabel = 8; |
| 23 } // namespace | 23 } // namespace |
| 24 | 24 |
| 25 @implementation PaymentsTextItem | 25 @implementation PaymentsTextItem |
| 26 | 26 |
| 27 @synthesize text = _text; | 27 @synthesize text = _text; |
| 28 @synthesize image = _image; | 28 @synthesize image = _image; |
| 29 @synthesize textFont = _textFont; | |
| 30 @synthesize textColor = _textColor; | |
| 29 | 31 |
| 30 #pragma mark CollectionViewItem | 32 #pragma mark CollectionViewItem |
| 31 | 33 |
| 32 - (instancetype)initWithType:(NSInteger)type { | 34 - (instancetype)initWithType:(NSInteger)type { |
| 33 self = [super initWithType:type]; | 35 self = [super initWithType:type]; |
| 34 if (self) { | 36 if (self) { |
| 35 self.cellClass = [PaymentsTextCell class]; | 37 self.cellClass = [PaymentsTextCell class]; |
| 36 } | 38 } |
| 37 return self; | 39 return self; |
| 38 } | 40 } |
| 39 | 41 |
| 42 - (UIFont*)textFont { | |
| 43 if (!_textFont) { | |
| 44 _textFont = [MDCTypography body1Font]; | |
| 45 } | |
| 46 return _textFont; | |
| 47 } | |
| 48 | |
| 49 - (UIColor*)textColor { | |
| 50 if (!_textColor) { | |
| 51 _textColor = [[MDCPalette greyPalette] tint900]; | |
| 52 } | |
| 53 return _textColor; | |
| 54 } | |
| 55 | |
| 40 - (void)configureCell:(PaymentsTextCell*)cell { | 56 - (void)configureCell:(PaymentsTextCell*)cell { |
| 41 [super configureCell:cell]; | 57 [super configureCell:cell]; |
| 42 cell.textLabel.text = self.text; | 58 cell.textLabel.text = self.text; |
| 43 cell.imageView.image = self.image; | 59 cell.imageView.image = self.image; |
| 60 | |
| 61 // Styling. | |
| 62 cell.textLabel.font = self.textFont; | |
| 63 cell.textLabel.textColor = self.textColor; | |
| 64 cell.textLabel.numberOfLines = 0; | |
|
gambard
2017/04/11 15:23:25
For me the item sets only the properties that migh
lpromero
2017/04/11 15:59:06
+1
Moe
2017/04/14 06:05:49
Done.
| |
| 65 cell.textLabel.lineBreakMode = NSLineBreakByWordWrapping; | |
| 44 } | 66 } |
| 45 | 67 |
| 46 @end | 68 @end |
| 47 | 69 |
| 48 @interface PaymentsTextCell () { | 70 @interface PaymentsTextCell () { |
| 49 NSLayoutConstraint* _textLeadingAnchorConstraint; | 71 NSLayoutConstraint* _textLeadingAnchorConstraint; |
| 50 NSLayoutConstraint* _imageLeadingAnchorConstraint; | 72 NSLayoutConstraint* _imageLeadingAnchorConstraint; |
| 51 } | 73 } |
| 52 @end | 74 @end |
| 53 | 75 |
| 54 @implementation PaymentsTextCell | 76 @implementation PaymentsTextCell |
| 55 | 77 |
| 56 @synthesize textLabel = _textLabel; | 78 @synthesize textLabel = _textLabel; |
| 57 @synthesize imageView = _imageView; | 79 @synthesize imageView = _imageView; |
| 58 | 80 |
| 59 - (instancetype)initWithFrame:(CGRect)frame { | 81 - (instancetype)initWithFrame:(CGRect)frame { |
| 60 self = [super initWithFrame:frame]; | 82 self = [super initWithFrame:frame]; |
| 61 if (self) { | 83 if (self) { |
| 62 self.isAccessibilityElement = YES; | 84 self.isAccessibilityElement = YES; |
| 63 [self addSubviews]; | 85 [self addSubviews]; |
| 64 [self setDefaultViewStyling]; | |
| 65 [self setViewConstraints]; | 86 [self setViewConstraints]; |
| 66 } | 87 } |
| 67 return self; | 88 return self; |
| 68 } | 89 } |
| 69 | 90 |
| 70 // Create and add subviews. | 91 // Create and add subviews. |
| 71 - (void)addSubviews { | 92 - (void)addSubviews { |
| 72 UIView* contentView = self.contentView; | 93 UIView* contentView = self.contentView; |
| 73 contentView.clipsToBounds = YES; | 94 contentView.clipsToBounds = YES; |
| 74 | 95 |
| 75 _textLabel = [[UILabel alloc] init]; | 96 _textLabel = [[UILabel alloc] init]; |
| 76 _textLabel.translatesAutoresizingMaskIntoConstraints = NO; | 97 _textLabel.translatesAutoresizingMaskIntoConstraints = NO; |
| 77 [contentView addSubview:_textLabel]; | 98 [contentView addSubview:_textLabel]; |
| 78 | 99 |
| 79 _imageView = [[UIImageView alloc] initWithFrame:CGRectZero]; | 100 _imageView = [[UIImageView alloc] initWithFrame:CGRectZero]; |
| 80 _imageView.translatesAutoresizingMaskIntoConstraints = NO; | 101 _imageView.translatesAutoresizingMaskIntoConstraints = NO; |
| 81 [contentView addSubview:_imageView]; | 102 [contentView addSubview:_imageView]; |
| 82 } | 103 } |
| 83 | 104 |
| 84 // Set default font and text colors for labels. | |
| 85 - (void)setDefaultViewStyling { | |
| 86 _textLabel.font = [MDCTypography body1Font]; | |
| 87 _textLabel.textColor = [[MDCPalette greyPalette] tint900]; | |
| 88 _textLabel.numberOfLines = 0; | |
| 89 _textLabel.lineBreakMode = NSLineBreakByWordWrapping; | |
| 90 } | |
| 91 | |
| 92 // Set constraints on subviews. | 105 // Set constraints on subviews. |
| 93 - (void)setViewConstraints { | 106 - (void)setViewConstraints { |
| 94 UIView* contentView = self.contentView; | 107 UIView* contentView = self.contentView; |
| 95 | 108 |
| 96 _textLeadingAnchorConstraint = [_textLabel.leadingAnchor | 109 _textLeadingAnchorConstraint = [_textLabel.leadingAnchor |
| 97 constraintEqualToAnchor:_imageView.trailingAnchor]; | 110 constraintEqualToAnchor:_imageView.trailingAnchor]; |
| 98 _imageLeadingAnchorConstraint = [_imageView.leadingAnchor | 111 _imageLeadingAnchorConstraint = [_imageView.leadingAnchor |
| 99 constraintEqualToAnchor:contentView.leadingAnchor | 112 constraintEqualToAnchor:contentView.leadingAnchor |
| 100 constant:kHorizontalPadding]; | 113 constant:kHorizontalPadding]; |
| 101 | 114 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 145 self.imageView.image = nil; | 158 self.imageView.image = nil; |
| 146 } | 159 } |
| 147 | 160 |
| 148 #pragma mark - NSObject(Accessibility) | 161 #pragma mark - NSObject(Accessibility) |
| 149 | 162 |
| 150 - (NSString*)accessibilityLabel { | 163 - (NSString*)accessibilityLabel { |
| 151 return [NSString stringWithFormat:@"%@", self.textLabel.text]; | 164 return [NSString stringWithFormat:@"%@", self.textLabel.text]; |
| 152 } | 165 } |
| 153 | 166 |
| 154 @end | 167 @end |
| OLD | NEW |