Chromium Code Reviews| 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 NSInteger kStackSpacing = 8; | |
|
marq (ping after 24h)
2017/01/16 18:04:42
If this is used to positions views, it should be a
gambard
2017/01/17 13:28:11
Done.
| |
| 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(topOfStackPressed:) | |
| 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 UIView* secondView = [[UIView alloc] init]; | |
|
marq (ping after 24h)
2017/01/16 18:04:42
If these are placeholders, please add comments ind
gambard
2017/01/17 13:28:11
Done.
| |
| 75 secondView.backgroundColor = [UIColor whiteColor]; | |
| 76 secondView.translatesAutoresizingMaskIntoConstraints = NO; | |
| 77 secondView.layer.borderColor = [UIColor blackColor].CGColor; | |
| 78 secondView.layer.borderWidth = 1; | |
| 79 | |
| 80 UIView* thirdView = [[UIView alloc] init]; | |
| 81 thirdView.backgroundColor = [UIColor whiteColor]; | |
| 82 thirdView.translatesAutoresizingMaskIntoConstraints = NO; | |
| 83 thirdView.layer.borderColor = [UIColor blackColor].CGColor; | |
| 84 thirdView.layer.borderWidth = 1; | |
| 85 | |
| 86 UIView* fourthView = [[UIView alloc] init]; | |
| 87 fourthView.backgroundColor = [UIColor whiteColor]; | |
| 88 fourthView.translatesAutoresizingMaskIntoConstraints = NO; | |
| 89 fourthView.layer.borderColor = [UIColor blackColor].CGColor; | |
| 90 fourthView.layer.borderWidth = 1; | |
| 91 | |
| 92 [self.contentView addSubview:itemDisplay]; | |
|
marq (ping after 24h)
2017/01/16 18:04:42
Why not just reverse the order of these and use -a
gambard
2017/01/17 13:28:11
This shows there is an intended order. Using only
| |
| 93 [self.contentView insertSubview:secondView belowSubview:itemDisplay]; | |
| 94 [self.contentView insertSubview:thirdView belowSubview:secondView]; | |
| 95 [self.contentView insertSubview:fourthView belowSubview:thirdView]; | |
| 96 | |
| 97 [NSLayoutConstraint activateConstraints:@[ | |
| 98 [itemDisplay.widthAnchor constraintEqualToAnchor:secondView.widthAnchor], | |
| 99 [itemDisplay.heightAnchor | |
| 100 constraintEqualToAnchor:secondView.heightAnchor], | |
| 101 [itemDisplay.widthAnchor constraintEqualToAnchor:thirdView.widthAnchor], | |
| 102 [itemDisplay.heightAnchor constraintEqualToAnchor:thirdView.heightAnchor], | |
| 103 [itemDisplay.widthAnchor constraintEqualToAnchor:fourthView.widthAnchor], | |
| 104 [itemDisplay.heightAnchor | |
| 105 constraintEqualToAnchor:fourthView.heightAnchor], | |
| 106 ]]; | |
| 107 | |
| 108 ApplyVisualConstraintsWithMetrics( | |
| 109 @[ | |
| 110 @"H:|-[title]-|", | |
| 111 @"H:|-[text]-|", | |
| 112 @"H:|[item]-(fourSpace)-|", | |
| 113 @"H:|-(oneSpace)-[second]-(threeSpace)-|", | |
| 114 @"H:|-(twoSpace)-[third]-(twoSpace)-|", | |
| 115 @"H:|-(threeSpace)-[fourth]-(oneSpace)-|", | |
| 116 @"V:|-[title]-[text]-|", | |
| 117 @"V:|[item]", | |
| 118 @"V:|-(oneSpace)-[second]", | |
| 119 @"V:|-(twoSpace)-[third]", | |
| 120 @"V:|-(threeSpace)-[fourth]|", | |
| 121 ], | |
| 122 @{ | |
| 123 @"title" : _titleButton, | |
| 124 @"text" : _detailTextLabel, | |
| 125 @"item" : itemDisplay, | |
| 126 @"second" : secondView, | |
| 127 @"third" : thirdView, | |
| 128 @"fourth" : fourthView, | |
| 129 }, | |
| 130 @{ | |
| 131 @"oneSpace" : @(kStackSpacing * 1), | |
| 132 @"twoSpace" : @(kStackSpacing * 2), | |
| 133 @"threeSpace" : @(kStackSpacing * 3), | |
| 134 @"fourSpace" : @(kStackSpacing * 4) | |
| 135 }); | |
| 136 } | |
| 137 return self; | |
| 138 } | |
| 139 | |
| 140 @end | |
| OLD | NEW |