This repository was archived by the owner on Feb 2, 2023. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments