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 #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 signinPromoViewConfigurator = _signinPromoViewConfigurator; | |
19 | |
20 - (instancetype)initWithType:(NSInteger)type | |
21 signinPromoViewConfigurator: | |
22 (id<SigninPromoViewConfigurator>)signinPromoViewConfigurator { | |
23 self = [super initWithType:type]; | |
24 if (self) { | |
25 self.cellClass = [SigninPromoCell class]; | |
26 _signinPromoViewConfigurator = signinPromoViewConfigurator; | |
27 } | |
28 return self; | |
29 } | |
30 | |
31 - (instancetype)initWithType:(NSInteger)type { | |
32 NOTREACHED(); | |
33 return nil; | |
34 } | |
35 | |
36 #pragma mark - CollectionViewItem | |
37 | |
38 - (void)configureCell:(SigninPromoCell*)cell { | |
39 [super configureCell:cell]; | |
40 cell.signinPromoView.textLabel.text = | |
41 l10n_util::GetNSString(IDS_IOS_SIGNIN_PROMO_SETTINGS); | |
42 [_signinPromoViewConfigurator configureSigninPromoView:cell.signinPromoView]; | |
msarda
2017/03/16 22:15:31
Should the configuration also configure the textLa
jlebel
2017/03/21 17:22:28
I can but this is a fixed value, and the value is
msarda
2017/03/22 12:18:38
OK, I see (basically this is not something configu
| |
43 } | |
44 | |
45 @end | |
46 | |
47 @implementation SigninPromoCell | |
48 | |
49 @synthesize signinPromoView = _signinPromoView; | |
50 | |
51 - (instancetype)initWithFrame:(CGRect)frame { | |
52 self = [super initWithFrame:frame]; | |
53 if (self) { | |
54 [self addSubviews]; | |
55 } | |
56 return self; | |
57 } | |
58 | |
59 - (void)addSubviews { | |
60 UIView* contentView = self.contentView; | |
61 | |
62 _signinPromoView = [[SigninPromoView alloc] initWithFrame:self.bounds]; | |
63 [contentView addSubview:_signinPromoView]; | |
64 [NSLayoutConstraint activateConstraints:@[ | |
65 [_signinPromoView.topAnchor constraintEqualToAnchor:contentView.topAnchor], | |
msarda
2017/03/16 22:15:31
Is the goal of these constraints to have the same
jlebel
2017/03/21 17:22:28
Done.
| |
66 [_signinPromoView.bottomAnchor | |
67 constraintEqualToAnchor:contentView.bottomAnchor], | |
68 [_signinPromoView.leftAnchor | |
69 constraintEqualToAnchor:contentView.leftAnchor], | |
70 [_signinPromoView.rightAnchor | |
71 constraintEqualToAnchor:contentView.rightAnchor], | |
72 ]]; | |
73 } | |
74 | |
75 // Implements -layoutSubviews as per instructions in documentation for | |
msarda
2017/03/16 22:15:31
I suppose this comment is not needed (but probably
jlebel
2017/03/21 17:22:28
I've done exactly the same implementation than tho
| |
76 // +[MDCCollectionViewCell cr_preferredHeightForWidth:forItem:]. | |
77 - (void)layoutSubviews { | |
78 [super layoutSubviews]; | |
msarda
2017/03/16 22:15:31
I think calling [super layoutSubviews] here is un
jlebel
2017/03/21 17:22:28
-[MDCollectionViewCell layoutSubviews layoutSubvie
msarda
2017/03/22 12:18:38
Ok, I've added a comment on the next patch. I'd li
| |
79 | |
80 // Adjust the text label preferredMaxLayoutWidth when the parent's width | |
81 // changes, for instance on screen rotation. | |
82 CGFloat parentWidth = CGRectGetWidth(self.bounds); | |
83 _signinPromoView.textLabel.preferredMaxLayoutWidth = | |
84 parentWidth - 2 * _signinPromoView.horizontalPadding; | |
85 | |
86 // Re-layout with the new preferred width to allow the label to adjust its | |
87 // height. | |
88 [super layoutSubviews]; | |
89 } | |
90 | |
91 @end | |
OLD | NEW |