Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions AsyncDisplayKit/ASPagerNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@
- (instancetype)initWithFlowLayout:(UICollectionViewFlowLayout *)flowLayout;

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

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

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

Expand Down
15 changes: 7 additions & 8 deletions AsyncDisplayKit/ASPagerNode.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ @interface ASPagerNode () <ASCollectionDataSource, ASCollectionViewDelegateFlowL
@end

@implementation ASPagerNode
@dynamic delegate;
@dynamic view, delegate, dataSource;

- (instancetype)init
{
Expand All @@ -31,6 +31,12 @@ - (instancetype)init
return [self initWithFlowLayout:flowLayout];
}

- (instancetype)initWithCollectionViewLayout:(UICollectionViewLayout *)layout
{
ASDisplayNodeAssert([layout isKindOfClass:[UICollectionViewFlowLayout class]], @"ASPagerNode requires a flow layout.");
return [self initWithFlowLayout:(UICollectionViewFlowLayout *)layout];
}

- (instancetype)initWithFlowLayout:(UICollectionViewFlowLayout *)flowLayout
{
self = [super initWithCollectionViewLayout:flowLayout];
Expand All @@ -40,11 +46,6 @@ - (instancetype)initWithFlowLayout:(UICollectionViewFlowLayout *)flowLayout
return self;
}

- (ASCollectionView *)collectionView
{
return self.view;
}

- (void)setDataSource:(id <ASPagerNodeDataSource>)pagerDataSource
{
if (pagerDataSource != _pagerDataSource) {
Expand All @@ -69,8 +70,6 @@ - (void)didLoad
[super didLoad];

ASCollectionView *cv = self.view;
cv.asyncDataSource = self;
cv.asyncDelegate = self;

cv.pagingEnabled = YES;
cv.allowsSelection = NO;
Expand Down
42 changes: 14 additions & 28 deletions examples/VerticalWithinHorizontalScrolling/Sample/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@
*/

#import <AsyncDisplayKit/AsyncDisplayKit.h>
#import <AsyncDisplayKit/ASAssert.h>

#import "ViewController.h"
#import "GradientTableNode.h"

@interface ViewController () <ASCollectionViewDataSource, ASCollectionViewDelegate>
@interface ViewController () <ASPagerNodeDataSource>
{
ASCollectionView *_pagerView;
ASPagerNode *_pagerNode;
}

@end
Expand All @@ -31,23 +29,12 @@ - (instancetype)init
{
if (!(self = [super init]))
return nil;

UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
// flowLayout.itemSize = [[UIScreen mainScreen] bounds].size;
flowLayout.minimumInteritemSpacing = 0;
flowLayout.minimumLineSpacing = 0;

_pagerView = [[ASCollectionView alloc] initWithCollectionViewLayout:flowLayout];

ASRangeTuningParameters rangeTuningParameters;
rangeTuningParameters.leadingBufferScreenfuls = 1.0;
rangeTuningParameters.trailingBufferScreenfuls = 1.0;
[_pagerView setTuningParameters:rangeTuningParameters forRangeType:ASLayoutRangeTypeRender];
_pagerNode = [[ASPagerNode alloc] init];
_pagerNode.dataSource = self;

_pagerView.pagingEnabled = YES;
_pagerView.asyncDataSource = self;
_pagerView.asyncDelegate = self;
// Could implement ASCollectionDelegate if we wanted extra callbacks, like from UIScrollView.
//_pagerNode.delegate = self;

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

- (void)reloadEverything
{
[_pagerView reloadData];
[_pagerNode reloadData];
}

- (void)viewDidLoad
{
[super viewDidLoad];

[self.view addSubview:_pagerView];
[self.view addSubnode:_pagerNode];
}

- (void)viewWillLayoutSubviews
{
_pagerView.frame = self.view.bounds;
_pagerView.contentInset = UIEdgeInsetsZero;
_pagerNode.frame = self.view.bounds;
}

- (BOOL)prefersStatusBarHidden
Expand All @@ -81,20 +67,20 @@ - (BOOL)prefersStatusBarHidden
}

#pragma mark -
#pragma mark ASTableView.
#pragma mark ASPagerNode.

- (ASCellNode *)collectionView:(ASCollectionView *)collectionView nodeForItemAtIndexPath:(NSIndexPath *)indexPath;
- (ASCellNode *)pagerNode:(ASPagerNode *)pagerNode nodeAtIndex:(NSInteger)index;
{
CGSize boundsSize = collectionView.bounds.size;
CGSize boundsSize = pagerNode.bounds.size;
CGSize gradientRowSize = CGSizeMake(boundsSize.width, 100);
GradientTableNode *node = [[GradientTableNode alloc] initWithElementSize:gradientRowSize];
node.preferredFrameSize = boundsSize;
return node;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
- (NSInteger)numberOfPagesInPagerNode:(ASPagerNode *)pagerNode
{
return (section == 0 ? 10 : 0);
return 10;
}

@end