| 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/price_item.h" | 5 #import "ios/chrome/browser/payments/cells/price_item.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" | 9 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" |
| 10 #import "ios/third_party/material_components_ios/src/components/Typography/src/M
aterialTypography.h" | 10 #import "ios/third_party/material_components_ios/src/components/Typography/src/M
aterialTypography.h" |
| 11 | 11 |
| 12 #if !defined(__has_feature) || !__has_feature(objc_arc) | 12 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 13 #error "This file requires ARC support." | 13 #error "This file requires ARC support." |
| 14 #endif | 14 #endif |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 // Padding used on the leading and trailing edges of the cell and in between the | 18 // Padding used on the leading and trailing edges of the cell and in between the |
| 19 // labels. | 19 // labels. |
| 20 const CGFloat kHorizontalPadding = 16; | 20 const CGFloat kHorizontalPadding = 16; |
| 21 | 21 |
| 22 // Minimum proportion of the available width to guarantee to the labels. | 22 // Minimum proportion of the available width to guarantee to the labels. |
| 23 const CGFloat kMinWidthRatio = 0.5f; | 23 const CGFloat kMinWidthRatio = 0.5f; |
| 24 } | 24 } |
| 25 | 25 |
| 26 @implementation PriceItem | 26 @implementation PriceItem |
| 27 | 27 |
| 28 @synthesize accessoryType = _accessoryType; | |
| 29 @synthesize item = _item; | 28 @synthesize item = _item; |
| 30 @synthesize notification = _notification; | 29 @synthesize notification = _notification; |
| 31 @synthesize price = _price; | 30 @synthesize price = _price; |
| 32 | 31 |
| 33 #pragma mark CollectionViewItem | 32 #pragma mark CollectionViewItem |
| 34 | 33 |
| 35 - (instancetype)initWithType:(NSInteger)type { | 34 - (instancetype)initWithType:(NSInteger)type { |
| 36 self = [super initWithType:type]; | 35 self = [super initWithType:type]; |
| 37 if (self) { | 36 if (self) { |
| 38 self.cellClass = [PriceCell class]; | 37 self.cellClass = [PriceCell class]; |
| 39 } | 38 } |
| 40 return self; | 39 return self; |
| 41 } | 40 } |
| 42 | 41 |
| 43 - (void)configureCell:(PriceCell*)cell { | 42 - (void)configureCell:(PriceCell*)cell { |
| 44 [super configureCell:cell]; | 43 [super configureCell:cell]; |
| 45 cell.accessoryType = self.accessoryType; | |
| 46 cell.itemLabel.text = self.item; | 44 cell.itemLabel.text = self.item; |
| 47 cell.notificationLabel.text = self.notification; | 45 cell.notificationLabel.text = self.notification; |
| 48 cell.priceLabel.text = self.price; | 46 cell.priceLabel.text = self.price; |
| 49 } | 47 } |
| 50 | 48 |
| 51 @end | 49 @end |
| 52 | 50 |
| 53 @implementation PriceCell { | 51 @implementation PriceCell { |
| 54 NSLayoutConstraint* _itemLabelWidthConstraint; | 52 NSLayoutConstraint* _itemLabelWidthConstraint; |
| 55 NSLayoutConstraint* _notificationLabelWidthConstraint; | 53 NSLayoutConstraint* _notificationLabelWidthConstraint; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 self.notificationLabelTargetWidth; | 156 self.notificationLabelTargetWidth; |
| 159 | 157 |
| 160 // Now invoke the layout. | 158 // Now invoke the layout. |
| 161 [super layoutSubviews]; | 159 [super layoutSubviews]; |
| 162 } | 160 } |
| 163 | 161 |
| 164 #pragma mark - UICollectionReusableView | 162 #pragma mark - UICollectionReusableView |
| 165 | 163 |
| 166 - (void)prepareForReuse { | 164 - (void)prepareForReuse { |
| 167 [super prepareForReuse]; | 165 [super prepareForReuse]; |
| 168 self.accessoryType = MDCCollectionViewCellAccessoryNone; | |
| 169 self.itemLabel.text = nil; | 166 self.itemLabel.text = nil; |
| 170 self.notificationLabel.text = nil; | 167 self.notificationLabel.text = nil; |
| 171 self.priceLabel.text = nil; | 168 self.priceLabel.text = nil; |
| 172 } | 169 } |
| 173 | 170 |
| 174 #pragma mark - NSObject(Accessibility) | 171 #pragma mark - NSObject(Accessibility) |
| 175 | 172 |
| 176 - (NSString*)accessibilityLabel { | 173 - (NSString*)accessibilityLabel { |
| 177 return [NSString stringWithFormat:@"%@, %@, %@", self.itemLabel.text, | 174 return [NSString stringWithFormat:@"%@, %@, %@", self.itemLabel.text, |
| 178 self.notificationLabel.text, | 175 self.notificationLabel.text, |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 if (itemLabelWidth + notificationLabelWidth + priceLabelWidth <= | 235 if (itemLabelWidth + notificationLabelWidth + priceLabelWidth <= |
| 239 availableWidth) { | 236 availableWidth) { |
| 240 return priceLabelWidth; | 237 return priceLabelWidth; |
| 241 } else { | 238 } else { |
| 242 return std::max(availableWidth - itemLabelWidth - notificationLabelWidth, | 239 return std::max(availableWidth - itemLabelWidth - notificationLabelWidth, |
| 243 std::min(availableWidth * kMinWidthRatio, priceLabelWidth)); | 240 std::min(availableWidth * kMinWidthRatio, priceLabelWidth)); |
| 244 } | 241 } |
| 245 } | 242 } |
| 246 | 243 |
| 247 @end | 244 @end |
| OLD | NEW |