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..347df545e1904520a6979a6aaf5889b1c47a592e |
| --- /dev/null |
| +++ b/ios/chrome/browser/ui/content_suggestions/content_suggestions_footer_item.mm |
| @@ -0,0 +1,90 @@ |
| +// 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; |
| + |
| +- (void)executeAction; |
|
lpromero
2017/03/14 10:16:19
executeBlock.
gambard
2017/03/14 11:02:23
Done.
|
| + |
| +@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.actionButton setTitle:self.title forState:UIControlStateNormal]; |
| + [cell.actionButton addTarget:self |
| + action:@selector(executeAction) |
| + forControlEvents:UIControlEventTouchUpInside]; |
| +} |
| + |
| +#pragma mark - Private |
| + |
| +- (void)executeAction { |
| + if (self.block) { |
| + self.block(); |
| + } |
| +} |
| + |
| +@end |
| + |
| +#pragma mark - ContentSuggestionsFooterCell |
| + |
| +@implementation ContentSuggestionsFooterCell |
| + |
| +@synthesize actionButton = _actionButton; |
| + |
| +- (instancetype)initWithFrame:(CGRect)frame { |
| + self = [super initWithFrame:frame]; |
| + if (self) { |
| + _actionButton = [UIButton buttonWithType:UIButtonTypeSystem]; |
| + _actionButton.translatesAutoresizingMaskIntoConstraints = NO; |
| + [self.contentView addSubview:_actionButton]; |
| + [_actionButton.heightAnchor |
| + constraintGreaterThanOrEqualToConstant:kMinimalCellHeight] |
| + .active = YES; |
| + AddSameSizeConstraint(self.contentView, _actionButton); |
| + } |
| + return self; |
| +} |
| + |
| +- (void)prepareForReuse { |
| + [self.actionButton removeTarget:nil |
| + action:NULL |
| + forControlEvents:UIControlEventAllEvents]; |
| +} |
| + |
| +@end |