Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #import "ios/chrome/browser/ui/authentication/signin_promo_item.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #import "ios/chrome/browser/ui/authentication/signin_promo_view.h" | |
| 9 #import "ios/chrome/browser/ui/uikit_ui_util.h" | |
| 10 #include "ios/chrome/grit/ios_chromium_strings.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 @implementation SigninPromoItem | |
| 18 | |
| 19 @synthesize signinPromoViewConfigurator = _signinPromoViewConfigurator; | |
| 20 | |
| 21 - (instancetype)initWithType:(NSInteger)type | |
| 22 signinPromoViewConfigurator: | |
| 23 (id<SigninPromoViewConfigurator>)signinPromoViewConfigurator { | |
| 24 self = [super initWithType:type]; | |
| 25 if (self) { | |
| 26 self.cellClass = [SigninPromoCell class]; | |
| 27 _signinPromoViewConfigurator = signinPromoViewConfigurator; | |
| 28 } | |
| 29 return self; | |
| 30 } | |
| 31 | |
| 32 - (instancetype)initWithType:(NSInteger)type { | |
|
lpromero
2017/03/24 10:36:19
No need for this runtime check. The compiler alrea
jlebel
2017/03/24 20:59:08
Done.
| |
| 33 NOTREACHED(); | |
| 34 return nil; | |
| 35 } | |
| 36 | |
| 37 #pragma mark - CollectionViewItem | |
| 38 | |
| 39 - (void)configureCell:(SigninPromoCell*)cell { | |
| 40 [super configureCell:cell]; | |
| 41 cell.signinPromoView.textLabel.text = | |
| 42 l10n_util::GetNSString(IDS_IOS_SIGNIN_PROMO_SETTINGS); | |
| 43 [_signinPromoViewConfigurator configureSigninPromoView:cell.signinPromoView]; | |
| 44 } | |
| 45 | |
| 46 @end | |
| 47 | |
| 48 @implementation SigninPromoCell | |
| 49 | |
| 50 @synthesize signinPromoView = _signinPromoView; | |
| 51 | |
| 52 - (instancetype)initWithFrame:(CGRect)frame { | |
| 53 self = [super initWithFrame:frame]; | |
| 54 if (self) { | |
| 55 [self addSubviews]; | |
|
msarda
2017/03/22 12:18:38
I think calling this method from the constructor i
lpromero
2017/03/24 10:36:19
Agreed. We have some instances of cells that use s
jlebel
2017/03/24 20:59:08
Done.
| |
| 56 } | |
| 57 return self; | |
| 58 } | |
| 59 | |
| 60 - (void)addSubviews { | |
| 61 UIView* contentView = self.contentView; | |
| 62 | |
|
msarda
2017/03/22 12:18:38
Optional nit: Kill empty line.
jlebel
2017/03/24 20:59:08
Done.
| |
| 63 _signinPromoView = [[SigninPromoView alloc] initWithFrame:self.bounds]; | |
| 64 [contentView addSubview:_signinPromoView]; | |
| 65 AddSameSizeConstraint(_signinPromoView, contentView); | |
| 66 } | |
| 67 | |
| 68 // Implements -layoutSubviews as per instructions in documentation for | |
| 69 // +[MDCCollectionViewCell cr_preferredHeightForWidth:forItem:]. | |
| 70 - (void)layoutSubviews { | |
| 71 [super layoutSubviews]; | |
|
msarda
2017/03/22 12:18:38
Louis: Please take a look at this double call of l
lpromero
2017/03/24 10:36:19
Correct, this is common pattern, as explained in t
jlebel
2017/03/24 20:59:08
Acknowledged.
| |
| 72 | |
| 73 // Adjust the text label preferredMaxLayoutWidth when the parent's width | |
| 74 // changes, for instance on screen rotation. | |
|
lpromero
2017/03/24 10:36:19
Did you check in the material_cell_catalog that ro
jlebel
2017/03/24 20:59:08
Nice tip! But it works like a charm (everything is
| |
| 75 CGFloat parentWidth = CGRectGetWidth(self.bounds); | |
| 76 _signinPromoView.textLabel.preferredMaxLayoutWidth = | |
| 77 parentWidth - 2 * _signinPromoView.horizontalPadding; | |
| 78 | |
| 79 // Re-layout with the new preferred width to allow the label to adjust its | |
| 80 // height. | |
| 81 [super layoutSubviews]; | |
| 82 } | |
| 83 | |
| 84 @end | |
| OLD | NEW |