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

Side by Side Diff: ios/chrome/browser/ui/bookmarks/bookmark_signin_promo_cell.mm

Issue 2844253003: Adding close button in SigninPromoView (Closed)
Patch Set: Changing dismiss to close, and moving the button to the cell Created 3 years, 7 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 unified diff | Download patch
« no previous file with comments | « ios/chrome/browser/ui/bookmarks/bookmark_signin_promo_cell.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "ios/chrome/browser/ui/bookmarks/bookmark_signin_promo_cell.h" 5 #import "ios/chrome/browser/ui/bookmarks/bookmark_signin_promo_cell.h"
6 6
7 #import "ios/chrome/browser/ui/authentication/signin_promo_view.h" 7 #import "ios/chrome/browser/ui/authentication/signin_promo_view.h"
8 #import "ios/chrome/browser/ui/uikit_ui_util.h" 8 #import "ios/chrome/browser/ui/uikit_ui_util.h"
9 #include "ios/chrome/grit/ios_chromium_strings.h" 9 #include "ios/chrome/grit/ios_chromium_strings.h"
10 #include "ui/base/l10n/l10n_util.h" 10 #include "ui/base/l10n/l10n_util.h"
11 11
12 #if !defined(__has_feature) || !__has_feature(objc_arc) 12 #if !defined(__has_feature) || !__has_feature(objc_arc)
13 #error "This file requires ARC support." 13 #error "This file requires ARC support."
14 #endif 14 #endif
15 15
16 namespace {
17 // Close button size.
18 const CGFloat kCloseButtonSize = 24;
19 }
20
16 @implementation BookmarkSigninPromoCell { 21 @implementation BookmarkSigninPromoCell {
17 SigninPromoView* _signinPromoView; 22 SigninPromoView* _signinPromoView;
23 UIButton* _closeButton;
18 } 24 }
19 25
20 @synthesize signinPromoView = _signinPromoView; 26 @synthesize signinPromoView = _signinPromoView;
27 @synthesize closeButtonAction = _closeButtonAction;
21 28
22 + (NSString*)reuseIdentifier { 29 + (NSString*)reuseIdentifier {
23 return @"BookmarkSigninPromoCell"; 30 return @"BookmarkSigninPromoCell";
24 } 31 }
25 32
26 + (BOOL)requiresConstraintBasedLayout { 33 + (BOOL)requiresConstraintBasedLayout {
27 return YES; 34 return YES;
28 } 35 }
29 36
30 - (instancetype)initWithFrame:(CGRect)frame { 37 - (instancetype)initWithFrame:(CGRect)frame {
31 self = [super initWithFrame:frame]; 38 self = [super initWithFrame:frame];
32 if (self) { 39 if (self) {
33 UIView* contentView = self.contentView; 40 UIView* contentView = self.contentView;
34 _signinPromoView = [[SigninPromoView alloc] initWithFrame:self.bounds]; 41 _signinPromoView = [[SigninPromoView alloc] initWithFrame:self.bounds];
35 _signinPromoView.translatesAutoresizingMaskIntoConstraints = NO; 42 _signinPromoView.translatesAutoresizingMaskIntoConstraints = NO;
36 [contentView addSubview:_signinPromoView]; 43 [contentView addSubview:_signinPromoView];
37 AddSameConstraints(_signinPromoView, contentView); 44 AddSameConstraints(_signinPromoView, contentView);
45
46 _closeButton = [[UIButton alloc]
47 initWithFrame:CGRectMake(0, 0, kCloseButtonSize, kCloseButtonSize)];
48 [_closeButton addTarget:self
49 action:@selector(closeButtonAction:)
50 forControlEvents:UIControlEventTouchUpInside];
51 _closeButton.translatesAutoresizingMaskIntoConstraints = NO;
52 [contentView addSubview:_closeButton];
53 [_closeButton setImage:[UIImage imageNamed:@"signin_promo_close_gray"]
54 forState:UIControlStateNormal];
55 NSArray* buttonVisualConstraints =
56 @[ @"H:[closeButton]-|", @"V:|-[closeButton]" ];
57 NSDictionary* views = @{ @"closeButton" : _closeButton };
58 ApplyVisualConstraints(buttonVisualConstraints, views);
59
38 _signinPromoView.backgroundColor = [UIColor whiteColor]; 60 _signinPromoView.backgroundColor = [UIColor whiteColor];
39 _signinPromoView.textLabel.text = 61 _signinPromoView.textLabel.text =
40 l10n_util::GetNSString(IDS_IOS_SIGNIN_PROMO_SETTINGS); 62 l10n_util::GetNSString(IDS_IOS_SIGNIN_PROMO_SETTINGS);
41 } 63 }
42 return self; 64 return self;
43 } 65 }
44 66
45 - (void)layoutSubviews { 67 - (void)layoutSubviews {
46 // Adjust the text label preferredMaxLayoutWidth according self.frame.width, 68 // Adjust the text label preferredMaxLayoutWidth according self.frame.width,
47 // so the text will adjust its height and not its width. 69 // so the text will adjust its height and not its width.
48 CGFloat parentWidth = CGRectGetWidth(self.bounds); 70 CGFloat parentWidth = CGRectGetWidth(self.bounds);
49 _signinPromoView.textLabel.preferredMaxLayoutWidth = 71 _signinPromoView.textLabel.preferredMaxLayoutWidth =
50 parentWidth - 2 * _signinPromoView.horizontalPadding; 72 parentWidth - 2 * _signinPromoView.horizontalPadding;
51 73
52 // Re-layout with the new preferred width to allow the label to adjust its 74 // Re-layout with the new preferred width to allow the label to adjust its
53 // height. 75 // height.
54 [super layoutSubviews]; 76 [super layoutSubviews];
55 } 77 }
56 78
79 - (void)prepareForReuse {
80 _closeButtonAction = nil;
81 }
82
83 - (void)closeButtonAction:(id)sender {
84 if (_closeButtonAction) {
85 _closeButtonAction();
msarda 2017/05/04 11:48:08 I think it would be better to set the closeButtonA
jlebel 2017/05/04 13:20:38 I don't believe it is relevant. This should be don
86 }
87 }
88
57 @end 89 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/bookmarks/bookmark_signin_promo_cell.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698