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); |
| 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]; |
| 50 _signinPromoView.translatesAutoresizingMaskIntoConstraints = NO; |
| 51 [contentView addSubview:_signinPromoView]; |
| 52 AddSameSizeConstraint(_signinPromoView, contentView); |
| 53 } |
| 54 return self; |
| 55 } |
| 56 |
| 57 // Implements -layoutSubviews as per instructions in documentation for |
| 58 // +[MDCCollectionViewCell cr_preferredHeightForWidth:forItem:]. |
| 59 - (void)layoutSubviews { |
| 60 [super layoutSubviews]; |
| 61 |
| 62 // Adjust the text label preferredMaxLayoutWidth when the parent's width |
| 63 // changes, for instance on screen rotation. |
| 64 CGFloat parentWidth = CGRectGetWidth(self.bounds); |
| 65 _signinPromoView.textLabel.preferredMaxLayoutWidth = |
| 66 parentWidth - 2 * _signinPromoView.horizontalPadding; |
| 67 |
| 68 // Re-layout with the new preferred width to allow the label to adjust its |
| 69 // height. |
| 70 [super layoutSubviews]; |
| 71 } |
| 72 |
| 73 @end |
OLD | NEW |