Index: ios/chrome/browser/ui/authentication/signin_promo_item.mm |
diff --git a/ios/chrome/browser/ui/authentication/signin_promo_item.mm b/ios/chrome/browser/ui/authentication/signin_promo_item.mm |
new file mode 100644 |
index 0000000000000000000000000000000000000000..97e3f53e7d42a1f7305142776a81a46920e15be5 |
--- /dev/null |
+++ b/ios/chrome/browser/ui/authentication/signin_promo_item.mm |
@@ -0,0 +1,72 @@ |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#import "ios/chrome/browser/ui/authentication/signin_promo_item.h" |
+ |
+#import "ios/chrome/browser/ui/authentication/signin_promo_view.h" |
+#import "ios/chrome/browser/ui/uikit_ui_util.h" |
+#include "ios/chrome/grit/ios_chromium_strings.h" |
+#include "ui/base/l10n/l10n_util.h" |
+ |
+#if !defined(__has_feature) || !__has_feature(objc_arc) |
+#error "This file requires ARC support." |
+#endif |
+ |
+@implementation SigninPromoItem |
+ |
+@synthesize configurator = _configurator; |
+ |
+- (instancetype)initWithType:(NSInteger)type |
+ configurator:(id<SigninPromoViewConfigurator>)configurator { |
+ self = [super initWithType:type]; |
+ if (self) { |
+ self.cellClass = [SigninPromoCell class]; |
+ _configurator = configurator; |
+ } |
+ return self; |
+} |
+ |
+#pragma mark - CollectionViewItem |
+ |
+- (void)configureCell:(SigninPromoCell*)cell { |
+ [super configureCell:cell]; |
+ cell.signinPromoView.textLabel.text = |
+ 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
|
+ [_configurator configureSigninPromoView:cell.signinPromoView]; |
+} |
+ |
+@end |
+ |
+@implementation SigninPromoCell |
+ |
+@synthesize signinPromoView = _signinPromoView; |
+ |
+- (instancetype)initWithFrame:(CGRect)frame { |
+ self = [super initWithFrame:frame]; |
+ if (self) { |
+ UIView* contentView = self.contentView; |
+ _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.
|
+ [contentView addSubview:_signinPromoView]; |
+ AddSameSizeConstraint(_signinPromoView, contentView); |
+ } |
+ return self; |
+} |
+ |
+// Implements -layoutSubviews as per instructions in documentation for |
+// +[MDCCollectionViewCell cr_preferredHeightForWidth:forItem:]. |
+- (void)layoutSubviews { |
+ [super layoutSubviews]; |
+ |
+ // Adjust the text label preferredMaxLayoutWidth when the parent's width |
+ // changes, for instance on screen rotation. |
+ CGFloat parentWidth = CGRectGetWidth(self.bounds); |
+ _signinPromoView.textLabel.preferredMaxLayoutWidth = |
+ parentWidth - 2 * _signinPromoView.horizontalPadding; |
+ |
+ // Re-layout with the new preferred width to allow the label to adjust its |
+ // height. |
+ [super layoutSubviews]; |
+} |
+ |
+@end |