[ASCollectionNode] add -indexPathsForVisibleNodes (#2451)

This commit is contained in:
Hannah Troisi
2016-10-21 10:19:27 -07:00
committed by Adlai Holler
parent 9719357901
commit 15aa784fe8
2 changed files with 19 additions and 0 deletions

View File

@@ -313,6 +313,12 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (nullable NSIndexPath *)indexPathForNode:(ASCellNode *)cellNode AS_WARN_UNUSED_RESULT;
/**
* Retrieve the index paths of all visible items.
*
* @return an array containing the index paths of all visible items. This must be called on the main thread.
*/
- (NSArray<__kindof NSIndexPath *> *)indexPathsForVisibleItems AS_WARN_UNUSED_RESULT;
/**
* Retrieves the context object for the given section, as provided by the data source in

View File

@@ -295,6 +295,19 @@
return [self.dataController indexPathForNode:cellNode];
}
- (NSArray<__kindof NSIndexPath *> *)indexPathsForVisibleItems
{
NSMutableArray *indexPathsArray = [NSMutableArray new];
for (ASCellNode *cell in [self visibleNodes]) {
NSIndexPath *indexPath = [self indexPathForNode:cell];
if (indexPath) {
[indexPathsArray addObject:indexPath];
}
}
return indexPathsArray;
}
- (ASCellNode *)nodeForItemAtIndexPath:(NSIndexPath *)indexPath
{
return [self.dataController nodeAtIndexPath:indexPath];