Skip to content

Commit

Permalink
Move ASSectionController and ASSupplementaryNodeSource method to be o…
Browse files Browse the repository at this point in the history
…ptional (TextureGroup#1302)
  • Loading branch information
maicki authored Feb 20, 2019
1 parent d4a1242 commit 8edb5a4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
7 changes: 3 additions & 4 deletions Source/ASSectionController.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <NSObject>

@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,
Expand All @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions Source/ASSupplementaryNodeSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ NS_ASSUME_NONNULL_BEGIN

@protocol ASSupplementaryNodeSource <NSObject>

@optional

/**
* A method to provide the node-block for the supplementary element.
*
Expand All @@ -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.
Expand Down
16 changes: 12 additions & 4 deletions Source/Private/ASIGListAdapterBasedDataSource.mm
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,16 @@ - (NSInteger)numberOfSectionsInCollectionNode:(ASCollectionNode *)collectionNode

- (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
Expand All @@ -235,12 +239,16 @@ - (ASSizeRange)collectionNode:(ASCollectionNode *)collectionNode constrainedSize

- (ASCellNodeBlock)collectionNode:(ASCollectionNode *)collectionNode nodeBlockForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
return [[self supplementaryElementSourceForSection:indexPath.section] nodeBlockForSupplementaryElementOfKind:kind atIndex:indexPath.item];
id<ASSupplementaryNodeSource> 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<ASSupplementaryNodeSource> 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<NSString *> *)collectionNode:(ASCollectionNode *)collectionNode supplementaryElementKindsInSection:(NSInteger)section
Expand Down

0 comments on commit 8edb5a4

Please sign in to comment.