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

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: Fix gn 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 @end
25
26 @implementation ContentSuggestionsFooterItem
27
28 @synthesize title = _title;
29 @synthesize block = _block;
30 @synthesize suggestionIdentifier = _suggestionIdentifier;
31
32 - (instancetype)initWithType:(NSInteger)type
33 title:(NSString*)title
34 block:(ProceduralBlock)block {
35 self = [super initWithType:type];
36 if (self) {
37 self.cellClass = [ContentSuggestionsFooterCell class];
38 _title = [title copy];
39 _block = [block copy];
40 }
41 return self;
42 }
43
44 - (void)configureCell:(ContentSuggestionsFooterCell*)cell {
45 [super configureCell:cell];
46 [cell.button setTitle:self.title forState:UIControlStateNormal];
47 [cell.button addTarget:self
48 action:@selector(executeBlock)
49 forControlEvents:UIControlEventTouchUpInside];
50 }
51
52 #pragma mark - Private
53
54 // Executes the |_block| if not nil.
55 - (void)executeBlock {
56 if (self.block) {
57 self.block();
58 }
59 }
60
61 @end
62
63 #pragma mark - ContentSuggestionsFooterCell
64
65 @implementation ContentSuggestionsFooterCell
66
67 @synthesize button = _button;
68
69 - (instancetype)initWithFrame:(CGRect)frame {
70 self = [super initWithFrame:frame];
71 if (self) {
72 _button = [UIButton buttonWithType:UIButtonTypeSystem];
73 _button.translatesAutoresizingMaskIntoConstraints = NO;
74 [self.contentView addSubview:_button];
75 [_button.heightAnchor
76 constraintGreaterThanOrEqualToConstant:kMinimalCellHeight]
77 .active = YES;
78 AddSameSizeConstraint(self.contentView, _button);
79 }
80 return self;
81 }
82
83 - (void)prepareForReuse {
84 [self.button removeTarget:nil
85 action:NULL
86 forControlEvents:UIControlEventAllEvents];
87 }
88
89 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698