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

Commit 676a1d3

Browse files
committed
Merge pull request #964 from levi/master
[ASPagerNode] Integrate feedback from initial review, incl. move view properties to -didLoad.
2 parents 841bed6 + 10030df commit 676a1d3

5 files changed

Lines changed: 92 additions & 34 deletions

File tree

AsyncDisplayKit/ASCollectionNode.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,48 @@
1818

1919
@property (nonatomic, readonly) ASCollectionView *view;
2020

21+
/**
22+
* Tuning parameters for a range type.
23+
*
24+
* @param rangeType The range type to get the tuning parameters for.
25+
*
26+
* @returns A tuning parameter value for the given range type.
27+
*
28+
* Defaults to the render range having one sceenful both leading and trailing and the preload range having two
29+
* screenfuls in both directions.
30+
*/
31+
- (ASRangeTuningParameters)tuningParametersForRangeType:(ASLayoutRangeType)rangeType;
32+
33+
/**
34+
* Set the tuning parameters for a range type.
35+
*
36+
* @param tuningParameters The tuning parameters to store for a range type.
37+
* @param rangeType The range type to set the tuning parameters for.
38+
*/
39+
- (void)setTuningParameters:(ASRangeTuningParameters)tuningParameters forRangeType:(ASLayoutRangeType)rangeType;
40+
41+
/**
42+
* Reload everything from scratch, destroying the working range and all cached nodes.
43+
*
44+
* @param completion block to run on completion of asynchronous loading or nil. If supplied, the block is run on
45+
* the main thread.
46+
* @warning This method is substantially more expensive than UICollectionView's version.
47+
*/
48+
- (void)reloadDataWithCompletion:(void (^)())completion;
49+
50+
/**
51+
* Reload everything from scratch, destroying the working range and all cached nodes.
52+
*
53+
* @warning This method is substantially more expensive than UICollectionView's version.
54+
*/
55+
- (void)reloadData;
56+
57+
/**
58+
* Reload everything from scratch entirely on the main thread, destroying the working range and all cached nodes.
59+
*
60+
* @warning This method is substantially more expensive than UICollectionView's version and will block the main thread
61+
* while all the cells load.
62+
*/
63+
- (void)reloadDataImmediately;
64+
2165
@end

AsyncDisplayKit/ASCollectionNode.m

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,31 @@ - (void)clearFetchedData
4343
[self.view clearFetchedData];
4444
}
4545

46+
#pragma mark - ASCollectionView Forwards
47+
48+
- (ASRangeTuningParameters)tuningParametersForRangeType:(ASLayoutRangeType)rangeType
49+
{
50+
return [self.view tuningParametersForRangeType:rangeType];
51+
}
52+
53+
- (void)setTuningParameters:(ASRangeTuningParameters)tuningParameters forRangeType:(ASLayoutRangeType)rangeType
54+
{
55+
return [self.view setTuningParameters:tuningParameters forRangeType:rangeType];
56+
}
57+
58+
- (void)reloadDataWithCompletion:(void (^)())completion
59+
{
60+
[self.view reloadDataWithCompletion:completion];
61+
}
62+
63+
- (void)reloadData
64+
{
65+
[self.view reloadData];
66+
}
67+
68+
- (void)reloadDataImmediately
69+
{
70+
[self.view reloadDataImmediately];
71+
}
72+
4673
@end

AsyncDisplayKit/ASPagerNode.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414

1515
@property (weak, nonatomic) id<ASPagerNodeDataSource> dataSource;
1616

17-
- (void)reloadData;
18-
19-
- (void)setTuningParameters:(ASRangeTuningParameters)tuningParameters forRangeType:(ASLayoutRangeType)rangeType;
17+
- (void)scrollToPageAtIndex:(NSInteger)index animated:(BOOL)animated;
2018

2119
@end
2220

AsyncDisplayKit/ASPagerNode.m

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,29 +27,34 @@ - (instancetype)init
2727

2828
self = [super initWithCollectionViewLayout:_flowLayout];
2929
if (self != nil) {
30-
self.view.asyncDataSource = self;
31-
self.view.asyncDelegate = self;
32-
33-
self.view.pagingEnabled = YES;
34-
self.view.allowsSelection = NO;
35-
self.view.showsVerticalScrollIndicator = NO;
36-
self.view.showsHorizontalScrollIndicator = NO;
37-
38-
ASRangeTuningParameters tuningParams = { .leadingBufferScreenfuls = 1.0, .trailingBufferScreenfuls = 1.0 };
39-
[self setTuningParameters:tuningParams forRangeType:ASLayoutRangeTypePreload];
40-
[self setTuningParameters:tuningParams forRangeType:ASLayoutRangeTypeRender];
4130
}
4231
return self;
4332
}
4433

45-
- (void)reloadData
34+
- (void)didLoad
4635
{
47-
[self.view reloadData];
36+
[super didLoad];
37+
38+
self.view.asyncDataSource = self;
39+
self.view.asyncDelegate = self;
40+
41+
self.view.pagingEnabled = YES;
42+
self.view.allowsSelection = NO;
43+
self.view.showsVerticalScrollIndicator = NO;
44+
self.view.showsHorizontalScrollIndicator = NO;
45+
46+
ASRangeTuningParameters preloadParams = { .leadingBufferScreenfuls = 2.0, .trailingBufferScreenfuls = 2.0 };
47+
ASRangeTuningParameters renderParams = { .leadingBufferScreenfuls = 1.0, .trailingBufferScreenfuls = 1.0 };
48+
[self setTuningParameters:preloadParams forRangeType:ASLayoutRangeTypePreload];
49+
[self setTuningParameters:renderParams forRangeType:ASLayoutRangeTypeRender];
4850
}
4951

50-
- (void)setTuningParameters:(ASRangeTuningParameters)tuningParameters forRangeType:(ASLayoutRangeType)rangeType
52+
#pragma mark - Helpers
53+
54+
- (void)scrollToPageAtIndex:(NSInteger)index animated:(BOOL)animated
5155
{
52-
[self.view setTuningParameters:tuningParameters forRangeType:rangeType];
56+
NSIndexPath *indexPath = [NSIndexPath indexPathForItem:index inSection:0];
57+
[self.view scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionLeft animated:animated];
5358
}
5459

5560
#pragma mark - ASCollectionViewDataSource

examples/PagerNode/Sample.xcodeproj/project.pbxproj

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@
123123
05E2127E19D4DB510098F589 /* Frameworks */,
124124
05E2127F19D4DB510098F589 /* Resources */,
125125
F012A6F39E0149F18F564F50 /* Copy Pods Resources */,
126-
D668455448B2FFAC9BEF28DD /* Embed Pods Frameworks */,
127126
);
128127
buildRules = (
129128
);
@@ -180,21 +179,6 @@
180179
/* End PBXResourcesBuildPhase section */
181180

182181
/* Begin PBXShellScriptBuildPhase section */
183-
D668455448B2FFAC9BEF28DD /* Embed Pods Frameworks */ = {
184-
isa = PBXShellScriptBuildPhase;
185-
buildActionMask = 2147483647;
186-
files = (
187-
);
188-
inputPaths = (
189-
);
190-
name = "Embed Pods Frameworks";
191-
outputPaths = (
192-
);
193-
runOnlyForDeploymentPostprocessing = 0;
194-
shellPath = /bin/sh;
195-
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods/Pods-frameworks.sh\"\n";
196-
showEnvVarsInLog = 0;
197-
};
198182
E080B80F89C34A25B3488E26 /* Check Pods Manifest.lock */ = {
199183
isa = PBXShellScriptBuildPhase;
200184
buildActionMask = 2147483647;

0 commit comments

Comments
 (0)