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

Commit bc08011

Browse files
Adlai Hollergarrettmoon
authored andcommitted
Fix Deleting Sections Issue (#2962)
* Add data source to main project * Remove the idea of deletingSectionsOfKind – always delete all kinds * Move comment into assertion
1 parent b366347 commit bc08011

File tree

4 files changed

+27
-40
lines changed

4 files changed

+27
-40
lines changed

AsyncDisplayKit.xcodeproj/project.pbxproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,10 @@
473473
CC8B05D81D73979700F54286 /* ASTextNodePerformanceTests.m in Sources */ = {isa = PBXBuildFile; fileRef = CC8B05D71D73979700F54286 /* ASTextNodePerformanceTests.m */; };
474474
CCA221D31D6FA7EF00AF6A0F /* ASViewControllerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = CCA221D21D6FA7EF00AF6A0F /* ASViewControllerTests.m */; };
475475
CCB2F34D1D63CCC6004E6DE9 /* ASDisplayNodeSnapshotTests.m in Sources */ = {isa = PBXBuildFile; fileRef = CCB2F34C1D63CCC6004E6DE9 /* ASDisplayNodeSnapshotTests.m */; };
476+
CCBD05E01E4147B000D18509 /* ASIGListAdapterBasedDataSource.m in Sources */ = {isa = PBXBuildFile; fileRef = CCBD05DE1E4147B000D18509 /* ASIGListAdapterBasedDataSource.m */; };
477+
CCBD05E11E4147B000D18509 /* ASIGListAdapterBasedDataSource.m in Sources */ = {isa = PBXBuildFile; fileRef = CCBD05DE1E4147B000D18509 /* ASIGListAdapterBasedDataSource.m */; };
478+
CCBD05E21E4147B000D18509 /* ASIGListAdapterBasedDataSource.h in Headers */ = {isa = PBXBuildFile; fileRef = CCBD05DF1E4147B000D18509 /* ASIGListAdapterBasedDataSource.h */; };
479+
CCBD05E31E4147CC00D18509 /* ASIGListAdapterBasedDataSource.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = CCBD05DF1E4147B000D18509 /* ASIGListAdapterBasedDataSource.h */; };
476480
CCE04B1F1E313EA7006AEBBB /* ASSectionController.h in Headers */ = {isa = PBXBuildFile; fileRef = CCE04B1E1E313EA7006AEBBB /* ASSectionController.h */; settings = {ATTRIBUTES = (Public, ); }; };
477481
CCE04B221E313EB9006AEBBB /* IGListAdapter+AsyncDisplayKit.h in Headers */ = {isa = PBXBuildFile; fileRef = CCE04B201E313EB9006AEBBB /* IGListAdapter+AsyncDisplayKit.h */; };
478482
CCE04B231E313EB9006AEBBB /* IGListAdapter+AsyncDisplayKit.m in Sources */ = {isa = PBXBuildFile; fileRef = CCE04B211E313EB9006AEBBB /* IGListAdapter+AsyncDisplayKit.m */; };
@@ -689,6 +693,7 @@
689693
dstPath = "include/$(PRODUCT_NAME)";
690694
dstSubfolderSpec = 16;
691695
files = (
696+
CCBD05E31E4147CC00D18509 /* ASIGListAdapterBasedDataSource.h in CopyFiles */,
692697
CC8525181E3FC316008EABE6 /* _ASCollectionViewCell.h in CopyFiles */,
693698
690ED59D1E36D140000627C0 /* ASImageNode+tvOS.h in CopyFiles */,
694699
690ED59C1E36D13A000627C0 /* ASControlNode+tvOS.h in CopyFiles */,
@@ -1190,6 +1195,8 @@
11901195
CC8B05D71D73979700F54286 /* ASTextNodePerformanceTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ASTextNodePerformanceTests.m; sourceTree = "<group>"; };
11911196
CCA221D21D6FA7EF00AF6A0F /* ASViewControllerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ASViewControllerTests.m; sourceTree = "<group>"; };
11921197
CCB2F34C1D63CCC6004E6DE9 /* ASDisplayNodeSnapshotTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ASDisplayNodeSnapshotTests.m; sourceTree = "<group>"; };
1198+
CCBD05DE1E4147B000D18509 /* ASIGListAdapterBasedDataSource.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ASIGListAdapterBasedDataSource.m; sourceTree = "<group>"; };
1199+
CCBD05DF1E4147B000D18509 /* ASIGListAdapterBasedDataSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASIGListAdapterBasedDataSource.h; sourceTree = "<group>"; };
11931200
CCE04B1E1E313EA7006AEBBB /* ASSectionController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASSectionController.h; sourceTree = "<group>"; };
11941201
CCE04B201E313EB9006AEBBB /* IGListAdapter+AsyncDisplayKit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "IGListAdapter+AsyncDisplayKit.h"; sourceTree = "<group>"; };
11951202
CCE04B211E313EB9006AEBBB /* IGListAdapter+AsyncDisplayKit.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "IGListAdapter+AsyncDisplayKit.m"; sourceTree = "<group>"; };
@@ -1830,6 +1837,8 @@
18301837
isa = PBXGroup;
18311838
children = (
18321839
CC6363E11E32C00800D8A8DE /* ASCollectionInteropProtocols.h */,
1840+
CCBD05DF1E4147B000D18509 /* ASIGListAdapterBasedDataSource.h */,
1841+
CCBD05DE1E4147B000D18509 /* ASIGListAdapterBasedDataSource.m */,
18331842
);
18341843
name = "Collection Data Adapter";
18351844
sourceTree = "<group>";
@@ -2015,6 +2024,7 @@
20152024
83A7D95C1D44548100BF333E /* ASWeakMap.h in Headers */,
20162025
69708BA61D76386D005C3CF9 /* ASEqualityHashHelpers.h in Headers */,
20172026
B350622D1B010EFD0018CF92 /* ASScrollDirection.h in Headers */,
2027+
CCBD05E21E4147B000D18509 /* ASIGListAdapterBasedDataSource.h in Headers */,
20182028
254C6B751BF94DF4003EC431 /* ASTextKitComponents.h in Headers */,
20192029
B35062081B010EFD0018CF92 /* ASScrollNode.h in Headers */,
20202030
25E327571C16819500A2170C /* ASPagerNode.h in Headers */,
@@ -2273,6 +2283,7 @@
22732283
DBDB83961C6E879900D0098C /* ASPagerFlowLayout.m in Sources */,
22742284
058D0A26195D050800B7D73C /* _ASCoreAnimationExtras.mm in Sources */,
22752285
6947B0C41E36B5040007C478 /* ASStackPositionedLayout.mm in Sources */,
2286+
CCBD05E01E4147B000D18509 /* ASIGListAdapterBasedDataSource.m in Sources */,
22762287
257754B41BEE44CD00737CA5 /* ASTextKitTailTruncater.mm in Sources */,
22772288
68B8A4E31CBDB958007E4543 /* ASWeakProxy.m in Sources */,
22782289
69E1006F1CA89CB600D88C1B /* ASEnvironmentInternal.mm in Sources */,
@@ -2466,6 +2477,7 @@
24662477
9B92C8851BC2EB6E00EE46B2 /* ASCollectionDataController.mm in Sources */,
24672478
B350623D1B010EFD0018CF92 /* _ASAsyncTransaction.mm in Sources */,
24682479
6947B0C51E36B5040007C478 /* ASStackPositionedLayout.mm in Sources */,
2480+
CCBD05E11E4147B000D18509 /* ASIGListAdapterBasedDataSource.m in Sources */,
24692481
B35062401B010EFD0018CF92 /* _ASAsyncTransactionContainer.m in Sources */,
24702482
AC026B721BD57DBF00BBC17E /* _ASHierarchyChangeSet.mm in Sources */,
24712483
B35062421B010EFD0018CF92 /* _ASAsyncTransactionGroup.m in Sources */,

AsyncDisplayKit/Details/ASCollectionDataController.mm

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,10 @@ - (void)willReloadDataWithSectionCount:(NSInteger)newSectionCount
8181

8282
[self applyPendingSections:sectionIndexes];
8383

84+
// Assert that ASDataController has already deleted all the old sections for us.
85+
ASDisplayNodeAssert([self editingNodesOfKind:ASDataControllerRowNodeKind].count == 0, @"Expected that all old sections were deleted before %@. Sections: %@", NSStringFromSelector(_cmd), [self editingNodesOfKind:ASDataControllerRowNodeKind]);
86+
8487
[_pendingNodeContexts enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull kind, NSMutableArray<ASIndexedNodeContext *> * _Nonnull contexts, __unused BOOL * _Nonnull stop) {
85-
// Remove everything that existed before the reload, now that we're ready to insert replacements
86-
NSArray *indexPaths = [self indexPathsForEditingNodesOfKind:kind];
87-
[self deleteNodesOfKind:kind atIndexPaths:indexPaths completion:nil];
88-
89-
NSArray *editingNodes = [self editingNodesOfKind:kind];
90-
NSIndexSet *indexSet = [[NSIndexSet alloc] initWithIndexesInRange:NSMakeRange(0, editingNodes.count)];
91-
[self deleteSectionsOfKind:kind atIndexSet:indexSet completion:nil];
92-
9388
// Insert each section
9489
NSMutableArray *sections = [NSMutableArray arrayWithCapacity:newSectionCount];
9590
for (int i = 0; i < newSectionCount; i++) {
@@ -135,22 +130,9 @@ - (void)willInsertSections:(NSIndexSet *)sections
135130
[_pendingNodeContexts removeAllObjects];
136131
}
137132

138-
- (void)prepareForDeleteSections:(NSIndexSet *)sections
139-
{
140-
_supplementaryKindsForPendingOperation = [self supplementaryKindsInSections:sections];
141-
}
142-
143133
- (void)willDeleteSections:(NSIndexSet *)sections
144134
{
145135
[_sections removeObjectsAtIndexes:sections];
146-
147-
for (NSString *kind in _supplementaryKindsForPendingOperation) {
148-
NSArray *indexPaths = ASIndexPathsForMultidimensionalArrayAtIndexSet([self editingNodesOfKind:kind], sections);
149-
150-
[self deleteNodesOfKind:kind atIndexPaths:indexPaths completion:nil];
151-
[self deleteSectionsOfKind:kind atIndexSet:sections completion:nil];
152-
}
153-
_supplementaryKindsForPendingOperation = nil;
154136
}
155137

156138
- (void)prepareForInsertRowsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths

AsyncDisplayKit/Details/ASDataController.mm

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -308,18 +308,22 @@ - (void)insertSections:(NSMutableArray *)sections ofKind:(NSString *)kind atInde
308308
}];
309309
}
310310

311-
- (void)deleteSectionsOfKind:(NSString *)kind atIndexSet:(NSIndexSet *)indexSet completion:(void (^)(NSIndexSet *indexSet))completionBlock
311+
- (void)deleteSections:(NSIndexSet *)indexSet completion:(void (^)())completionBlock
312312
{
313313
ASSERT_ON_EDITING_QUEUE;
314314
if (!indexSet.count || _dataSource == nil) {
315315
return;
316316
}
317-
318-
[_editingNodes[kind] removeObjectsAtIndexes:indexSet];
317+
318+
[_editingNodes enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull kind, NSMutableArray *sections, BOOL * _Nonnull stop) {
319+
[sections removeObjectsAtIndexes:indexSet];
320+
}];
319321
[_mainSerialQueue performBlockOnMainThread:^{
320-
[_completedNodes[kind] removeObjectsAtIndexes:indexSet];
322+
[_completedNodes enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull kind, NSMutableArray *sections, BOOL * _Nonnull stop) {
323+
[sections removeObjectsAtIndexes:indexSet];
324+
}];
321325
if (completionBlock) {
322-
completionBlock(indexSet);
326+
completionBlock();
323327
}
324328
}];
325329
}
@@ -390,7 +394,7 @@ - (void)_deleteSectionsAtIndexSet:(NSIndexSet *)indexSet withAnimationOptions:(A
390394
{
391395
ASSERT_ON_EDITING_QUEUE;
392396

393-
[self deleteSectionsOfKind:ASDataControllerRowNodeKind atIndexSet:indexSet completion:^(NSIndexSet *indexSet) {
397+
[self deleteSections:indexSet completion:^() {
394398
ASDisplayNodeAssertMainThread();
395399

396400
if (_delegateDidDeleteSections)
@@ -899,12 +903,6 @@ - (void)_relayoutNodesOfKind:(NSString *)kind
899903

900904
#pragma mark - Data Querying (Subclass API)
901905

902-
- (NSArray<NSIndexPath *> *)indexPathsForEditingNodesOfKind:(NSString *)kind
903-
{
904-
NSArray *nodes = _editingNodes[kind];
905-
return nodes != nil ? ASIndexPathsForTwoDimensionalArray(nodes) : nil;
906-
}
907-
908906
- (NSMutableArray *)editingNodesOfKind:(NSString *)kind
909907
{
910908
return _editingNodes[kind] ? : [NSMutableArray array];

AsyncDisplayKit/Private/ASDataController+Subclasses.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@ typedef void (^ASDataControllerCompletionBlock)(NSArray<ASCellNode *> *nodes, NS
1919

2020
#pragma mark - Internal editing & completed store querying
2121

22-
/**
23-
* Provides a collection of index paths for nodes of the given kind that are currently in the editing store
24-
*/
25-
- (NSArray<NSIndexPath *> *)indexPathsForEditingNodesOfKind:(NSString *)kind;
26-
2722
/**
2823
* Read-only access to the underlying editing nodes of the given kind
2924
*/
@@ -67,9 +62,9 @@ typedef void (^ASDataControllerCompletionBlock)(NSArray<ASCellNode *> *nodes, NS
6762
- (void)insertSections:(NSMutableArray *)sections ofKind:(NSString *)kind atIndexSet:(NSIndexSet *)indexSet completion:(void (^)(NSArray *sections, NSIndexSet *indexSet))completionBlock;
6863

6964
/**
70-
* Deletes the given sections of the specified kind in the backing store, calling completion on the main thread when finished.
65+
* Deletes the given sections in the backing store, calling completion on the main thread when finished.
7166
*/
72-
- (void)deleteSectionsOfKind:(NSString *)kind atIndexSet:(NSIndexSet *)indexSet completion:(void (^)(NSIndexSet *indexSet))completionBlock;
67+
- (void)deleteSections:(NSIndexSet *)indexSet completion:(void (^)())completionBlock;
7368

7469
#pragma mark - Data Manipulation Hooks
7570

0 commit comments

Comments
 (0)