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

Commit 74c6cca

Browse files
nguyenhuyAdlai Holler
authored andcommitted
[ASDataController] Refactor ASDataController (#3017)
* Refactor ASDataController Check optional methods in ASDataControllerSource * Reimplement reloadData * Refactor new code - No more new/inserted contexts flag - Encapsulate code shared between reloadData and updateWithChangeSet - Remove dataControllerWillDeleteAllData delegate method - Hierarchy changes no longer needs to conform to NSCopying - Reword TODOs * Forgot to call completion block of reloadData :P * Completion block of -[ASDataController reloadDataWithCompletion:] is nullable * Data queried from ASCollectionNode and ASTableNode should be in UIKit index space - This helps to avoid immature node allocation, especially when node virtualization is a thing - However, this means that -reloadDataInitiallyIfNeeded in ASCollectionNode and ASTableNode must wait until all updates are finished. * ASDataController shouldn't assume that allocated nodes were also laid out * Revert "Data queried from ASCollectionNode and ASTableNode should be in UIKit index space" This reverts commit 7bc977b. * -nodeAtIndexPath: of ASDataController now forces node allocation, with the assumption that clients absolutely need it. - Revisit this when node virtualization is implemented. * ASDataController only grab changeSet.completionHandler when needed because it'll be niled out * Fix ASTableViewTests related to reloadData * Fix testThatDeletedItemsAreMarkedInvisible in ASCollectionViewTests * Minor changes in ASCollectionView and ASTableView * ASCollectionView and ASTableView shouldn't call [super reloadData] before their data controller does anything * Address comments * Fuse reloadData into -updateWithChangeSet: of ASDataController * reloadData shouldn't be called as if it's inside a batch - It can't be used in conjuntion with other updates. - Calling it inside a batch update during the initial load can cause data inconsistency thrown by UICollectionView/UITableView * Refactor ASDataControllerDelegate and ASRangeControllerDelegate - Replace delegate methods in these protocols with -willUpdateWithChangeSet and -didUpdateWithChangeSet. - ASRangeController, ASCollectionView and ASTableView are simplified because of this. * Fix mismatch between sorting orders in ASDataController * Forgot to call completion handler of reload change sets * Make sure ASCollectionView is compatible with the behavior of UICollectionView's reloadData - Since UICollectionView's reloadData doesn't requery data source but defers until the next layout pass, we need to wait until then to update range controller and do batch fetching. - `-[ASCollectionView waitUntilAllUpdatesAreCommited]` needs to force a layout pass to make sure everything is ready after it returns. * testSectionIndexHandling of ASTableViewTests should only check visible nodes. Other nodes will be re-measured later. * ASTableView is not ready until the first layout pass finished * Address comments * Bug fixes
1 parent ea09ad7 commit 74c6cca

25 files changed

+764
-1578
lines changed

AsyncDisplayKit.xcodeproj/project.pbxproj

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,6 @@
181181
92DD2FE61BF4D05E0074C9DD /* MapKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 92DD2FE51BF4D05E0074C9DD /* MapKit.framework */; settings = {ATTRIBUTES = (Weak, ); }; };
182182
92DD2FE71BF4D0850074C9DD /* ASMapNode.mm in Sources */ = {isa = PBXBuildFile; fileRef = 92DD2FE21BF4B97E0074C9DD /* ASMapNode.mm */; };
183183
92DD2FE81BF4D0A80074C9DD /* ASMapNode.h in Headers */ = {isa = PBXBuildFile; fileRef = 92DD2FE11BF4B97E0074C9DD /* ASMapNode.h */; settings = {ATTRIBUTES = (Public, ); }; };
184-
9B92C8851BC2EB6E00EE46B2 /* ASCollectionDataController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 251B8EF31BBB3D690087C538 /* ASCollectionDataController.mm */; };
185184
9C49C3701B853961000B0DD5 /* ASStackLayoutElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 9C49C36E1B853957000B0DD5 /* ASStackLayoutElement.h */; settings = {ATTRIBUTES = (Public, ); }; };
186185
9C55866B1BD54A1900B50E3A /* ASAsciiArtBoxCreator.m in Sources */ = {isa = PBXBuildFile; fileRef = 9C5586681BD549CB00B50E3A /* ASAsciiArtBoxCreator.m */; };
187186
9C55866C1BD54A3000B50E3A /* ASAsciiArtBoxCreator.h in Headers */ = {isa = PBXBuildFile; fileRef = 9C5586671BD549CB00B50E3A /* ASAsciiArtBoxCreator.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -190,8 +189,6 @@
190189
9C70F2061CDA4F0C007D6C76 /* ASTraitCollection.h in Headers */ = {isa = PBXBuildFile; fileRef = 9C70F2011CDA4EFA007D6C76 /* ASTraitCollection.h */; settings = {ATTRIBUTES = (Public, ); }; };
191190
9C70F2091CDABA36007D6C76 /* ASViewController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9CFFC6BF1CCAC73C006A6476 /* ASViewController.mm */; };
192191
9C70F20A1CDBE949007D6C76 /* ASTableNode.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9CFFC6C11CCAC768006A6476 /* ASTableNode.mm */; };
193-
9C70F20B1CDBE9A4007D6C76 /* ASDataController+Subclasses.h in Headers */ = {isa = PBXBuildFile; fileRef = 251B8EF61BBB3D690087C538 /* ASDataController+Subclasses.h */; settings = {ATTRIBUTES = (Private, ); }; };
194-
9C70F20C1CDBE9B6007D6C76 /* ASCollectionDataController.h in Headers */ = {isa = PBXBuildFile; fileRef = 251B8EF21BBB3D690087C538 /* ASCollectionDataController.h */; settings = {ATTRIBUTES = (Private, ); }; };
195192
9C70F20D1CDBE9CB007D6C76 /* ASDefaultPlayButton.h in Headers */ = {isa = PBXBuildFile; fileRef = AEB7B0181C5962EA00662EF4 /* ASDefaultPlayButton.h */; settings = {ATTRIBUTES = (Private, ); }; };
196193
9C70F20E1CDBE9E5007D6C76 /* NSArray+Diffing.h in Headers */ = {isa = PBXBuildFile; fileRef = DBC452D91C5BF64600B16017 /* NSArray+Diffing.h */; settings = {ATTRIBUTES = (Public, ); }; };
197194
9C70F20F1CDBE9FF007D6C76 /* ASLayoutManager.h in Headers */ = {isa = PBXBuildFile; fileRef = B30BF6501C5964B0004FCD53 /* ASLayoutManager.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -489,9 +486,6 @@
489486
205F0E1F1B376416007741D0 /* CoreGraphics+ASConvenience.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "CoreGraphics+ASConvenience.h"; sourceTree = "<group>"; };
490487
205F0E201B376416007741D0 /* CoreGraphics+ASConvenience.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "CoreGraphics+ASConvenience.m"; sourceTree = "<group>"; };
491488
242995D21B29743C00090100 /* ASBasicImageDownloaderTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ASBasicImageDownloaderTests.m; sourceTree = "<group>"; };
492-
251B8EF21BBB3D690087C538 /* ASCollectionDataController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = ASCollectionDataController.h; sourceTree = "<group>"; };
493-
251B8EF31BBB3D690087C538 /* ASCollectionDataController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; lineEnding = 0; path = ASCollectionDataController.mm; sourceTree = "<group>"; };
494-
251B8EF61BBB3D690087C538 /* ASDataController+Subclasses.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "ASDataController+Subclasses.h"; sourceTree = "<group>"; };
495489
2538B6F21BC5D2A2003CA0B4 /* ASCollectionViewFlowLayoutInspectorTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = ASCollectionViewFlowLayoutInspectorTests.m; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objc; };
496490
254C6B511BF8FE6D003EC431 /* ASTextKitTruncationTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ASTextKitTruncationTests.mm; sourceTree = "<group>"; };
497491
254C6B531BF8FF2A003EC431 /* ASTextKitTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ASTextKitTests.mm; sourceTree = "<group>"; };
@@ -1152,7 +1146,6 @@
11521146
CC0F88591E42807F00576FED /* ASCollectionViewFlowLayoutInspector.m */,
11531147
9F98C0231DBDF2A300476D92 /* ASControlTargetAction.h */,
11541148
9F98C0241DBDF2A300476D92 /* ASControlTargetAction.m */,
1155-
251B8EF61BBB3D690087C538 /* ASDataController+Subclasses.h */,
11561149
8B0768B11CE752EC002E1453 /* ASDefaultPlaybackButton.h */,
11571150
8B0768B21CE752EC002E1453 /* ASDefaultPlaybackButton.m */,
11581151
AEB7B0181C5962EA00662EF4 /* ASDefaultPlayButton.h */,
@@ -1241,8 +1234,6 @@
12411234
children = (
12421235
DE8BEABF1C2DF3FC00D57C12 /* ASDelegateProxy.h */,
12431236
DE8BEAC01C2DF3FC00D57C12 /* ASDelegateProxy.m */,
1244-
251B8EF21BBB3D690087C538 /* ASCollectionDataController.h */,
1245-
251B8EF31BBB3D690087C538 /* ASCollectionDataController.mm */,
12461237
464052191A3F83C40061C0BA /* ASDataController.h */,
12471238
4640521A1A3F83C40061C0BA /* ASDataController.mm */,
12481239
E5711A2A1C840C81009619D4 /* ASIndexedNodeContext.h */,
@@ -1464,7 +1455,6 @@
14641455
044285081BAA63FE00D16268 /* ASBatchFetching.h in Headers */,
14651456
AC026B701BD57DBF00BBC17E /* _ASHierarchyChangeSet.h in Headers */,
14661457
CC87BB951DA8193C0090E380 /* ASCellNode+Internal.h in Headers */,
1467-
9C70F20C1CDBE9B6007D6C76 /* ASCollectionDataController.h in Headers */,
14681458
9C8898BD1C738BB800D6B02E /* ASTextKitFontSizeAdjuster.h in Headers */,
14691459
254C6B791BF94DF4003EC431 /* ASTextKitEntityAttribute.h in Headers */,
14701460
CC3B20841C3F76D600798563 /* ASPendingStateController.h in Headers */,
@@ -1481,7 +1471,6 @@
14811471
CC58AA4B1E398E1D002C8CB4 /* ASBlockTypes.h in Headers */,
14821472
6977965F1D8AC8D3007E93D7 /* ASLayoutSpec+Subclasses.h in Headers */,
14831473
692BE8D71E36B65B00C86D87 /* ASLayoutSpecPrivate.h in Headers */,
1484-
9C70F20B1CDBE9A4007D6C76 /* ASDataController+Subclasses.h in Headers */,
14851474
34EFC75D1B701BE900AD841F /* ASInternalHelpers.h in Headers */,
14861475
DEC146B71C37A16A004A0EE7 /* ASCollectionInternal.h in Headers */,
14871476
68B8A4E21CBDB958007E4543 /* ASWeakProxy.h in Headers */,
@@ -1812,7 +1801,6 @@
18121801
690C35671E0567C600069B91 /* ASDimensionDeprecated.mm in Sources */,
18131802
92DD2FE71BF4D0850074C9DD /* ASMapNode.mm in Sources */,
18141803
636EA1A51C7FF4EF00EE152F /* ASDefaultPlayButton.m in Sources */,
1815-
9B92C8851BC2EB6E00EE46B2 /* ASCollectionDataController.mm in Sources */,
18161804
B350623D1B010EFD0018CF92 /* _ASAsyncTransaction.mm in Sources */,
18171805
6947B0C51E36B5040007C478 /* ASStackPositionedLayout.mm in Sources */,
18181806
B35062401B010EFD0018CF92 /* _ASAsyncTransactionContainer.m in Sources */,

AsyncDisplayKit/ASCellNode.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ typedef NS_ENUM(NSUInteger, ASCellNodeVisibilityEvent) {
7979
*
8080
* @return The supplementary element kind, or @c nil if this node does not represent a supplementary element.
8181
*/
82+
//TODO change this to be a generic "kind" or "elementKind" that exposes `nil` for row kind
8283
@property (nonatomic, copy, readonly, nullable) NSString *supplementaryElementKind;
8384

8485
/*

AsyncDisplayKit/ASCollectionNode.mm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#import <AsyncDisplayKit/ASCellNode+Internal.h>
2222
#import <AsyncDisplayKit/AsyncDisplayKit+Debug.h>
2323
#import <AsyncDisplayKit/ASSectionContext.h>
24-
#import <AsyncDisplayKit/ASCollectionDataController.h>
24+
#import <AsyncDisplayKit/ASDataController.h>
2525
#import <AsyncDisplayKit/ASCollectionView+Undeprecated.h>
2626
#import <AsyncDisplayKit/ASThread.h>
2727

@@ -202,9 +202,9 @@ - (void)didExitVisibleState
202202
#pragma mark Setter / Getter
203203

204204
// TODO: Implement this without the view.
205-
- (ASCollectionDataController *)dataController
205+
- (ASDataController *)dataController
206206
{
207-
return (ASCollectionDataController *)self.view.dataController;
207+
return self.view.dataController;
208208
}
209209

210210
// TODO: Implement this without the view.

0 commit comments

Comments
 (0)