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

Unified Diff: ios/chrome/browser/ui/collection_view/collection_view_model.mm

Issue 2761263003: Allow CollectionViewModel/Controller queries without SectionIdentifier (Closed)
Patch Set: Cleanup Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: ios/chrome/browser/ui/collection_view/collection_view_model.mm
diff --git a/ios/chrome/browser/ui/collection_view/collection_view_model.mm b/ios/chrome/browser/ui/collection_view/collection_view_model.mm
index 0866b37bdafde7636ef71ab9c88f608417224f14..5825f6e1103ebb33669fbf34ecd3c6c50bbd7d53 100644
--- a/ios/chrome/browser/ui/collection_view/collection_view_model.mm
+++ b/ios/chrome/browser/ui/collection_view/collection_view_model.mm
@@ -256,15 +256,23 @@ typedef NSMutableArray<CollectionViewItem*> SectionItems;
indexOfObject:item] != NSNotFound;
}
-- (NSIndexPath*)indexPathForItem:(CollectionViewItem*)item
- inSectionWithIdentifier:(NSInteger)sectionIdentifier {
- NSArray* itemsInSection =
- [self itemsInSectionWithIdentifier:sectionIdentifier];
+- (BOOL)hasItem:(CollectionViewItem*)item {
+ for (NSNumber* section in _sectionIdentifiers) {
+ if ([self hasItem:item inSectionWithIdentifier:[section integerValue]])
+ return YES;
+ }
+ return NO;
+}
- NSInteger section = [self sectionForSectionIdentifier:sectionIdentifier];
- NSInteger itemIndex = [itemsInSection indexOfObject:item];
- DCHECK_NE(NSNotFound, itemIndex);
- return [NSIndexPath indexPathForItem:itemIndex inSection:section];
+- (NSIndexPath*)indexPathForItem:(CollectionViewItem*)item {
+ for (NSUInteger section = 0; section < _sections.count; section++) {
+ NSInteger itemIndex = [_sections[section] indexOfObject:item];
+ if (itemIndex != NSNotFound) {
+ return [NSIndexPath indexPathForItem:itemIndex inSection:section];
+ }
+ }
+ NOTREACHED();
+ return nil;
}
#pragma mark UICollectionView data sourcing

Powered by Google App Engine
This is Rietveld 408576698