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

Commit dd6ddfc

Browse files
committed
Merge pull request #976 from facebook/CollectionRefactoring
Make ASCollectionView always create an ASCollectionNode. Add visibility and interfaceState change notifications.
2 parents c968b8d + 38d9ceb commit dd6ddfc

13 files changed

Lines changed: 217 additions & 219 deletions

File tree

AsyncDisplayKit.xcodeproj/project.pbxproj

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@
128128
242995D31B29743C00090100 /* ASBasicImageDownloaderTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 242995D21B29743C00090100 /* ASBasicImageDownloaderTests.m */; };
129129
251B8EF71BBB3D690087C538 /* ASCollectionDataController.h in Headers */ = {isa = PBXBuildFile; fileRef = 251B8EF21BBB3D690087C538 /* ASCollectionDataController.h */; };
130130
251B8EF81BBB3D690087C538 /* ASCollectionDataController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 251B8EF31BBB3D690087C538 /* ASCollectionDataController.mm */; };
131-
251B8EF91BBB3D690087C538 /* ASCollectionViewFlowLayoutInspector.h in Headers */ = {isa = PBXBuildFile; fileRef = 251B8EF41BBB3D690087C538 /* ASCollectionViewFlowLayoutInspector.h */; };
131+
251B8EF91BBB3D690087C538 /* ASCollectionViewFlowLayoutInspector.h in Headers */ = {isa = PBXBuildFile; fileRef = 251B8EF41BBB3D690087C538 /* ASCollectionViewFlowLayoutInspector.h */; settings = {ATTRIBUTES = (Public, ); }; };
132132
251B8EFA1BBB3D690087C538 /* ASCollectionViewFlowLayoutInspector.m in Sources */ = {isa = PBXBuildFile; fileRef = 251B8EF51BBB3D690087C538 /* ASCollectionViewFlowLayoutInspector.m */; };
133133
251B8EFB1BBB3D690087C538 /* ASDataController+Subclasses.h in Headers */ = {isa = PBXBuildFile; fileRef = 251B8EF61BBB3D690087C538 /* ASDataController+Subclasses.h */; };
134134
2538B6F31BC5D2A2003CA0B4 /* ASCollectionViewFlowLayoutInspectorTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 2538B6F21BC5D2A2003CA0B4 /* ASCollectionViewFlowLayoutInspectorTests.m */; };
@@ -458,6 +458,7 @@
458458
D785F6621A74327E00291744 /* ASScrollNode.h in Headers */ = {isa = PBXBuildFile; fileRef = D785F6601A74327E00291744 /* ASScrollNode.h */; settings = {ATTRIBUTES = (Public, ); }; };
459459
D785F6631A74327E00291744 /* ASScrollNode.m in Sources */ = {isa = PBXBuildFile; fileRef = D785F6611A74327E00291744 /* ASScrollNode.m */; };
460460
DB7121BCD50849C498C886FB /* libPods-AsyncDisplayKitTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = EFA731F0396842FF8AB635EE /* libPods-AsyncDisplayKitTests.a */; };
461+
DE040EF91C2B40AC004692FF /* ASCollectionViewFlowLayoutInspector.h in Headers */ = {isa = PBXBuildFile; fileRef = 251B8EF41BBB3D690087C538 /* ASCollectionViewFlowLayoutInspector.h */; settings = {ATTRIBUTES = (Public, ); }; };
461462
DE6EA3221C14000600183B10 /* ASDisplayNode+FrameworkPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = DE6EA3211C14000600183B10 /* ASDisplayNode+FrameworkPrivate.h */; };
462463
DE6EA3231C14000600183B10 /* ASDisplayNode+FrameworkPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = DE6EA3211C14000600183B10 /* ASDisplayNode+FrameworkPrivate.h */; };
463464
DECBD6E71BE56E1900CF4905 /* ASButtonNode.h in Headers */ = {isa = PBXBuildFile; fileRef = DECBD6E51BE56E1900CF4905 /* ASButtonNode.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -1451,6 +1452,7 @@
14511452
B35062551B010EFD0018CF92 /* ASSentinel.h in Headers */,
14521453
9C8221961BA237B80037F19A /* ASStackBaselinePositionedLayout.h in Headers */,
14531454
9C49C3701B853961000B0DD5 /* ASStackLayoutable.h in Headers */,
1455+
DE040EF91C2B40AC004692FF /* ASCollectionViewFlowLayoutInspector.h in Headers */,
14541456
34EFC7701B701CFA00AD841F /* ASStackLayoutDefines.h in Headers */,
14551457
254C6B7B1BF94DF4003EC431 /* ASTextKitRenderer+Positioning.h in Headers */,
14561458
CC7FD9E21BB603FF005CCB2B /* ASPhotosFrameworkImageRequest.h in Headers */,
@@ -1523,7 +1525,6 @@
15231525
058D09B9195D04C000B7D73C /* Frameworks */,
15241526
058D09BA195D04C000B7D73C /* Resources */,
15251527
3B9D88CDF51B429C8409E4B6 /* Copy Pods Resources */,
1526-
5ADEA7587189397768F2B36C /* Embed Pods Frameworks */,
15271528
);
15281529
buildRules = (
15291530
);
@@ -1623,21 +1624,6 @@
16231624
/* End PBXResourcesBuildPhase section */
16241625

16251626
/* Begin PBXShellScriptBuildPhase section */
1626-
1B86F48711505F91D5FEF571 /* Embed Pods Frameworks */ = {
1627-
isa = PBXShellScriptBuildPhase;
1628-
buildActionMask = 2147483647;
1629-
files = (
1630-
);
1631-
inputPaths = (
1632-
);
1633-
name = "Embed Pods Frameworks";
1634-
outputPaths = (
1635-
);
1636-
runOnlyForDeploymentPostprocessing = 0;
1637-
shellPath = /bin/sh;
1638-
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-AsyncDisplayKitTests/Pods-AsyncDisplayKitTests-frameworks.sh\"\n";
1639-
showEnvVarsInLog = 0;
1640-
};
16411627
2E61B6A0DB0F436A9DDBE86F /* Check Pods Manifest.lock */ = {
16421628
isa = PBXShellScriptBuildPhase;
16431629
buildActionMask = 2147483647;
@@ -1668,21 +1654,6 @@
16681654
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-AsyncDisplayKitTests/Pods-AsyncDisplayKitTests-resources.sh\"\n";
16691655
showEnvVarsInLog = 0;
16701656
};
1671-
5ADEA7587189397768F2B36C /* Embed Pods Frameworks */ = {
1672-
isa = PBXShellScriptBuildPhase;
1673-
buildActionMask = 2147483647;
1674-
files = (
1675-
);
1676-
inputPaths = (
1677-
);
1678-
name = "Embed Pods Frameworks";
1679-
outputPaths = (
1680-
);
1681-
runOnlyForDeploymentPostprocessing = 0;
1682-
shellPath = /bin/sh;
1683-
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-AsyncDisplayKitTests/Pods-AsyncDisplayKitTests-frameworks.sh\"\n";
1684-
showEnvVarsInLog = 0;
1685-
};
16861657
/* End PBXShellScriptBuildPhase section */
16871658

16881659
/* Begin PBXSourcesBuildPhase section */

AsyncDisplayKit/ASCollectionNode.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
*/
1515
@interface ASCollectionNode : ASDisplayNode
1616

17-
- (instancetype)initWithCollectionViewLayout:(UICollectionViewLayout *)layout NS_DESIGNATED_INITIALIZER;
17+
- (instancetype)initWithCollectionViewLayout:(UICollectionViewLayout *)layout;
18+
- (instancetype)initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionViewLayout *)layout;
1819

1920
@property (nonatomic, readonly) ASCollectionView *view;
2021

AsyncDisplayKit/ASCollectionNode.m

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
#import "ASCollectionNode.h"
1010
#import "ASDisplayNode+Subclasses.h"
1111

12+
@interface ASCollectionView (Internal)
13+
- (instancetype)_initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionViewLayout *)layout;
14+
@end
15+
1216
@implementation ASCollectionNode
1317

1418
- (instancetype)init
@@ -20,7 +24,12 @@ - (instancetype)init
2024

2125
- (instancetype)initWithCollectionViewLayout:(UICollectionViewLayout *)layout
2226
{
23-
if (self = [super initWithViewBlock:^UIView *{ return [[ASCollectionView alloc] initWithCollectionViewLayout:layout]; }]) {
27+
return [self initWithFrame:CGRectZero collectionViewLayout:layout];
28+
}
29+
30+
- (instancetype)initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionViewLayout *)layout
31+
{
32+
if (self = [super initWithViewBlock:^UIView *{ return [[ASCollectionView alloc] _initWithFrame:frame collectionViewLayout:layout]; }]) {
2433
return self;
2534
}
2635
return nil;
@@ -31,6 +40,11 @@ - (ASCollectionView *)view
3140
return (ASCollectionView *)[super view];
3241
}
3342

43+
- (void)visibilityDidChange:(BOOL)isVisible
44+
{
45+
46+
}
47+
3448
- (void)clearContents
3549
{
3650
[super clearContents];

AsyncDisplayKit/ASCollectionView.h

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#import <AsyncDisplayKit/ASCollectionViewProtocols.h>
1313
#import <AsyncDisplayKit/ASBaseDefines.h>
1414
#import <AsyncDisplayKit/ASBatchContext.h>
15-
15+
#import <AsyncDisplayKit/ASCollectionViewFlowLayoutInspector.h>
1616

1717
@class ASCellNode;
1818
@protocol ASCollectionViewDataSource;
@@ -27,7 +27,13 @@
2727
*/
2828
@interface ASCollectionView : UICollectionView
2929

30+
/**
31+
* Initializer.
32+
*
33+
* @param layout The layout object to use for organizing items. The collection view stores a strong reference to the specified object. Must not be nil.
34+
*/
3035
- (instancetype)initWithCollectionViewLayout:(UICollectionViewLayout *)layout;
36+
- (instancetype)initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionViewLayout *)layout;
3137

3238
@property (nonatomic, weak) id<ASCollectionViewDataSource> asyncDataSource;
3339
@property (nonatomic, weak) id<ASCollectionViewDelegate> asyncDelegate; // must not be nil
@@ -52,27 +58,6 @@
5258
*/
5359
- (void)setTuningParameters:(ASRangeTuningParameters)tuningParameters forRangeType:(ASLayoutRangeType)rangeType;
5460

55-
/**
56-
* Initializer.
57-
*
58-
* @param frame The frame rectangle for the collection view, measured in points. The origin of the frame is relative to the superview
59-
* in which you plan to add it. This frame is passed to the superclass during initialization.
60-
*
61-
* @param layout The layout object to use for organizing items. The collection view stores a strong reference to the specified object.
62-
* Must not be nil.
63-
*
64-
* @param asyncDataFetchingEnabled Enable the data fetching in async mode.
65-
*
66-
* @discussion If asyncDataFetching is enabled, the `ASCollectionView` will fetch data through `collectionView:numberOfRowsInSection:` and
67-
* `collectionView:nodeForRowAtIndexPath:` in async mode from background thread. Otherwise, the methods will be invoked synchronically
68-
* from calling thread.
69-
* Enabling asyncDataFetching could avoid blocking main thread for `ASCellNode` allocation, which is frequently reported issue for
70-
* large scale data. On another hand, the application code need take the responsibility to avoid data inconsistence. Specifically,
71-
* we will lock the data source through `collectionViewLockDataSource`, and unlock it by `collectionViewUnlockDataSource` after the data fetching.
72-
* The application should not update the data source while the data source is locked, to keep data consistence.
73-
*/
74-
- (instancetype)initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionViewLayout *)layout asyncDataFetching:(BOOL)asyncDataFetchingEnabled;
75-
7661
/**
7762
* The number of screens left to scroll before the delegate -collectionView:beginBatchFetchingWithContext: is called.
7863
*
@@ -429,4 +414,10 @@
429414
*/
430415
- (CGSize)collectionView:(ASCollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section;
431416

432-
@end
417+
@end
418+
419+
@interface ASCollectionView (Deprecated)
420+
421+
- (instancetype)initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionViewLayout *)layout asyncDataFetching:(BOOL)asyncDataFetchingEnabled ASDISPLAYNODE_DEPRECATED;
422+
423+
@end

0 commit comments

Comments
 (0)