Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(250)

Side by Side Diff: ios/chrome/browser/ui/collection_view/collection_view_controller.mm

Issue 2738743005: Add a way to reconfigure cell from IndexPaths (Closed)
Patch Set: Add a comment Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "ios/chrome/browser/ui/collection_view/collection_view_controller.h" 5 #import "ios/chrome/browser/ui/collection_view/collection_view_controller.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/mac/foundation_util.h" 8 #include "base/mac/foundation_util.h"
9 #import "base/mac/scoped_nsobject.h" 9 #import "base/mac/scoped_nsobject.h"
10 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h" 10 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 - (void)loadModel { 67 - (void)loadModel {
68 _collectionViewModel.reset([[CollectionViewModel alloc] init]); 68 _collectionViewModel.reset([[CollectionViewModel alloc] init]);
69 } 69 }
70 70
71 - (void)reconfigureCellsForItems:(NSArray*)items 71 - (void)reconfigureCellsForItems:(NSArray*)items
72 inSectionWithIdentifier:(NSInteger)sectionIdentifier { 72 inSectionWithIdentifier:(NSInteger)sectionIdentifier {
73 for (CollectionViewItem* item in items) { 73 for (CollectionViewItem* item in items) {
74 NSIndexPath* indexPath = 74 NSIndexPath* indexPath =
75 [self.collectionViewModel indexPathForItem:item 75 [self.collectionViewModel indexPathForItem:item
76 inSectionWithIdentifier:sectionIdentifier]; 76 inSectionWithIdentifier:sectionIdentifier];
77 MDCCollectionViewCell* cell = 77 [self reconfigureCellAtIndexPath:indexPath withItem:item];
78 base::mac::ObjCCastStrict<MDCCollectionViewCell>(
79 [self.collectionView cellForItemAtIndexPath:indexPath]);
80
81 // |cell| may be nil if the row is not currently on screen.
82 if (cell) {
83 [item configureCell:cell];
84 }
85 } 78 }
86 } 79 }
87 80
81 - (void)reconfigureCellsAtIndexPaths:(NSArray*)indexPaths {
82 for (NSIndexPath* indexPath in indexPaths) {
83 CollectionViewItem* item =
84 [self.collectionViewModel itemAtIndexPath:indexPath];
85 [self reconfigureCellAtIndexPath:indexPath withItem:item];
86 }
87 }
88
88 #pragma mark MDCCollectionViewEditingDelegate 89 #pragma mark MDCCollectionViewEditingDelegate
89 90
90 - (void)collectionView:(UICollectionView*)collectionView 91 - (void)collectionView:(UICollectionView*)collectionView
91 willDeleteItemsAtIndexPaths:(NSArray*)indexPaths { 92 willDeleteItemsAtIndexPaths:(NSArray*)indexPaths {
92 // Check that the parent class doesn't implement this method. Otherwise, it 93 // Check that the parent class doesn't implement this method. Otherwise, it
93 // would need to be called here. 94 // would need to be called here.
94 DCHECK([self isKindOfClass:[MDCCollectionViewController class]]); 95 DCHECK([self isKindOfClass:[MDCCollectionViewController class]]);
95 DCHECK(![MDCCollectionViewController instancesRespondToSelector:_cmd]); 96 DCHECK(![MDCCollectionViewController instancesRespondToSelector:_cmd]);
96 97
97 // Sort and enumerate in reverse order to delete the items from the collection 98 // Sort and enumerate in reverse order to delete the items from the collection
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 targetContentOffset:(inout CGPoint*)targetContentOffset { 262 targetContentOffset:(inout CGPoint*)targetContentOffset {
262 MDCFlexibleHeaderView* headerView = 263 MDCFlexibleHeaderView* headerView =
263 self.appBar.headerViewController.headerView; 264 self.appBar.headerViewController.headerView;
264 if (scrollView == headerView.trackingScrollView) { 265 if (scrollView == headerView.trackingScrollView) {
265 [headerView 266 [headerView
266 trackingScrollViewWillEndDraggingWithVelocity:velocity 267 trackingScrollViewWillEndDraggingWithVelocity:velocity
267 targetContentOffset:targetContentOffset]; 268 targetContentOffset:targetContentOffset];
268 } 269 }
269 } 270 }
270 271
272 #pragma mark - Private
273
274 // Reconfigures the cell at |indexPath| by calling |configureCell:| with |item|.
275 - (void)reconfigureCellAtIndexPath:(NSIndexPath*)indexPath
276 withItem:(CollectionViewItem*)item {
277 MDCCollectionViewCell* cell =
278 base::mac::ObjCCastStrict<MDCCollectionViewCell>(
279 [self.collectionView cellForItemAtIndexPath:indexPath]);
280
281 // |cell| may be nil if the row is not currently on screen.
282 if (cell) {
283 [item configureCell:cell];
284 }
285 }
286
271 @end 287 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698