Chromium Code Reviews| 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..bd51946f3642611abaf9a4bb8ebded6ca4c97157 |
| --- /dev/null |
| +++ b/ios/chrome/browser/ui/content_suggestions/content_suggestions_footer_item.mm |
| @@ -0,0 +1,83 @@ |
| +// 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 |
| + |
| +#pragma mark - ContentSuggestionsFooterItem |
| + |
| +@interface ContentSuggestionsFooterItem () |
| + |
| +@property(nonatomic, copy) NSString* title; |
| +@property(nonatomic, copy) void (^action)(); |
| + |
| +- (void)executeAction; |
| + |
| +@end |
| + |
| +@implementation ContentSuggestionsFooterItem |
| + |
| +@synthesize title = _title; |
| +@synthesize action = _action; |
| +@synthesize suggestionIdentifier = _suggestionIdentifier; |
| + |
| +- (instancetype)initWithType:(NSInteger)type |
| + title:(NSString*)title |
| + action:(void (^)())action { |
| + self = [super initWithType:type]; |
| + if (self) { |
| + self.cellClass = [ContentSuggestionsFooterCell class]; |
| + _title = [title copy]; |
| + _action = [action copy]; |
| + } |
| + return self; |
| +} |
| + |
| +- (void)configureCell:(ContentSuggestionsFooterCell*)cell { |
| + [super configureCell:cell]; |
| + [cell.actionButton setTitle:self.title forState:UIControlStateNormal]; |
| + [cell.actionButton addTarget:self |
| + action:@selector(executeAction) |
| + forControlEvents:UIControlEventTouchUpInside]; |
| +} |
| + |
| +#pragma mark - Private |
| + |
| +- (void)executeAction { |
| + if (self.action) { |
| + self.action(); |
| + } |
| +} |
| + |
| +@end |
| + |
| +#pragma mark - ContentSuggestionsFooterCell |
| + |
| +@implementation ContentSuggestionsFooterCell |
| + |
| +@synthesize actionButton = _actionButton; |
| + |
| +- (instancetype)initWithFrame:(CGRect)frame { |
| + self = [super initWithFrame:frame]; |
| + if (self) { |
| + _actionButton = [UIButton buttonWithType:UIButtonTypeSystem]; |
|
lpromero
2017/03/13 14:45:14
No other styling? Will it be an MDCButton?
gambard
2017/03/14 10:02:42
For now I have no design for it so I go for the ea
|
| + _actionButton.translatesAutoresizingMaskIntoConstraints = NO; |
| + [self.contentView addSubview:_actionButton]; |
| + AddSameSizeConstraint(self.contentView, _actionButton); |
| + } |
| + return self; |
| +} |
| + |
| +- (void)prepareForReuse { |
| + [self.actionButton removeTarget:nil |
| + action:NULL |
| + forControlEvents:UIControlEventAllEvents]; |
| +} |
| + |
| +@end |