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

Commit 3efd01a

Browse files
erichoracekappleguy
authored andcommitted
[ASCollectionDataController] Repopulate deleted supplementary nodes if necessary (#1773)
* Repopulate deleted supplementary nodes if necessary Fixes 1771 * Fix warning
1 parent f39c2ce commit 3efd01a

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

AsyncDisplayKit/Details/ASCollectionDataController.mm

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,32 @@ - (void)willInsertRowsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths
154154
}
155155
}
156156

157+
- (void)prepareForDeleteRowsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths
158+
{
159+
for (NSString *kind in [self supplementaryKinds]) {
160+
NSMutableArray<ASIndexedNodeContext *> *contexts = [NSMutableArray array];
161+
[self _populateSupplementaryNodesOfKind:kind atIndexPaths:indexPaths mutableContexts:contexts];
162+
_pendingContexts[kind] = contexts;
163+
}
164+
}
165+
157166
- (void)willDeleteRowsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths
158167
{
159168
for (NSString *kind in [self supplementaryKinds]) {
160169
NSArray<NSIndexPath *> *deletedIndexPaths = ASIndexPathsInMultidimensionalArrayIntersectingIndexPaths([self editingNodesOfKind:kind], indexPaths);
170+
161171
[self deleteNodesOfKind:kind atIndexPaths:deletedIndexPaths completion:nil];
172+
173+
// If any of the contexts remain after the deletion, re-insert them, e.g.
174+
// UICollectionElementKindSectionHeader remains even if item 0 is deleted.
175+
NSArray<ASIndexedNodeContext *> *contexts = [_pendingContexts[kind] filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^(ASIndexedNodeContext *context, NSDictionary *_) {
176+
return [deletedIndexPaths containsObject:context.indexPath];
177+
}]];
178+
179+
[self batchLayoutNodesFromContexts:contexts ofKind:kind completion:^(NSArray<ASCellNode *> *nodes, NSArray<NSIndexPath *> *indexPaths) {
180+
[self insertNodes:nodes ofKind:kind atIndexPaths:indexPaths completion:nil];
181+
}];
182+
[_pendingContexts removeObjectForKey:kind];
162183
}
163184
}
164185

0 commit comments

Comments
 (0)