From 9235ce5ac285ff068c49c7d9bb05c953e29a8201 Mon Sep 17 00:00:00 2001 From: Levi McCallum Date: Tue, 6 Oct 2015 12:10:28 -0700 Subject: [PATCH] Support reloading supplementary nodes when sections reload --- .../Details/ASCollectionDataController.mm | 20 +++++++++++++++++-- AsyncDisplayKit/Details/ASDataController.mm | 2 ++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/AsyncDisplayKit/Details/ASCollectionDataController.mm b/AsyncDisplayKit/Details/ASCollectionDataController.mm index 7eee33fffe..733594fe4f 100644 --- a/AsyncDisplayKit/Details/ASCollectionDataController.mm +++ b/AsyncDisplayKit/Details/ASCollectionDataController.mm @@ -99,6 +99,8 @@ [self insertSections:sectionArray ofKind:kind atIndexSet:sections completion:nil]; [self batchLayoutNodes:nodes ofKind:kind atIndexPaths:_pendingIndexPaths[kind] completion:nil]; + _pendingNodes[kind] = nil; + _pendingIndexPaths[kind] = nil; }]; } @@ -115,12 +117,26 @@ - (void)prepareForReloadSections:(NSIndexSet *)sections { - // TODO: Implement + NSArray *elementKinds = [self.collectionDataSource supplementaryNodeKindsInDataController:self]; + [elementKinds enumerateObjectsUsingBlock:^(NSString *kind, NSUInteger idx, BOOL *stop) { + NSMutableArray *nodes = [NSMutableArray array]; + NSMutableArray *indexPaths = [NSMutableArray array]; + [self _populateSupplementaryNodesOfKind:kind withSections:sections mutableNodes:nodes mutableIndexPaths:indexPaths]; + _pendingNodes[kind] = nodes; + _pendingIndexPaths[kind] = indexPaths; + }]; } - (void)willReloadSections:(NSIndexSet *)sections { - // TODO: Implement + [_pendingNodes enumerateKeysAndObjectsUsingBlock:^(NSString *kind, NSMutableArray *nodes, BOOL *stop) { + NSArray *indexPaths = ASIndexPathsForMultidimensionalArrayAtIndexSet([self editingNodesOfKind:kind], sections); + [self deleteNodesOfKind:kind atIndexPaths:indexPaths completion:nil]; + // reinsert the elements + [self batchLayoutNodes:nodes ofKind:kind atIndexPaths:_pendingIndexPaths[kind] completion:nil]; + _pendingNodes[kind] = nil; + _pendingIndexPaths[kind] = nil; + }]; } - (void)willMoveSection:(NSInteger)section toSection:(NSInteger)newSection diff --git a/AsyncDisplayKit/Details/ASDataController.mm b/AsyncDisplayKit/Details/ASDataController.mm index 89eab8b8e4..e4b0f81fde 100644 --- a/AsyncDisplayKit/Details/ASDataController.mm +++ b/AsyncDisplayKit/Details/ASDataController.mm @@ -623,6 +623,8 @@ static void *kASSizingQueueContext = &kASSizingQueueContext; [self _layoutNodesWithMainThreadAffinity:updatedNodes atIndexPaths:updatedIndexPaths]; [_editingTransactionQueue addOperationWithBlock:^{ + [self willReloadSections:sections]; + NSArray *indexPaths = ASIndexPathsForMultidimensionalArrayAtIndexSet(_editingNodes[ASDataControllerRowNodeKind], sections); LOG(@"Edit Transaction - reloadSections: updatedIndexPaths: %@, indexPaths: %@, _editingNodes: %@", updatedIndexPaths, indexPaths, ASIndexPathsForMultidimensionalArray(_editingNodes[ASDataControllerRowNodeKind]));