Chromium Code Reviews| 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..eb16cff75321b42cb61395b53307f89653e18564 |
| --- /dev/null |
| +++ b/ios/chrome/browser/ui/authentication/signin_promo_item.mm |
| @@ -0,0 +1,91 @@ |
| +// 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" |
| +#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 { |
| + 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]; |
|
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
|
| +} |
| + |
| +@end |
| + |
| +@implementation SigninPromoCell |
| + |
| +@synthesize signinPromoView = _signinPromoView; |
| + |
| +- (instancetype)initWithFrame:(CGRect)frame { |
| + self = [super initWithFrame:frame]; |
| + if (self) { |
| + [self addSubviews]; |
| + } |
| + return self; |
| +} |
| + |
| +- (void)addSubviews { |
| + UIView* contentView = self.contentView; |
| + |
| + _signinPromoView = [[SigninPromoView alloc] initWithFrame:self.bounds]; |
| + [contentView addSubview:_signinPromoView]; |
| + [NSLayoutConstraint activateConstraints:@[ |
| + [_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.
|
| + [_signinPromoView.bottomAnchor |
| + constraintEqualToAnchor:contentView.bottomAnchor], |
| + [_signinPromoView.leftAnchor |
| + constraintEqualToAnchor:contentView.leftAnchor], |
| + [_signinPromoView.rightAnchor |
| + constraintEqualToAnchor:contentView.rightAnchor], |
| + ]]; |
| +} |
| + |
| +// 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
|
| +// +[MDCCollectionViewCell cr_preferredHeightForWidth:forItem:]. |
| +- (void)layoutSubviews { |
| + [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
|
| + |
| + // 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 |