From 8edb5a45d3d08001c4b1b9af9cf705a9fb8affaa Mon Sep 17 00:00:00 2001 From: Michael Schneider Date: Wed, 20 Feb 2019 11:21:47 -0800 Subject: [PATCH] Move ASSectionController and ASSupplementaryNodeSource method to be optional (#1302) --- Source/ASSectionController.h | 7 +++---- Source/ASSupplementaryNodeSource.h | 4 ++-- Source/Private/ASIGListAdapterBasedDataSource.mm | 16 ++++++++++++---- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/Source/ASSectionController.h b/Source/ASSectionController.h index 5d48bbef1f..6807596138 100644 --- a/Source/ASSectionController.h +++ b/Source/ASSectionController.h @@ -16,13 +16,14 @@ NS_ASSUME_NONNULL_BEGIN @class ASBatchContext; /** - * A protocol that your section controllers should conform to, - * in order to be used with AsyncDisplayKit. + * A protocol that your section controllers should conform to, in order to be used with Texture. * * @note Your supplementary view source should conform to @c ASSupplementaryNodeSource. */ @protocol ASSectionController +@optional + /** * A method to provide the node block for the item at the given index. * The node block you return will be run asynchronously off the main thread, @@ -48,8 +49,6 @@ NS_ASSUME_NONNULL_BEGIN */ - (ASCellNode *)nodeForItemAtIndex:(NSInteger)index; -@optional - /** * Asks the section controller whether it should batch fetch because the user is * near the end of the current data set. diff --git a/Source/ASSupplementaryNodeSource.h b/Source/ASSupplementaryNodeSource.h index 3d63a6900e..20bedddeec 100644 --- a/Source/ASSupplementaryNodeSource.h +++ b/Source/ASSupplementaryNodeSource.h @@ -15,6 +15,8 @@ NS_ASSUME_NONNULL_BEGIN @protocol ASSupplementaryNodeSource +@optional + /** * A method to provide the node-block for the supplementary element. * @@ -33,8 +35,6 @@ NS_ASSUME_NONNULL_BEGIN */ - (ASCellNode *)nodeForSupplementaryElementOfKind:(NSString *)kind atIndex:(NSInteger)index; -@optional - /** * A method to provide the size range used for measuring the supplementary * element of the given kind at the given index. diff --git a/Source/Private/ASIGListAdapterBasedDataSource.mm b/Source/Private/ASIGListAdapterBasedDataSource.mm index ade87eb581..3cf77afc0a 100644 --- a/Source/Private/ASIGListAdapterBasedDataSource.mm +++ b/Source/Private/ASIGListAdapterBasedDataSource.mm @@ -215,12 +215,16 @@ typedef struct { - (ASCellNodeBlock)collectionNode:(ASCollectionNode *)collectionNode nodeBlockForItemAtIndexPath:(NSIndexPath *)indexPath { - return [[self sectionControllerForSection:indexPath.section] nodeBlockForItemAtIndex:indexPath.item]; + ASIGSectionController *ctrl = [self sectionControllerForSection:indexPath.section]; + ASDisplayNodeAssert([ctrl respondsToSelector:@selector(nodeBlockForItemAtIndex:)], @"Expected section controller to respond to to %@. Controller: %@", NSStringFromSelector(@selector(nodeBlockForItemAtIndex:)), ctrl); + return [ctrl nodeBlockForItemAtIndex:indexPath.item]; } - (ASCellNode *)collectionNode:(ASCollectionNode *)collectionNode nodeForItemAtIndexPath:(NSIndexPath *)indexPath { - return [[self sectionControllerForSection:indexPath.section] nodeForItemAtIndex:indexPath.item]; + ASIGSectionController *ctrl = [self sectionControllerForSection:indexPath.section]; + ASDisplayNodeAssert([ctrl respondsToSelector:@selector(nodeForItemAtIndex:)], @"Expected section controller to respond to to %@. Controller: %@", NSStringFromSelector(@selector(nodeForItemAtIndex:)), ctrl); + return [ctrl nodeForItemAtIndex:indexPath.item]; } - (ASSizeRange)collectionNode:(ASCollectionNode *)collectionNode constrainedSizeForItemAtIndexPath:(NSIndexPath *)indexPath @@ -235,12 +239,16 @@ typedef struct { - (ASCellNodeBlock)collectionNode:(ASCollectionNode *)collectionNode nodeBlockForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath { - return [[self supplementaryElementSourceForSection:indexPath.section] nodeBlockForSupplementaryElementOfKind:kind atIndex:indexPath.item]; + id ctrl = [self supplementaryElementSourceForSection:indexPath.section]; + ASDisplayNodeAssert([ctrl respondsToSelector:@selector(nodeBlockForSupplementaryElementOfKind:atIndex:)], @"Expected section controller to respond to to %@. Controller: %@", NSStringFromSelector(@selector(nodeBlockForSupplementaryElementOfKind:atIndex:)), ctrl); + return [ctrl nodeBlockForSupplementaryElementOfKind:kind atIndex:indexPath.item]; } - (ASCellNode *)collectionNode:(ASCollectionNode *)collectionNode nodeForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath { - return [[self supplementaryElementSourceForSection:indexPath.section] nodeForSupplementaryElementOfKind:kind atIndex:indexPath.item]; + id ctrl = [self supplementaryElementSourceForSection:indexPath.section]; + ASDisplayNodeAssert([ctrl respondsToSelector:@selector(nodeForSupplementaryElementOfKind:atIndex:)], @"Expected section controller to respond to to %@. Controller: %@", NSStringFromSelector(@selector(nodeForSupplementaryElementOfKind:atIndex:)), ctrl); + return [ctrl nodeForSupplementaryElementOfKind:kind atIndex:indexPath.item]; } - (NSArray *)collectionNode:(ASCollectionNode *)collectionNode supplementaryElementKindsInSection:(NSInteger)section