Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Unified Diff: ios/chrome/browser/ui/authentication/signin_promo_item.mm

Issue 2749703003: Adding mediator for Sign-in promo (Closed)
Patch Set: Visual constraints Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..b47351ef1278e91ad86d607a1923d295495c638f
--- /dev/null
+++ b/ios/chrome/browser/ui/authentication/signin_promo_item.mm
@@ -0,0 +1,84 @@
+// 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"
+
+#include "base/logging.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 signinPromoViewConfigurator = _signinPromoViewConfigurator;
+
+- (instancetype)initWithType:(NSInteger)type
+ signinPromoViewConfigurator:
+ (id<SigninPromoViewConfigurator>)signinPromoViewConfigurator {
+ self = [super initWithType:type];
+ if (self) {
+ self.cellClass = [SigninPromoCell class];
+ _signinPromoViewConfigurator = signinPromoViewConfigurator;
+ }
+ return self;
+}
+
+- (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.
+ NOTREACHED();
+ return nil;
+}
+
+#pragma mark - CollectionViewItem
+
+- (void)configureCell:(SigninPromoCell*)cell {
+ [super configureCell:cell];
+ cell.signinPromoView.textLabel.text =
+ l10n_util::GetNSString(IDS_IOS_SIGNIN_PROMO_SETTINGS);
+ [_signinPromoViewConfigurator configureSigninPromoView:cell.signinPromoView];
+}
+
+@end
+
+@implementation SigninPromoCell
+
+@synthesize signinPromoView = _signinPromoView;
+
+- (instancetype)initWithFrame:(CGRect)frame {
+ self = [super initWithFrame:frame];
+ if (self) {
+ [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.
+ }
+ return self;
+}
+
+- (void)addSubviews {
+ UIView* contentView = self.contentView;
+
msarda 2017/03/22 12:18:38 Optional nit: Kill empty line.
jlebel 2017/03/24 20:59:08 Done.
+ _signinPromoView = [[SigninPromoView alloc] initWithFrame:self.bounds];
+ [contentView addSubview:_signinPromoView];
+ AddSameSizeConstraint(_signinPromoView, contentView);
+}
+
+// Implements -layoutSubviews as per instructions in documentation for
+// +[MDCCollectionViewCell cr_preferredHeightForWidth:forItem:].
+- (void)layoutSubviews {
+ [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.
+
+ // Adjust the text label preferredMaxLayoutWidth when the parent's width
+ // 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
+ 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

Powered by Google App Engine
This is Rietveld 408576698