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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: ios/chrome/browser/ui/content_suggestions/content_suggestions_footer_item.mm
diff --git a/ios/chrome/browser/ui/content_suggestions/content_suggestions_footer_item.mm b/ios/chrome/browser/ui/content_suggestions/content_suggestions_footer_item.mm
new file mode 100644
index 0000000000000000000000000000000000000000..7f37c499636cfbaedbc6273250284ff3f8ad1f96
--- /dev/null
+++ b/ios/chrome/browser/ui/content_suggestions/content_suggestions_footer_item.mm
@@ -0,0 +1,89 @@
+// 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/content_suggestions/content_suggestions_footer_item.h"
+
+#import "ios/chrome/browser/ui/uikit_ui_util.h"
+
+#if !defined(__has_feature) || !__has_feature(objc_arc)
+#error "This file requires ARC support."
+#endif
+
+namespace {
+const CGFloat kMinimalCellHeight = 44;
+}
+
+#pragma mark - ContentSuggestionsFooterItem
+
+@interface ContentSuggestionsFooterItem ()
+
+@property(nonatomic, copy) NSString* title;
+@property(nonatomic, copy) ProceduralBlock block;
+
+@end
+
+@implementation ContentSuggestionsFooterItem
+
+@synthesize title = _title;
+@synthesize block = _block;
+@synthesize suggestionIdentifier = _suggestionIdentifier;
+
+- (instancetype)initWithType:(NSInteger)type
+ title:(NSString*)title
+ block:(ProceduralBlock)block {
+ self = [super initWithType:type];
+ if (self) {
+ self.cellClass = [ContentSuggestionsFooterCell class];
+ _title = [title copy];
+ _block = [block copy];
+ }
+ return self;
+}
+
+- (void)configureCell:(ContentSuggestionsFooterCell*)cell {
+ [super configureCell:cell];
+ [cell.button setTitle:self.title forState:UIControlStateNormal];
+ [cell.button addTarget:self
+ action:@selector(executeBlock)
+ forControlEvents:UIControlEventTouchUpInside];
+}
+
+#pragma mark - Private
+
+// Executes the |_block| if not nil.
+- (void)executeBlock {
+ if (self.block) {
+ self.block();
+ }
+}
+
+@end
+
+#pragma mark - ContentSuggestionsFooterCell
+
+@implementation ContentSuggestionsFooterCell
+
+@synthesize button = _button;
+
+- (instancetype)initWithFrame:(CGRect)frame {
+ self = [super initWithFrame:frame];
+ if (self) {
+ _button = [UIButton buttonWithType:UIButtonTypeSystem];
+ _button.translatesAutoresizingMaskIntoConstraints = NO;
+ [self.contentView addSubview:_button];
+ [_button.heightAnchor
+ constraintGreaterThanOrEqualToConstant:kMinimalCellHeight]
+ .active = YES;
+ AddSameSizeConstraint(self.contentView, _button);
+ }
+ return self;
+}
+
+- (void)prepareForReuse {
+ [self.button removeTarget:nil
+ action:NULL
+ forControlEvents:UIControlEventAllEvents];
+}
+
+@end

Powered by Google App Engine
This is Rietveld 408576698