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_favicon_item.h" | |
6 | |
7 #import <UIKit/UIKit.h> | |
8 | |
9 #include "base/logging.h" | |
10 #import "ios/chrome/browser/ui/suggestions/suggestions_favicon_internal_cell.h" | |
11 #import "ios/chrome/browser/ui/uikit_ui_util.h" | |
12 | |
13 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
14 #error "This file requires ARC support." | |
15 #endif | |
16 | |
17 namespace { | |
18 // Space between two cells in the internal collection view. | |
19 const CGFloat kInternalCellSpacing = 40; | |
20 // Width of the cells in the internal collection view. | |
21 const CGFloat kInternalCellWidth = 70; | |
22 // Height of the cells in the internal collection view. | |
23 const CGFloat kInternalCellHeight = 120; | |
24 // Left inset of the internal collection view. | |
25 const CGFloat kInternalLeftSpacing = 16; | |
lpromero
2017/01/18 09:34:38
s/left/leading, idem in the comment.
gambard
2017/01/18 12:37:58
Done.
| |
26 } // namespace | |
27 | |
28 #pragma mark - SugggestionsFaviconItem | |
29 | |
30 // The item is the data source of the inner collection view. | |
31 @interface SuggestionsFaviconItem ()<UICollectionViewDataSource> { | |
32 NSMutableArray<NSString*>* _faviconTitles; | |
33 NSMutableArray<UIImage*>* _faviconImages; | |
34 } | |
35 | |
36 @end | |
37 | |
38 @implementation SuggestionsFaviconItem | |
39 | |
40 @synthesize delegate = _delegate; | |
41 | |
42 - (instancetype)initWithType:(NSInteger)type { | |
43 self = [super initWithType:type]; | |
44 if (self) { | |
45 self.cellClass = [SuggestionsFaviconCell class]; | |
46 _faviconTitles = [NSMutableArray array]; | |
47 _faviconImages = [NSMutableArray array]; | |
48 } | |
49 return self; | |
50 } | |
51 | |
52 - (void)addFavicon:(UIImage*)favicon withTitle:(NSString*)title { | |
53 [_faviconImages addObject:favicon]; | |
54 [_faviconTitles addObject:title]; | |
55 } | |
56 | |
57 #pragma mark - UICollectionViewDataSource | |
58 | |
59 - (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView | |
60 cellForItemAtIndexPath:(NSIndexPath*)indexPath { | |
61 SuggestionsFaviconInternalCell* cell = [collectionView | |
62 dequeueReusableCellWithReuseIdentifier:[SuggestionsFaviconInternalCell | |
63 reuseIdentifier] | |
64 forIndexPath:indexPath]; | |
65 cell.faviconView.image = [_faviconImages objectAtIndex:indexPath.item]; | |
66 cell.title.text = [_faviconTitles objectAtIndex:indexPath.item]; | |
67 return cell; | |
68 } | |
69 | |
70 - (NSInteger)collectionView:(UICollectionView*)collectionView | |
71 numberOfItemsInSection:(NSInteger)section { | |
72 DCHECK([_faviconImages count] == [_faviconTitles count]); | |
73 return [_faviconImages count]; | |
74 } | |
75 | |
76 #pragma mark - CollectionViewItem | |
77 | |
78 - (void)configureCell:(SuggestionsFaviconCell*)cell { | |
79 [super configureCell:cell]; | |
80 cell.collectionView.dataSource = self; | |
81 cell.delegate = self.delegate; | |
lpromero
2017/01/18 09:34:38
Add a prepareForReuse to the cell, where these are
gambard
2017/01/18 12:37:58
Done.
To reset the image and the title, I have add
lpromero
2017/01/18 13:14:02
Usually I reset everything I can have set in confi
gambard
2017/01/18 14:19:08
Acknowledged.
| |
82 } | |
83 | |
84 @end | |
85 | |
86 #pragma mark - SuggestionsFaviconCell | |
87 | |
88 // The cell is the delegate of the inner collection view. | |
89 @interface SuggestionsFaviconCell ()<UICollectionViewDelegate> | |
90 | |
91 @end | |
92 | |
93 @implementation SuggestionsFaviconCell | |
94 | |
95 @synthesize collectionView = _collectionView; | |
96 @synthesize delegate = _delegate; | |
97 | |
98 - (instancetype)initWithFrame:(CGRect)frame { | |
99 self = [super initWithFrame:frame]; | |
100 if (self) { | |
101 UICollectionViewFlowLayout* layout = | |
102 [[UICollectionViewFlowLayout alloc] init]; | |
103 layout.scrollDirection = UICollectionViewScrollDirectionHorizontal; | |
104 layout.minimumInteritemSpacing = kInternalCellSpacing; | |
105 layout.itemSize = CGSizeMake(kInternalCellWidth, kInternalCellHeight); | |
106 layout.sectionInset = UIEdgeInsetsMake(0, kInternalLeftSpacing, 0, 0); | |
107 | |
108 _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero | |
109 collectionViewLayout:layout]; | |
110 [_collectionView registerClass:[SuggestionsFaviconInternalCell class] | |
111 forCellWithReuseIdentifier:[SuggestionsFaviconInternalCell | |
112 reuseIdentifier]]; | |
113 _collectionView.backgroundColor = [UIColor clearColor]; | |
114 | |
115 _collectionView.delegate = self; | |
116 | |
117 [self.contentView addSubview:_collectionView]; | |
118 _collectionView.translatesAutoresizingMaskIntoConstraints = NO; | |
lpromero
2017/01/18 09:34:38
You might need to add that before adding as subvie
gambard
2017/01/18 12:37:58
Done.
I don't unsatisfiable constraints. I have so
lpromero
2017/01/18 13:14:02
What kind of ambiguous constraints log do you get?
gambard
2017/01/18 14:19:08
The title and description of the article are pinne
| |
119 AddSameSizeConstraint(_collectionView, self.contentView); | |
120 [_collectionView.heightAnchor constraintEqualToConstant:kInternalCellHeight] | |
121 .active = YES; | |
122 } | |
123 return self; | |
124 } | |
125 | |
126 #pragma mark - UICollectionViewDelegate | |
127 | |
128 - (void)collectionView:(UICollectionView*)collectionView | |
129 didSelectItemAtIndexPath:(NSIndexPath*)indexPath { | |
130 [self.delegate openFaviconAtIndexPath:indexPath]; | |
131 } | |
132 | |
133 @end | |
OLD | NEW |