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

Commit b1b9ad2

Browse files
committed
Merge pull request #1014 from facebook/PagerProxy
[ASPagerNode] Ensure delegate property can be set before the view is loaded.
2 parents 0dc0179 + 1870208 commit b1b9ad2

3 files changed

Lines changed: 24 additions & 38 deletions

File tree

AsyncDisplayKit/ASPagerNode.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,14 @@
2626
- (instancetype)initWithFlowLayout:(UICollectionViewFlowLayout *)flowLayout;
2727

2828
// The underlying ASCollectionView object.
29-
- (ASCollectionView *)collectionView;
29+
@property (nonatomic, readonly) ASCollectionView *view;
3030

3131
// Delegate is optional, and uses the same protocol as ASCollectionNode.
3232
// This includes UIScrollViewDelegate as well as most methods from UICollectionViewDelegate, like willDisplay...
33-
@property (weak, nonatomic) id <ASCollectionDelegate> delegate;
33+
@property (nonatomic, weak) id <ASCollectionDelegate> delegate;
3434

3535
// Data Source is required, and uses a different protocol from ASCollectionNode.
36+
//@property (nonatomic, weak) id <ASPagerNodeDataSource> dataSource;
3637
- (void)setDataSource:(id <ASPagerNodeDataSource>)dataSource;
3738
- (id <ASPagerNodeDataSource>)dataSource;
3839

AsyncDisplayKit/ASPagerNode.m

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ @interface ASPagerNode () <ASCollectionDataSource, ASCollectionViewDelegateFlowL
1919
@end
2020

2121
@implementation ASPagerNode
22-
@dynamic delegate;
22+
@dynamic view, delegate, dataSource;
2323

2424
- (instancetype)init
2525
{
@@ -31,6 +31,12 @@ - (instancetype)init
3131
return [self initWithFlowLayout:flowLayout];
3232
}
3333

34+
- (instancetype)initWithCollectionViewLayout:(UICollectionViewLayout *)layout
35+
{
36+
ASDisplayNodeAssert([layout isKindOfClass:[UICollectionViewFlowLayout class]], @"ASPagerNode requires a flow layout.");
37+
return [self initWithFlowLayout:(UICollectionViewFlowLayout *)layout];
38+
}
39+
3440
- (instancetype)initWithFlowLayout:(UICollectionViewFlowLayout *)flowLayout
3541
{
3642
self = [super initWithCollectionViewLayout:flowLayout];
@@ -40,11 +46,6 @@ - (instancetype)initWithFlowLayout:(UICollectionViewFlowLayout *)flowLayout
4046
return self;
4147
}
4248

43-
- (ASCollectionView *)collectionView
44-
{
45-
return self.view;
46-
}
47-
4849
- (void)setDataSource:(id <ASPagerNodeDataSource>)pagerDataSource
4950
{
5051
if (pagerDataSource != _pagerDataSource) {
@@ -69,8 +70,6 @@ - (void)didLoad
6970
[super didLoad];
7071

7172
ASCollectionView *cv = self.view;
72-
cv.asyncDataSource = self;
73-
cv.asyncDelegate = self;
7473

7574
cv.pagingEnabled = YES;
7675
cv.allowsSelection = NO;

examples/VerticalWithinHorizontalScrolling/Sample/ViewController.m

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,12 @@
1010
*/
1111

1212
#import <AsyncDisplayKit/AsyncDisplayKit.h>
13-
#import <AsyncDisplayKit/ASAssert.h>
14-
1513
#import "ViewController.h"
1614
#import "GradientTableNode.h"
1715

18-
@interface ViewController () <ASCollectionViewDataSource, ASCollectionViewDelegate>
16+
@interface ViewController () <ASPagerNodeDataSource>
1917
{
20-
ASCollectionView *_pagerView;
18+
ASPagerNode *_pagerNode;
2119
}
2220

2321
@end
@@ -31,23 +29,12 @@ - (instancetype)init
3129
{
3230
if (!(self = [super init]))
3331
return nil;
34-
35-
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
36-
flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
37-
// flowLayout.itemSize = [[UIScreen mainScreen] bounds].size;
38-
flowLayout.minimumInteritemSpacing = 0;
39-
flowLayout.minimumLineSpacing = 0;
40-
41-
_pagerView = [[ASCollectionView alloc] initWithCollectionViewLayout:flowLayout];
4232

43-
ASRangeTuningParameters rangeTuningParameters;
44-
rangeTuningParameters.leadingBufferScreenfuls = 1.0;
45-
rangeTuningParameters.trailingBufferScreenfuls = 1.0;
46-
[_pagerView setTuningParameters:rangeTuningParameters forRangeType:ASLayoutRangeTypeRender];
33+
_pagerNode = [[ASPagerNode alloc] init];
34+
_pagerNode.dataSource = self;
4735

48-
_pagerView.pagingEnabled = YES;
49-
_pagerView.asyncDataSource = self;
50-
_pagerView.asyncDelegate = self;
36+
// Could implement ASCollectionDelegate if we wanted extra callbacks, like from UIScrollView.
37+
//_pagerNode.delegate = self;
5138

5239
self.title = @"Paging Table Nodes";
5340
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRedo
@@ -59,20 +46,19 @@ - (instancetype)init
5946

6047
- (void)reloadEverything
6148
{
62-
[_pagerView reloadData];
49+
[_pagerNode reloadData];
6350
}
6451

6552
- (void)viewDidLoad
6653
{
6754
[super viewDidLoad];
6855

69-
[self.view addSubview:_pagerView];
56+
[self.view addSubnode:_pagerNode];
7057
}
7158

7259
- (void)viewWillLayoutSubviews
7360
{
74-
_pagerView.frame = self.view.bounds;
75-
_pagerView.contentInset = UIEdgeInsetsZero;
61+
_pagerNode.frame = self.view.bounds;
7662
}
7763

7864
- (BOOL)prefersStatusBarHidden
@@ -81,20 +67,20 @@ - (BOOL)prefersStatusBarHidden
8167
}
8268

8369
#pragma mark -
84-
#pragma mark ASTableView.
70+
#pragma mark ASPagerNode.
8571

86-
- (ASCellNode *)collectionView:(ASCollectionView *)collectionView nodeForItemAtIndexPath:(NSIndexPath *)indexPath;
72+
- (ASCellNode *)pagerNode:(ASPagerNode *)pagerNode nodeAtIndex:(NSInteger)index;
8773
{
88-
CGSize boundsSize = collectionView.bounds.size;
74+
CGSize boundsSize = pagerNode.bounds.size;
8975
CGSize gradientRowSize = CGSizeMake(boundsSize.width, 100);
9076
GradientTableNode *node = [[GradientTableNode alloc] initWithElementSize:gradientRowSize];
9177
node.preferredFrameSize = boundsSize;
9278
return node;
9379
}
9480

95-
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
81+
- (NSInteger)numberOfPagesInPagerNode:(ASPagerNode *)pagerNode
9682
{
97-
return (section == 0 ? 10 : 0);
83+
return 10;
9884
}
9985

10086
@end

0 commit comments

Comments
 (0)