diff --git a/AsyncDisplayKit/ASCollectionNode.h b/AsyncDisplayKit/ASCollectionNode.h index 6e3c5fd9ad..d5d799d68a 100644 --- a/AsyncDisplayKit/ASCollectionNode.h +++ b/AsyncDisplayKit/ASCollectionNode.h @@ -335,9 +335,9 @@ NS_ASSUME_NONNULL_BEGIN /** * Similar to -visibleCells. * - * @return an array containing the nodes being displayed on screen. + * @return an array containing the nodes being displayed on screen. This must be called on the main thread. */ -- (NSArray<__kindof ASCellNode *> *)visibleNodes AS_WARN_UNUSED_RESULT; +@property(readonly, copy) NSArray<__kindof ASCellNode *> *visibleNodes; /** * Retrieves the node for the item at the given index path. diff --git a/AsyncDisplayKit/ASCollectionNode.mm b/AsyncDisplayKit/ASCollectionNode.mm index b9dcc1c676..69f8bc25d6 100644 --- a/AsyncDisplayKit/ASCollectionNode.mm +++ b/AsyncDisplayKit/ASCollectionNode.mm @@ -349,7 +349,8 @@ - (NSArray<__kindof ASCellNode *> *)visibleNodes { - return [self.view visibleNodes]; + ASDisplayNodeAssertMainThread(); + return self.isNodeLoaded ? [self.view visibleNodes] : @[]; } - (NSIndexPath *)indexPathForNode:(ASCellNode *)cellNode diff --git a/AsyncDisplayKit/ASTableNode.h b/AsyncDisplayKit/ASTableNode.h index 3111704b54..540f644aaf 100644 --- a/AsyncDisplayKit/ASTableNode.h +++ b/AsyncDisplayKit/ASTableNode.h @@ -339,6 +339,13 @@ NS_ASSUME_NONNULL_BEGIN */ - (NSInteger)tableNode:(ASTableNode *)tableNode numberOfRowsInSection:(NSInteger)section; +/** + * Similar to -visibleCells. + * + * @return an array containing the nodes being displayed on screen. This must be called on the main thread. + */ +@property(readonly, copy) NSArray<__kindof ASCellNode *> *visibleNodes; + /** * Asks the data source for a block to create a node to represent the row at the given index path. * The block will be run by the table node concurrently in the background before the row is inserted diff --git a/AsyncDisplayKit/ASTableNode.mm b/AsyncDisplayKit/ASTableNode.mm index 5fa32a1425..f2f2f7e126 100644 --- a/AsyncDisplayKit/ASTableNode.mm +++ b/AsyncDisplayKit/ASTableNode.mm @@ -371,6 +371,12 @@ ASEnvironmentCollectionTableSetEnvironmentState(_environmentStateLock) return [self.dataController numberOfSections]; } +- (NSArray<__kindof ASCellNode *> *)visibleNodes +{ + ASDisplayNodeAssertMainThread(); + return self.isNodeLoaded ? [self.view visibleNodes] : @[]; +} + - (NSIndexPath *)indexPathForNode:(ASCellNode *)cellNode { return [self.dataController indexPathForNode:cellNode];