Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.

Commit e56315d

Browse files
committed
Merge pull request #1004 from facebook/SupplementaryNodeSectionReloading
Supplementary nodes must be added to the completed nodes after their measurement completes.
2 parents f87b915 + 690f90a commit e56315d

2 files changed

Lines changed: 21 additions & 6 deletions

File tree

AsyncDisplayKit/Details/ASCollectionDataController.mm

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
#import "ASAssert.h"
1212
#import "ASMultidimensionalArrayUtils.h"
13-
#import "ASDisplayNode.h"
13+
#import "ASCellNode.h"
1414
#import "ASDisplayNodeInternal.h"
1515
#import "ASDataController+Subclasses.h"
1616

@@ -142,7 +142,9 @@ - (void)willReloadSections:(NSIndexSet *)sections
142142
NSArray *indexPaths = ASIndexPathsForMultidimensionalArrayAtIndexSet([self editingNodesOfKind:kind], sections);
143143
[self deleteNodesOfKind:kind atIndexPaths:indexPaths completion:nil];
144144
// reinsert the elements
145-
[self batchLayoutNodes:nodes ofKind:kind atIndexPaths:_pendingIndexPaths[kind] completion:nil];
145+
[self batchLayoutNodes:nodes ofKind:kind atIndexPaths:_pendingIndexPaths[kind] completion:^(NSArray *nodes, NSArray *indexPaths) {
146+
[self insertNodes:nodes ofKind:kind atIndexPaths:indexPaths completion:nil];
147+
}];
146148
[_pendingNodes removeObjectForKey:kind];
147149
[_pendingIndexPaths removeObjectForKey:kind];
148150
}];
@@ -187,7 +189,8 @@ - (void)_populateSupplementaryNodesOfKind:(NSString *)kind withSections:(NSIndex
187189
for (NSUInteger i = 0; i < rowNum; i++) {
188190
NSIndexPath *indexPath = [sectionIndex indexPathByAddingIndex:i];
189191
[indexPaths addObject:indexPath];
190-
[nodes addObject:[self.collectionDataSource dataController:self supplementaryNodeOfKind:kind atIndexPath:indexPath]];
192+
ASCellNode *supplementaryNode = [self.collectionDataSource dataController:self supplementaryNodeOfKind:kind atIndexPath:indexPath];
193+
[nodes addObject:supplementaryNode];
191194
}
192195
}];
193196
}
@@ -208,7 +211,17 @@ - (ASSizeRange)constrainedSizeForNodeOfKind:(NSString *)kind atIndexPath:(NSInde
208211
- (ASCellNode *)supplementaryNodeOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
209212
{
210213
ASDisplayNodeAssertMainThread();
211-
return [self completedNodesOfKind:kind][indexPath.section][indexPath.item];
214+
NSArray *nodesOfKind = [self completedNodesOfKind:kind];
215+
NSInteger section = indexPath.section;
216+
if (section < nodesOfKind.count) {
217+
NSArray *nodesOfKindInSection = nodesOfKind[section];
218+
NSInteger itemIndex = indexPath.item;
219+
if (itemIndex < nodesOfKindInSection.count) {
220+
return nodesOfKindInSection[itemIndex];
221+
}
222+
}
223+
ASDisplayNodeAssert(NO, @"Supplementary node should exist. Kind = %@, indexPath = %@, collectionDataSource = %@", kind, indexPath, self.collectionDataSource);
224+
return [[ASCellNode alloc] init];
212225
}
213226

214227
#pragma mark - Private Helpers

examples/CustomCollectionView/Sample/ViewController.m

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,13 @@ - (ASCellNode *)collectionView:(ASCollectionView *)collectionView nodeForSupplem
101101
return [[SupplementaryNode alloc] initWithText:text];
102102
}
103103

104-
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
104+
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
105+
{
105106
return _sections.count;
106107
}
107108

108-
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
109+
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
110+
{
109111
return [_sections[section] count];
110112
}
111113

0 commit comments

Comments
 (0)