mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2026-02-04 02:15:47 +00:00
Add collectionNode:nodeBlockForSupplementaryElementOfKind:atIndexPath: (#3078)
* Add optional support for nodeBlockForSupplementaryElementOfKind: * Update example * Update harder
This commit is contained in:
@@ -480,6 +480,15 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
*/
|
||||
- (ASCellNode *)collectionNode:(ASCollectionNode *)collectionNode nodeForItemAtIndexPath:(NSIndexPath *)indexPath;
|
||||
|
||||
/**
|
||||
* Asks the data source to provide a node-block to display for the given supplementary element in the collection view.
|
||||
*
|
||||
* @param collectionNode The sender.
|
||||
* @param kind The kind of supplementary element.
|
||||
* @param indexPath The index path of the supplementary element.
|
||||
*/
|
||||
- (ASCellNodeBlock)collectionNode:(ASCollectionNode *)collectionNode nodeBlockForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath;
|
||||
|
||||
/**
|
||||
* Asks the data source to provide a node to display for the given supplementary element in the collection view.
|
||||
*
|
||||
|
||||
@@ -190,6 +190,7 @@ static NSString * const kReuseIdentifier = @"_ASCollectionReuseIdentifier";
|
||||
unsigned int collectionNodeNodeForItem:1;
|
||||
unsigned int collectionNodeNodeBlockForItem:1;
|
||||
unsigned int collectionNodeNodeForSupplementaryElement:1;
|
||||
unsigned int collectionNodeNodeBlockForSupplementaryElement:1;
|
||||
unsigned int collectionNodeSupplementaryElementKindsInSection:1;
|
||||
unsigned int numberOfSectionsInCollectionNode:1;
|
||||
unsigned int collectionNodeNumberOfItemsInSection:1;
|
||||
@@ -422,6 +423,7 @@ static NSString * const kReuseIdentifier = @"_ASCollectionReuseIdentifier";
|
||||
_asyncDataSourceFlags.collectionNodeNumberOfItemsInSection = [_asyncDataSource respondsToSelector:@selector(collectionNode:numberOfItemsInSection:)];
|
||||
_asyncDataSourceFlags.collectionNodeContextForSection = [_asyncDataSource respondsToSelector:@selector(collectionNode:contextForSection:)];
|
||||
_asyncDataSourceFlags.collectionNodeNodeForSupplementaryElement = [_asyncDataSource respondsToSelector:@selector(collectionNode:nodeForSupplementaryElementOfKind:atIndexPath:)];
|
||||
_asyncDataSourceFlags.collectionNodeNodeBlockForSupplementaryElement = [_asyncDataSource respondsToSelector:@selector(collectionNode:nodeBlockForSupplementaryElementOfKind:atIndexPath:)];
|
||||
_asyncDataSourceFlags.collectionNodeSupplementaryElementKindsInSection = [_asyncDataSource respondsToSelector:@selector(collectionNode:supplementaryElementKindsInSection:)];
|
||||
|
||||
_asyncDataSourceFlags.interop = [_asyncDataSource conformsToProtocol:@protocol(ASCollectionDataSourceInterop)];
|
||||
@@ -1555,25 +1557,35 @@ static NSString * const kReuseIdentifier = @"_ASCollectionReuseIdentifier";
|
||||
|
||||
- (ASCellNodeBlock)dataController:(ASDataController *)dataController supplementaryNodeBlockOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
//TODO _asyncDataSource to support supplementary node block and deprecate nodeForSupplementaryElementOfKind
|
||||
ASCellNode *node = nil;
|
||||
if (_asyncDataSourceFlags.collectionNodeNodeForSupplementaryElement) {
|
||||
ASCellNodeBlock nodeBlock = nil;
|
||||
if (_asyncDataSourceFlags.collectionNodeNodeBlockForSupplementaryElement) {
|
||||
GET_COLLECTIONNODE_OR_RETURN(collectionNode, ^{ return [[ASCellNode alloc] init]; });
|
||||
node = [_asyncDataSource collectionNode:collectionNode nodeForSupplementaryElementOfKind:kind atIndexPath:indexPath];
|
||||
nodeBlock = [_asyncDataSource collectionNode:collectionNode nodeBlockForSupplementaryElementOfKind:kind atIndexPath:indexPath];
|
||||
ASDisplayNodeAssert(nodeBlock != nil, @"A node block must be returned for supplementary element of kind '%@' at index path '%@'", kind, indexPath);
|
||||
} else if (_asyncDataSourceFlags.collectionNodeNodeForSupplementaryElement) {
|
||||
GET_COLLECTIONNODE_OR_RETURN(collectionNode, ^{ return [[ASCellNode alloc] init]; });
|
||||
ASCellNode *node = [_asyncDataSource collectionNode:collectionNode nodeForSupplementaryElementOfKind:kind atIndexPath:indexPath];
|
||||
ASDisplayNodeAssert(node != nil, @"A node must be returned for supplementary element of kind '%@' at index path '%@'", kind, indexPath);
|
||||
nodeBlock = ^{ return node; };
|
||||
} else if (_asyncDataSourceFlags.collectionViewNodeForSupplementaryElement) {
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
node = [_asyncDataSource collectionView:self nodeForSupplementaryElementOfKind:kind atIndexPath:indexPath];
|
||||
ASCellNode *node = [_asyncDataSource collectionView:self nodeForSupplementaryElementOfKind:kind atIndexPath:indexPath];
|
||||
ASDisplayNodeAssert(node != nil, @"A node must be returned for supplementary element of kind '%@' at index path '%@'", kind, indexPath);
|
||||
nodeBlock = ^{ return node; };
|
||||
#pragma clang diagnostic pop
|
||||
}
|
||||
|
||||
if (node == nil && _asyncDataSourceFlags.interop) {
|
||||
node = [[ASCellNode alloc] init];
|
||||
node.shouldUseUIKitCell = YES;
|
||||
if (nodeBlock == nil) {
|
||||
BOOL useUIKitCell = _asyncDataSourceFlags.interop;
|
||||
nodeBlock = ^{
|
||||
ASCellNode *node = [[ASCellNode alloc] init];
|
||||
node.shouldUseUIKitCell = useUIKitCell;
|
||||
return node;
|
||||
};
|
||||
}
|
||||
|
||||
ASDisplayNodeAssert(node != nil, @"A node must be returned for supplementary element of kind '%@' at index path '%@'", kind, indexPath);
|
||||
return ^{ return node; };
|
||||
|
||||
return nodeBlock;
|
||||
}
|
||||
|
||||
- (NSArray<NSString *> *)dataController:(ASDataController *)dataController supplementaryNodeKindsInSections:(NSIndexSet *)sections
|
||||
|
||||
@@ -16,14 +16,14 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
@protocol ASSupplementaryNodeSource <NSObject>
|
||||
|
||||
/**
|
||||
* A method to provide the node for the item at the given index.
|
||||
* A method to provide the node-block for the supplementary element.
|
||||
*
|
||||
* @param elementKind The kind of supplementary element.
|
||||
* @param index The index of the item.
|
||||
* @return A node for the supplementary element.
|
||||
* @return A node block for the supplementary element.
|
||||
* @see collectionNode:nodeForSupplementaryElementOfKind:atIndexPath:
|
||||
*/
|
||||
- (ASCellNode *)nodeForSupplementaryElementOfKind:(NSString *)elementKind atIndex:(NSInteger)index;
|
||||
- (ASCellNodeBlock)nodeBlockForSupplementaryElementOfKind:(NSString *)elementKind atIndex:(NSInteger)index;
|
||||
|
||||
@optional
|
||||
|
||||
|
||||
@@ -199,9 +199,9 @@ typedef struct {
|
||||
}
|
||||
}
|
||||
|
||||
- (ASCellNode *)collectionNode:(ASCollectionNode *)collectionNode nodeForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
|
||||
- (ASCellNodeBlock)collectionNode:(ASCollectionNode *)collectionNode nodeBlockForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
return [[self supplementaryElementSourceForSection:indexPath.section] nodeForSupplementaryElementOfKind:kind atIndex:indexPath.item];
|
||||
return [[self supplementaryElementSourceForSection:indexPath.section] nodeBlockForSupplementaryElementOfKind:kind atIndex:indexPath.item];
|
||||
}
|
||||
|
||||
- (NSArray<NSString *> *)collectionNode:(ASCollectionNode *)collectionNode supplementaryElementKindsInSection:(NSInteger)section
|
||||
|
||||
@@ -96,10 +96,12 @@ ASIGSectionControllerCellForIndexImplementation;
|
||||
|
||||
#pragma mark - ASSupplementaryNodeSource
|
||||
|
||||
- (ASCellNode *)nodeForSupplementaryElementOfKind:(NSString *)elementKind atIndex:(NSInteger)index
|
||||
- (ASCellNodeBlock)nodeBlockForSupplementaryElementOfKind:(NSString *)elementKind atIndex:(NSInteger)index
|
||||
{
|
||||
ASDisplayNodeAssert([elementKind isEqualToString:UICollectionElementKindSectionHeader], nil);
|
||||
return [[FeedHeaderNode alloc] init];
|
||||
return ^{
|
||||
return [[FeedHeaderNode alloc] init];
|
||||
};
|
||||
}
|
||||
|
||||
- (ASSizeRange)sizeRangeForSupplementaryElementOfKind:(NSString *)elementKind atIndex:(NSInteger)index
|
||||
|
||||
Reference in New Issue
Block a user