| 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/suggestions/suggestions_stack_item.h" |
| 6 |
| 7 #import "ios/chrome/browser/ui/suggestions/suggestions_stack_item_actions.h" |
| 8 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
| 9 |
| 10 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 11 #error "This file requires ARC support." |
| 12 #endif |
| 13 |
| 14 namespace { |
| 15 const CGFloat kStackSpacing = 8; |
| 16 } |
| 17 |
| 18 @implementation SuggestionsStackItem { |
| 19 NSString* _title; |
| 20 NSString* _subtitle; |
| 21 } |
| 22 |
| 23 - (instancetype)initWithType:(NSInteger)type |
| 24 title:(NSString*)title |
| 25 subtitle:(NSString*)subtitle { |
| 26 self = [super initWithType:type]; |
| 27 if (self) { |
| 28 self.cellClass = [SuggestionsStackCell class]; |
| 29 _title = [title copy]; |
| 30 _subtitle = [subtitle copy]; |
| 31 } |
| 32 return self; |
| 33 } |
| 34 |
| 35 #pragma mark - CollectionViewItem |
| 36 |
| 37 - (void)configureCell:(SuggestionsStackCell*)cell { |
| 38 [super configureCell:cell]; |
| 39 [cell.titleButton setTitle:_title forState:UIControlStateNormal]; |
| 40 cell.detailTextLabel.text = _subtitle; |
| 41 } |
| 42 |
| 43 @end |
| 44 |
| 45 @implementation SuggestionsStackCell |
| 46 |
| 47 @synthesize titleButton = _titleButton; |
| 48 @synthesize detailTextLabel = _detailTextLabel; |
| 49 |
| 50 - (instancetype)initWithFrame:(CGRect)frame { |
| 51 self = [super initWithFrame:frame]; |
| 52 if (self) { |
| 53 self.backgroundColor = [UIColor clearColor]; |
| 54 self.contentView.backgroundColor = [UIColor clearColor]; |
| 55 self.backgroundView.backgroundColor = [UIColor clearColor]; |
| 56 |
| 57 UIControl* itemDisplay = [[UIControl alloc] init]; |
| 58 itemDisplay.layer.borderColor = [UIColor blackColor].CGColor; |
| 59 itemDisplay.layer.borderWidth = 1; |
| 60 itemDisplay.backgroundColor = [UIColor whiteColor]; |
| 61 [itemDisplay addTarget:nil |
| 62 action:@selector(openReadingListFirstItem:) |
| 63 forControlEvents:UIControlEventTouchUpInside]; |
| 64 itemDisplay.translatesAutoresizingMaskIntoConstraints = NO; |
| 65 |
| 66 _titleButton = [UIButton buttonWithType:UIButtonTypeSystem]; |
| 67 _detailTextLabel = [[UILabel alloc] init]; |
| 68 _titleButton.translatesAutoresizingMaskIntoConstraints = NO; |
| 69 _detailTextLabel.translatesAutoresizingMaskIntoConstraints = NO; |
| 70 |
| 71 [itemDisplay addSubview:_titleButton]; |
| 72 [itemDisplay addSubview:_detailTextLabel]; |
| 73 |
| 74 // Placeholder. This view is only used to display a border below the item. |
| 75 UIView* secondView = [[UIView alloc] init]; |
| 76 secondView.backgroundColor = [UIColor whiteColor]; |
| 77 secondView.translatesAutoresizingMaskIntoConstraints = NO; |
| 78 secondView.layer.borderColor = [UIColor blackColor].CGColor; |
| 79 secondView.layer.borderWidth = 1; |
| 80 |
| 81 // Placeholder. This view is only used to display a border below the item. |
| 82 UIView* thirdView = [[UIView alloc] init]; |
| 83 thirdView.backgroundColor = [UIColor whiteColor]; |
| 84 thirdView.translatesAutoresizingMaskIntoConstraints = NO; |
| 85 thirdView.layer.borderColor = [UIColor blackColor].CGColor; |
| 86 thirdView.layer.borderWidth = 1; |
| 87 |
| 88 // Placeholder. This view is only used to display a border below the item. |
| 89 UIView* fourthView = [[UIView alloc] init]; |
| 90 fourthView.backgroundColor = [UIColor whiteColor]; |
| 91 fourthView.translatesAutoresizingMaskIntoConstraints = NO; |
| 92 fourthView.layer.borderColor = [UIColor blackColor].CGColor; |
| 93 fourthView.layer.borderWidth = 1; |
| 94 |
| 95 [self.contentView addSubview:itemDisplay]; |
| 96 [self.contentView insertSubview:secondView belowSubview:itemDisplay]; |
| 97 [self.contentView insertSubview:thirdView belowSubview:secondView]; |
| 98 [self.contentView insertSubview:fourthView belowSubview:thirdView]; |
| 99 |
| 100 [NSLayoutConstraint activateConstraints:@[ |
| 101 [itemDisplay.widthAnchor constraintEqualToAnchor:secondView.widthAnchor], |
| 102 [itemDisplay.heightAnchor |
| 103 constraintEqualToAnchor:secondView.heightAnchor], |
| 104 [itemDisplay.widthAnchor constraintEqualToAnchor:thirdView.widthAnchor], |
| 105 [itemDisplay.heightAnchor constraintEqualToAnchor:thirdView.heightAnchor], |
| 106 [itemDisplay.widthAnchor constraintEqualToAnchor:fourthView.widthAnchor], |
| 107 [itemDisplay.heightAnchor |
| 108 constraintEqualToAnchor:fourthView.heightAnchor], |
| 109 ]]; |
| 110 |
| 111 ApplyVisualConstraintsWithMetrics( |
| 112 @[ |
| 113 @"H:|-[title]-|", |
| 114 @"H:|-[text]-|", |
| 115 @"H:|[item]-(fourSpace)-|", |
| 116 @"H:|-(oneSpace)-[second]-(threeSpace)-|", |
| 117 @"H:|-(twoSpace)-[third]-(twoSpace)-|", |
| 118 @"H:|-(threeSpace)-[fourth]-(oneSpace)-|", |
| 119 @"V:|-[title]-[text]-|", |
| 120 @"V:|[item]", |
| 121 @"V:|-(oneSpace)-[second]", |
| 122 @"V:|-(twoSpace)-[third]", |
| 123 @"V:|-(threeSpace)-[fourth]|", |
| 124 ], |
| 125 @{ |
| 126 @"title" : _titleButton, |
| 127 @"text" : _detailTextLabel, |
| 128 @"item" : itemDisplay, |
| 129 @"second" : secondView, |
| 130 @"third" : thirdView, |
| 131 @"fourth" : fourthView, |
| 132 }, |
| 133 @{ |
| 134 @"oneSpace" : @(kStackSpacing * 1), |
| 135 @"twoSpace" : @(kStackSpacing * 2), |
| 136 @"threeSpace" : @(kStackSpacing * 3), |
| 137 @"fourSpace" : @(kStackSpacing * 4) |
| 138 }); |
| 139 } |
| 140 return self; |
| 141 } |
| 142 |
| 143 @end |
| OLD | NEW |