From 68e58bf60e41dc56ec2e92881a82bc838b322a82 Mon Sep 17 00:00:00 2001 From: Andy Wang Date: Mon, 9 Mar 2020 17:46:34 -0700 Subject: [PATCH] Add fullyVisibleCellsForSectionController to IGListCollectionContext [IGListKit] Reviewed By: chritto Differential Revision: D20261859 fbshipit-source-id: 919132f935462c2a57270f0afaba511adc936995 --- Source/IGListKit/IGListAdapter.m | 16 ++++++++++++++++ Source/IGListKit/IGListCollectionContext.h | 9 +++++++++ 2 files changed, 25 insertions(+) diff --git a/Source/IGListKit/IGListAdapter.m b/Source/IGListKit/IGListAdapter.m index 033aaa87..4c2741df 100644 --- a/Source/IGListKit/IGListAdapter.m +++ b/Source/IGListKit/IGListAdapter.m @@ -927,6 +927,22 @@ return nil; } +- (NSArray *)fullyVisibleCellsForSectionController:(IGListSectionController *)sectionController { + NSMutableArray *cells = [NSMutableArray new]; + UICollectionView *collectionView = self.collectionView; + NSArray *visibleCells = [collectionView visibleCells]; + const NSInteger section = [self sectionForSectionController:sectionController]; + for (UICollectionViewCell *cell in visibleCells) { + if ([collectionView indexPathForCell:cell].section == section) { + const CGRect cellRect = [cell convertRect:cell.bounds toView:collectionView]; + if (CGRectContainsRect(UIEdgeInsetsInsetRect(collectionView.bounds, collectionView.contentInset), cellRect)) { + [cells addObject:cell]; + } + } + } + return cells; +} + - (NSArray *)visibleCellsForSectionController:(IGListSectionController *)sectionController { NSMutableArray *cells = [NSMutableArray new]; UICollectionView *collectionView = self.collectionView; diff --git a/Source/IGListKit/IGListCollectionContext.h b/Source/IGListKit/IGListCollectionContext.h index 29bd3f32..be16b3ea 100644 --- a/Source/IGListKit/IGListCollectionContext.h +++ b/Source/IGListKit/IGListCollectionContext.h @@ -85,6 +85,15 @@ NS_SWIFT_NAME(ListCollectionContext) - (nullable __kindof UICollectionViewCell *)cellForItemAtIndex:(NSInteger)index sectionController:(IGListSectionController *)sectionController; +/** + Returns the fully visible cells for the given section controller. + + @param sectionController The section controller requesting this information. + + @return An array of fully visible cells, or an empty array if none are found. + */ +- (NSArray *)fullyVisibleCellsForSectionController:(IGListSectionController *)sectionController; + /** Returns the visible cells for the given section controller.