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 #import "ios/chrome/browser/ui/authentication/signin_promo_view.h" | |
8 #import "ios/chrome/browser/ui/uikit_ui_util.h" | |
9 #include "ios/chrome/grit/ios_chromium_strings.h" | |
10 #include "ui/base/l10n/l10n_util.h" | |
11 | |
12 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
13 #error "This file requires ARC support." | |
14 #endif | |
15 | |
16 @implementation SigninPromoItem | |
17 | |
18 @synthesize configurator = _configurator; | |
19 | |
20 - (instancetype)initWithType:(NSInteger)type | |
21 configurator:(id<SigninPromoViewConfigurator>)configurator { | |
22 self = [super initWithType:type]; | |
23 if (self) { | |
24 self.cellClass = [SigninPromoCell class]; | |
25 _configurator = configurator; | |
26 } | |
27 return self; | |
28 } | |
29 | |
30 #pragma mark - CollectionViewItem | |
31 | |
32 - (void)configureCell:(SigninPromoCell*)cell { | |
33 [super configureCell:cell]; | |
34 cell.signinPromoView.textLabel.text = | |
35 l10n_util::GetNSString(IDS_IOS_SIGNIN_PROMO_SETTINGS); | |
lpromero
2017/03/27 13:14:46
Since this is not settable by items clients, I sug
jlebel
2017/03/27 21:34:42
The issue is then the item will not be usable for
| |
36 [_configurator configureSigninPromoView:cell.signinPromoView]; | |
37 } | |
38 | |
39 @end | |
40 | |
41 @implementation SigninPromoCell | |
42 | |
43 @synthesize signinPromoView = _signinPromoView; | |
44 | |
45 - (instancetype)initWithFrame:(CGRect)frame { | |
46 self = [super initWithFrame:frame]; | |
47 if (self) { | |
48 UIView* contentView = self.contentView; | |
49 _signinPromoView = [[SigninPromoView alloc] initWithFrame:self.bounds]; | |
lpromero
2017/03/27 13:14:46
Nit: I prefer to let the creator of the view set t
jlebel
2017/03/27 21:34:42
Done.
| |
50 [contentView addSubview:_signinPromoView]; | |
51 AddSameSizeConstraint(_signinPromoView, contentView); | |
52 } | |
53 return self; | |
54 } | |
55 | |
56 // Implements -layoutSubviews as per instructions in documentation for | |
57 // +[MDCCollectionViewCell cr_preferredHeightForWidth:forItem:]. | |
58 - (void)layoutSubviews { | |
59 [super layoutSubviews]; | |
60 | |
61 // Adjust the text label preferredMaxLayoutWidth when the parent's width | |
62 // changes, for instance on screen rotation. | |
63 CGFloat parentWidth = CGRectGetWidth(self.bounds); | |
64 _signinPromoView.textLabel.preferredMaxLayoutWidth = | |
65 parentWidth - 2 * _signinPromoView.horizontalPadding; | |
66 | |
67 // Re-layout with the new preferred width to allow the label to adjust its | |
68 // height. | |
69 [super layoutSubviews]; | |
70 } | |
71 | |
72 @end | |
OLD | NEW |