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