From d69dd880a5c03fea46cfd692c1067eeeac3c672e Mon Sep 17 00:00:00 2001 From: Colin McArdell and Robin Chou Date: Mon, 20 Jun 2016 18:24:07 -0400 Subject: [PATCH 1/4] Exposing `supplementaryNodeOfKind:atIndexPath:` in the `ASCollectionView` interface. --- AsyncDisplayKit/ASCollectionView.h | 2 ++ AsyncDisplayKit/ASCollectionView.mm | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/AsyncDisplayKit/ASCollectionView.h b/AsyncDisplayKit/ASCollectionView.h index 9b7fe864b5..015f2cd3b3 100644 --- a/AsyncDisplayKit/ASCollectionView.h +++ b/AsyncDisplayKit/ASCollectionView.h @@ -282,6 +282,8 @@ NS_ASSUME_NONNULL_BEGIN */ - (ASCellNode *)nodeForItemAtIndexPath:(NSIndexPath *)indexPath; +- (ASCellNode *)supplementaryNodeOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath; + /** * Similar to -indexPathForCell:. * diff --git a/AsyncDisplayKit/ASCollectionView.mm b/AsyncDisplayKit/ASCollectionView.mm index 68031f464a..0ea30e853a 100644 --- a/AsyncDisplayKit/ASCollectionView.mm +++ b/AsyncDisplayKit/ASCollectionView.mm @@ -444,6 +444,11 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell"; return [_dataController nodeAtIndexPath:indexPath]; } +- (ASCellNode *)supplementaryNodeOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath +{ + return [_dataController supplementaryNodeOfKind:kind atIndexPath:indexPath]; +} + - (NSIndexPath *)indexPathForNode:(ASCellNode *)cellNode { return [_dataController indexPathForNode:cellNode]; From 488ded2fe88212eac9cb57ed9d3c9eb35e5f3822 Mon Sep 17 00:00:00 2001 From: Colin McArdell and Robin Chou Date: Mon, 20 Jun 2016 18:25:30 -0400 Subject: [PATCH 2/4] `ASCollectionDataController`s `supplementaryNodeOfKind:atIndexPath:` now returns `nil` instead of an assertion if the supplementary node of kind doesn't exist within `completedNodesOfKind` --- AsyncDisplayKit/Details/ASCollectionDataController.mm | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/AsyncDisplayKit/Details/ASCollectionDataController.mm b/AsyncDisplayKit/Details/ASCollectionDataController.mm index b54583c2a2..fea9981724 100644 --- a/AsyncDisplayKit/Details/ASCollectionDataController.mm +++ b/AsyncDisplayKit/Details/ASCollectionDataController.mm @@ -305,8 +305,7 @@ return nodesOfKindInSection[itemIndex]; } } - ASDisplayNodeAssert(NO, @"Supplementary node should exist. Kind = %@, indexPath = %@, collectionDataSource = %@", kind, indexPath, self.collectionDataSource); - return [[ASCellNode alloc] init]; + return nil; } #pragma mark - Private Helpers From 1c103333f792b75173146d18bdd674b1c1883c4c Mon Sep 17 00:00:00 2001 From: Colin McArdell and Robin Chou Date: Tue, 21 Jun 2016 10:27:59 -0400 Subject: [PATCH 3/4] `ASCollectionView` docs for `-supplementaryNodeOfKind:atIndexPath:` + nullability. Also, nullability for `-nodeForItemAtIndexPath:` --- AsyncDisplayKit/ASCollectionView.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/AsyncDisplayKit/ASCollectionView.h b/AsyncDisplayKit/ASCollectionView.h index 015f2cd3b3..519705fc97 100644 --- a/AsyncDisplayKit/ASCollectionView.h +++ b/AsyncDisplayKit/ASCollectionView.h @@ -278,11 +278,19 @@ NS_ASSUME_NONNULL_BEGIN * * @param indexPath The index path of the requested node. * - * @returns a node for display at this indexpath. + * @returns a node for display at this indexpath or nil */ -- (ASCellNode *)nodeForItemAtIndexPath:(NSIndexPath *)indexPath; +- (nullable ASCellNode *)nodeForItemAtIndexPath:(NSIndexPath *)indexPath; -- (ASCellNode *)supplementaryNodeOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath; + +/** + * Similar to -collectionView:viewForSupplementaryElementOfKind:atIndexPath:. + * + * @param indexPath The index path of the requested supplementary node. + * + * @returns a supplementary node for display at this indexpath or nil + */ +- (nullable ASCellNode *)supplementaryNodeOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath; /** * Similar to -indexPathForCell:. From 9c130185685c65ebacad7156b147b8e98c62c41f Mon Sep 17 00:00:00 2001 From: Colin McArdell and Robin Chou Date: Wed, 22 Jun 2016 15:41:24 -0400 Subject: [PATCH 4/4] Updates exposed method signature and docs for what is now `-supplementaryNodeForElementKind:atIndexPath:` on `ASCollectionView`. Assert non-nil for usage of `ASCollectionDataController`s `-supplementaryNodeOfKind:atIndexPath:` within `ASCollectionView` --- AsyncDisplayKit/ASCollectionView.h | 7 ++++--- AsyncDisplayKit/ASCollectionView.mm | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/AsyncDisplayKit/ASCollectionView.h b/AsyncDisplayKit/ASCollectionView.h index 519705fc97..dd9db56bc3 100644 --- a/AsyncDisplayKit/ASCollectionView.h +++ b/AsyncDisplayKit/ASCollectionView.h @@ -284,13 +284,14 @@ NS_ASSUME_NONNULL_BEGIN /** - * Similar to -collectionView:viewForSupplementaryElementOfKind:atIndexPath:. + * Similar to -supplementaryViewForElementKind:atIndexPath: * + * @param elementKind The kind of supplementary node to locate. * @param indexPath The index path of the requested supplementary node. * - * @returns a supplementary node for display at this indexpath or nil + * @returns The specified supplementary node or nil */ -- (nullable ASCellNode *)supplementaryNodeOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath; +- (nullable ASCellNode *)supplementaryNodeForElementKind:(NSString *)elementKind atIndexPath:(NSIndexPath *)indexPath; /** * Similar to -indexPathForCell:. diff --git a/AsyncDisplayKit/ASCollectionView.mm b/AsyncDisplayKit/ASCollectionView.mm index 0ea30e853a..74c51e614a 100644 --- a/AsyncDisplayKit/ASCollectionView.mm +++ b/AsyncDisplayKit/ASCollectionView.mm @@ -444,9 +444,9 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell"; return [_dataController nodeAtIndexPath:indexPath]; } -- (ASCellNode *)supplementaryNodeOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath +- (ASCellNode *)supplementaryNodeForElementKind:(NSString *)elementKind atIndexPath:(NSIndexPath *)indexPath { - return [_dataController supplementaryNodeOfKind:kind atIndexPath:indexPath]; + return [_dataController supplementaryNodeOfKind:elementKind atIndexPath:indexPath]; } - (NSIndexPath *)indexPathForNode:(ASCellNode *)cellNode @@ -577,6 +577,7 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell"; NSString *identifier = [self __reuseIdentifierForKind:kind]; UICollectionReusableView *view = [self dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:identifier forIndexPath:indexPath]; ASCellNode *node = [_dataController supplementaryNodeOfKind:kind atIndexPath:indexPath]; + ASDisplayNodeAssert(node != nil, @"Supplementary node should exist. Kind = %@, indexPath = %@, collectionDataSource = %@", kind, indexPath, self); [_rangeController configureContentView:view forCellNode:node]; return view; }