Use ASCellNodes for supplementary nodes

This commit is contained in:
Levi McCallum 2015-10-11 10:47:35 -07:00
parent 0870d50e36
commit fddb0061b0
10 changed files with 19 additions and 19 deletions

View File

@ -281,7 +281,7 @@
@optional
- (ASDisplayNode *)collectionView:(ASCollectionView *)collectionView nodeForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath;
- (ASCellNode *)collectionView:(ASCollectionView *)collectionView nodeForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath;
/**
* Provides the constrained size range for measuring the node at the index path.

View File

@ -476,7 +476,7 @@ static BOOL _isInterceptedSelector(SEL sel)
ASCellNode *node = [_dataController nodeAtIndexPath:indexPath];
[_rangeController configureContentView:cell.contentView forNode:node];
[_rangeController configureContentView:cell.contentView forCellNode:node];
cell.node = node;
@ -492,8 +492,8 @@ static BOOL _isInterceptedSelector(SEL sel)
{
NSString *identifier = [self __reuseIdentifierForKind:kind];
UICollectionReusableView *view = [self dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:identifier forIndexPath:indexPath];
ASDisplayNode *node = [_dataController supplementaryNodeOfKind:kind atIndexPath:indexPath];
[_rangeController configureContentView:view forNode:node];
ASCellNode *node = [_dataController supplementaryNodeOfKind:kind atIndexPath:indexPath];
[_rangeController configureContentView:view forCellNode:node];
return view;
}
@ -731,9 +731,9 @@ static BOOL _isInterceptedSelector(SEL sel)
#pragma mark - ASCollectionViewDataControllerSource Supplementary view support
- (ASDisplayNode *)dataController:(ASCollectionDataController *)dataController supplementaryNodeOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
- (ASCellNode *)dataController:(ASCollectionDataController *)dataController supplementaryNodeOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
ASDisplayNode *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 a supplementary node");
ASDisplayNodeAssert(!node.nodeLoaded, @"The supplementary node must not be loaded");
return node;

View File

@ -530,7 +530,7 @@ void ASPerformBlockWithoutAnimation(BOOL withoutAnimation, void (^block)()) {
}
ASCellNode *node = [_dataController nodeAtIndexPath:indexPath];
[_rangeController configureContentView:cell.contentView forNode:node];
[_rangeController configureContentView:cell.contentView forCellNode:node];
cell.node = node;
cell.backgroundColor = node.backgroundColor;

View File

@ -17,7 +17,7 @@
@protocol ASCollectionDataControllerSource <ASDataControllerSource>
- (ASDisplayNode *)dataController:(ASCollectionDataController *)dataController supplementaryNodeOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath;
- (ASCellNode *)dataController:(ASCollectionDataController *)dataController supplementaryNodeOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath;
/**
The constrained size range for layout.
@ -34,6 +34,6 @@
@interface ASCollectionDataController : ASDataController
- (ASDisplayNode *)supplementaryNodeOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath;
- (ASCellNode *)supplementaryNodeOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath;
@end

View File

@ -197,7 +197,7 @@
#pragma mark - External supplementary store querying
- (ASDisplayNode *)supplementaryNodeOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
- (ASCellNode *)supplementaryNodeOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
ASDisplayNodeAssertMainThread();
return [self completedNodesOfKind:kind][indexPath.section][indexPath.item];

View File

@ -169,7 +169,7 @@ static void *kASSizingQueueContext = &kASSizingQueueContext;
dispatch_group_async(layoutGroup, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
for (NSUInteger k = j; k < j + batchCount; k++) {
ASDisplayNode *node = nodes[k];
ASCellNode *node = nodes[k];
// Only measure nodes whose views aren't loaded, since we're in the background.
// We should already have measured loaded nodes before we left the main thread, using _layoutNodesWithMainThreadAffinity:
if (!node.isNodeLoaded) {
@ -928,7 +928,7 @@ static void *kASSizingQueueContext = &kASSizingQueueContext;
ASDisplayNodeAssertMainThread();
[_completedNodes enumerateKeysAndObjectsUsingBlock:^(NSString *kind, NSMutableArray *nodes, BOOL *stop) {
[nodes enumerateObjectsUsingBlock:^(NSMutableArray *section, NSUInteger sectionIndex, BOOL *stop) {
[section enumerateObjectsUsingBlock:^(ASDisplayNode *node, NSUInteger rowIndex, BOOL *stop) {
[section enumerateObjectsUsingBlock:^(ASCellNode *node, NSUInteger rowIndex, BOOL *stop) {
if (node.isNodeLoaded) {
if (node.layerBacked) {
[node.layer removeFromSuperlayer];

View File

@ -41,9 +41,9 @@
*
* @param contentView UIView to add a (sized) node's view to.
*
* @param node The node to be added. Often an ASCellNode.
* @param cellNode The cell node to be added.
*/
- (void)configureContentView:(UIView *)contentView forNode:(ASDisplayNode *)node;
- (void)configureContentView:(UIView *)contentView forCellNode:(ASCellNode *)node;
/**
* Delegate and ultimate data source. Must not be nil.

View File

@ -48,7 +48,7 @@
#pragma mark - View manipulation
- (void)moveNode:(ASDisplayNode *)node toView:(UIView *)view
- (void)moveCellNode:(ASCellNode *)node toView:(UIView *)view
{
ASDisplayNodeAssertMainThread();
ASDisplayNodeAssert(node, @"Cannot move a nil node to a view");
@ -158,7 +158,7 @@
return rangeType == ASLayoutRangeTypeRender;
}
- (void)configureContentView:(UIView *)contentView forNode:(ASDisplayNode *)node
- (void)configureContentView:(UIView *)contentView forCellNode:(ASCellNode *)node
{
if (node.view.superview == contentView) {
// this content view is already correctly configured
@ -170,7 +170,7 @@
[view removeFromSuperview];
}
[self moveNode:node toView:contentView];
[self moveCellNode:node toView:contentView];
}

View File

@ -64,7 +64,7 @@
// This happens if the UITableViewCell is reused after scrolling offscreen. Because the node has already been given the opportunity to display, we do not
// proactively re-host it within the workingWindow (improving efficiency). Some time later, it may fall outside the working range, in which case calling
// -recursivelyClearContents is critical. If the user scrolls back and it is re-hosted in a UITableViewCell, the content will still exist as it is not cleared
// by simply being removed from the cell. The code that usually triggers this condition is the -removeFromSuperview in -[ASRangeController configureContentView:forNode:].
// by simply being removed from the cell. The code that usually triggers this condition is the -removeFromSuperview in -[ASRangeController configureContentView:forCellNode:].
// Condition #4 is suboptimal in some cases, as it is conceivable that memory warnings could trigger clearing content that is inside the working range. However, enforcing the
// preservation of this content could result in the app being killed, which is not likely preferable over briefly seeing placeholders in the event the user scrolls backwards.
// Nonetheless, future changes to the implementation will likely eliminate this behavior to simplify debugging and extensibility of working range functionality.

View File

@ -78,7 +78,7 @@
return node;
}
- (ASDisplayNode *)collectionView:(ASCollectionView *)collectionView nodeForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
- (ASCellNode *)collectionView:(ASCollectionView *)collectionView nodeForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
NSString *text = [kind isEqualToString:UICollectionElementKindSectionHeader] ? @"Header" : @"Footer";
SupplementaryNode *node = [[SupplementaryNode alloc] initWithText:text];