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

Side by Side Diff: ios/chrome/browser/ui/content_suggestions/content_suggestions_footer_item.mm

Issue 2749543002: Add a footer item for the Content Suggestions (Closed)
Patch Set: Address comments 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 unified diff | Download patch
OLDNEW
(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/content_suggestions/content_suggestions_footer_it em.h"
6
7 #import "ios/chrome/browser/ui/uikit_ui_util.h"
8
9 #if !defined(__has_feature) || !__has_feature(objc_arc)
10 #error "This file requires ARC support."
11 #endif
12
13 namespace {
14 const CGFloat kMinimalCellHeight = 44;
15 }
16
17 #pragma mark - ContentSuggestionsFooterItem
18
19 @interface ContentSuggestionsFooterItem ()
20
21 @property(nonatomic, copy) NSString* title;
22 @property(nonatomic, copy) ProceduralBlock block;
23
24 - (void)executeAction;
lpromero 2017/03/14 10:16:19 executeBlock.
gambard 2017/03/14 11:02:23 Done.
25
26 @end
27
28 @implementation ContentSuggestionsFooterItem
29
30 @synthesize title = _title;
31 @synthesize block = _block;
32 @synthesize suggestionIdentifier = _suggestionIdentifier;
33
34 - (instancetype)initWithType:(NSInteger)type
35 title:(NSString*)title
36 block:(ProceduralBlock)block {
37 self = [super initWithType:type];
38 if (self) {
39 self.cellClass = [ContentSuggestionsFooterCell class];
40 _title = [title copy];
41 _block = [block copy];
42 }
43 return self;
44 }
45
46 - (void)configureCell:(ContentSuggestionsFooterCell*)cell {
47 [super configureCell:cell];
48 [cell.actionButton setTitle:self.title forState:UIControlStateNormal];
49 [cell.actionButton addTarget:self
50 action:@selector(executeAction)
51 forControlEvents:UIControlEventTouchUpInside];
52 }
53
54 #pragma mark - Private
55
56 - (void)executeAction {
57 if (self.block) {
58 self.block();
59 }
60 }
61
62 @end
63
64 #pragma mark - ContentSuggestionsFooterCell
65
66 @implementation ContentSuggestionsFooterCell
67
68 @synthesize actionButton = _actionButton;
69
70 - (instancetype)initWithFrame:(CGRect)frame {
71 self = [super initWithFrame:frame];
72 if (self) {
73 _actionButton = [UIButton buttonWithType:UIButtonTypeSystem];
74 _actionButton.translatesAutoresizingMaskIntoConstraints = NO;
75 [self.contentView addSubview:_actionButton];
76 [_actionButton.heightAnchor
77 constraintGreaterThanOrEqualToConstant:kMinimalCellHeight]
78 .active = YES;
79 AddSameSizeConstraint(self.contentView, _actionButton);
80 }
81 return self;
82 }
83
84 - (void)prepareForReuse {
85 [self.actionButton removeTarget:nil
86 action:NULL
87 forControlEvents:UIControlEventAllEvents];
88 }
89
90 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698