diff --git a/AsyncDisplayKit/ASCollectionView.h b/AsyncDisplayKit/ASCollectionView.h index ca86cf3a..49ea6420 100644 --- a/AsyncDisplayKit/ASCollectionView.h +++ b/AsyncDisplayKit/ASCollectionView.h @@ -276,14 +276,18 @@ NS_ASSUME_NONNULL_BEGIN - (void)moveItemAtIndexPath:(NSIndexPath *)indexPath toIndexPath:(NSIndexPath *)newIndexPath; /** - * Similar to -cellForItemAtIndexPath:. + * Retrieves the node for the row at the given index path, in the data source's index space. * * @param indexPath The index path of the requested node. - * - * @return a node for display at this indexpath or nil */ - (nullable ASCellNode *)nodeForItemAtIndexPath:(NSIndexPath *)indexPath; +/** + * Retrieves the node for the item at the given index path, in UICollectionView's index space. + * + * @param indexPath The index path of the requested node. + */ +- (nullable ASCellNode *)nodeForItemAtCompletedIndexPath:(NSIndexPath *)indexPath; /** * Similar to -supplementaryViewForElementKind:atIndexPath: @@ -316,13 +320,6 @@ NS_ASSUME_NONNULL_BEGIN */ - (NSArray *)visibleNodes; -/** - * Query the sized node at `indexPath` for its calculatedSize. - * - * @param indexPath The index path for the node of interest. - */ -- (CGSize)calculatedSizeForNodeAtIndexPath:(NSIndexPath *)indexPath; - /** * Determines collection view's current scroll direction. Supports 2-axis collection views. * @@ -363,6 +360,19 @@ NS_ASSUME_NONNULL_BEGIN @end +@interface ASCollectionView (Deprecated) + +/** + * Query the sized node at `indexPath` for its calculatedSize. + * + * @param indexPath The index path for the node of interest. + * + * @deprecated Call @c calculatedSize for the node of interest instead. + */ +- (CGSize)calculatedSizeForNodeAtIndexPath:(NSIndexPath *)indexPath ASDISPLAYNODE_DEPRECATED; + +@end + /** * This is a node-based UICollectionViewDataSource. diff --git a/AsyncDisplayKit/ASCollectionView.mm b/AsyncDisplayKit/ASCollectionView.mm index c868aa3e..b815473c 100644 --- a/AsyncDisplayKit/ASCollectionView.mm +++ b/AsyncDisplayKit/ASCollectionView.mm @@ -481,6 +481,11 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell"; return [_dataController nodeAtIndexPath:indexPath]; } +- (ASCellNode *)nodeForItemAtCompletedIndexPath:(NSIndexPath *)indexPath +{ + return [_dataController nodeAtCompletedIndexPath:indexPath]; +} + - (ASCellNode *)supplementaryNodeForElementKind:(NSString *)elementKind atIndexPath:(NSIndexPath *)indexPath { return [_dataController supplementaryNodeOfKind:elementKind atIndexPath:indexPath]; diff --git a/AsyncDisplayKit/ASTableView.h b/AsyncDisplayKit/ASTableView.h index f9f41fb5..b0e7567a 100644 --- a/AsyncDisplayKit/ASTableView.h +++ b/AsyncDisplayKit/ASTableView.h @@ -272,14 +272,19 @@ NS_ASSUME_NONNULL_BEGIN - (void)moveRowAtIndexPath:(NSIndexPath *)indexPath toIndexPath:(NSIndexPath *)newIndexPath; /** - * Similar to -cellForRowAtIndexPath:. + * Retrieves the node for the row at the given index path, in the data source's index space. * * @param indexPath The index path of the requested node. - * - * @return a node for display at this indexpath. */ - (nullable ASCellNode *)nodeForRowAtIndexPath:(NSIndexPath *)indexPath; +/** + * Retrieves the node for the row at the given index path, in UITableView's index space. + * + * @param indexPath The index path of the requested node. + */ +- (nullable ASCellNode *)nodeForRowAtCompletedIndexPath:(NSIndexPath *)indexPath; + /** * Similar to -indexPathForCell:. * diff --git a/AsyncDisplayKit/ASTableView.mm b/AsyncDisplayKit/ASTableView.mm index ab7f4ec5..e49b382a 100644 --- a/AsyncDisplayKit/ASTableView.mm +++ b/AsyncDisplayKit/ASTableView.mm @@ -414,6 +414,11 @@ static NSString * const kCellReuseIdentifier = @"_ASTableViewCell"; return [_dataController nodeAtIndexPath:indexPath]; } +- (ASCellNode *)nodeForRowAtCompletedIndexPath:(NSIndexPath *)indexPath +{ + return [_dataController nodeAtCompletedIndexPath:indexPath]; +} + - (NSIndexPath *)indexPathForNode:(ASCellNode *)cellNode { return [_dataController indexPathForNode:cellNode]; diff --git a/AsyncDisplayKit/Details/ASDataController.h b/AsyncDisplayKit/Details/ASDataController.h index 3ad1ae1e..d328ac97 100644 --- a/AsyncDisplayKit/Details/ASDataController.h +++ b/AsyncDisplayKit/Details/ASDataController.h @@ -181,6 +181,8 @@ FOUNDATION_EXPORT NSString * const ASDataControllerRowNodeKind; - (nullable ASCellNode *)nodeAtIndexPath:(NSIndexPath *)indexPath; +- (nullable ASCellNode *)nodeAtCompletedIndexPath:(NSIndexPath *)indexPath; + /** * @return The index path, in the data source's index space, for the given node. */ diff --git a/AsyncDisplayKit/Details/ASDataController.mm b/AsyncDisplayKit/Details/ASDataController.mm index 3bc26d65..d1933a71 100644 --- a/AsyncDisplayKit/Details/ASDataController.mm +++ b/AsyncDisplayKit/Details/ASDataController.mm @@ -915,6 +915,25 @@ NSString * const ASDataControllerRowNodeKind = @"_ASDataControllerRowNodeKind"; return context.node; } +- (ASCellNode *)nodeAtCompletedIndexPath:(NSIndexPath *)indexPath +{ + ASDisplayNodeAssertMainThread(); + + NSArray *completedNodes = [self completedNodes]; + NSInteger section = indexPath.section; + NSInteger row = indexPath.row; + ASCellNode *node = nil; + + if (section >= 0 && row >= 0 && section < completedNodes.count) { + NSArray *completedNodesSection = completedNodes[section]; + if (row < completedNodesSection.count) { + node = completedNodesSection[row]; + } + } + + return node; +} + - (NSIndexPath *)indexPathForNode:(ASCellNode *)cellNode; { ASDisplayNodeAssertMainThread(); diff --git a/AsyncDisplayKitTests/ASCollectionViewTests.mm b/AsyncDisplayKitTests/ASCollectionViewTests.mm index 516c3121..1fdbafd1 100644 --- a/AsyncDisplayKitTests/ASCollectionViewTests.mm +++ b/AsyncDisplayKitTests/ASCollectionViewTests.mm @@ -450,14 +450,14 @@ { updateValidationTestPrologue id layout = cv.collectionViewLayout; - CGSize initialItemSize = [cv calculatedSizeForNodeAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]]; + CGSize initialItemSize = [cv nodeForItemAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]].calculatedSize; CGSize initialCVSize = cv.bounds.size; // Capture the node size before first call to prepareLayout after frame change. __block CGSize itemSizeAtFirstLayout = CGSizeZero; __block CGSize boundsSizeAtFirstLayout = CGSizeZero; [[[[layout expect] andDo:^(NSInvocation *) { - itemSizeAtFirstLayout = [cv calculatedSizeForNodeAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]]; + itemSizeAtFirstLayout = [cv nodeForItemAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]].calculatedSize; boundsSizeAtFirstLayout = [cv bounds].size; }] andForwardToRealObject] prepareLayout]; @@ -465,7 +465,7 @@ UIDeviceOrientation oldDeviceOrientation = [[UIDevice currentDevice] orientation]; [[UIDevice currentDevice] setValue:@(UIDeviceOrientationLandscapeLeft) forKey:@"orientation"]; - CGSize finalItemSize = [cv calculatedSizeForNodeAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]]; + CGSize finalItemSize = [cv nodeForItemAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]].calculatedSize; CGSize finalCVSize = cv.bounds.size; XCTAssertNotEqualObjects(NSStringFromCGSize(initialItemSize), NSStringFromCGSize(itemSizeAtFirstLayout)); XCTAssertNotEqualObjects(NSStringFromCGSize(initialCVSize), NSStringFromCGSize(boundsSizeAtFirstLayout));