Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement simple horizontal paging node
- Loading branch information
Levi McCallum
committed
Dec 17, 2015
1 parent
8349be2
commit aea5a33
Showing
19 changed files
with
809 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// | ||
// ASPagerNode.h | ||
// AsyncDisplayKit | ||
// | ||
// Created by Levi McCallum on 12/7/15. | ||
// Copyright © 2015 Facebook. All rights reserved. | ||
// | ||
|
||
#import <AsyncDisplayKit/AsyncDisplayKit.h> | ||
|
||
@protocol ASPagerNodeDataSource; | ||
|
||
@interface ASPagerNode : ASCollectionNode | ||
|
||
@property (weak, nonatomic) id<ASPagerNodeDataSource> dataSource; | ||
|
||
- (void)reloadData; | ||
|
||
- (void)setTuningParameters:(ASRangeTuningParameters)tuningParameters forRangeType:(ASLayoutRangeType)rangeType; | ||
|
||
@end | ||
|
||
@protocol ASPagerNodeDataSource <NSObject> | ||
|
||
- (NSInteger)numberOfPagesInPagerNode:(ASPagerNode *)pagerNode; | ||
|
||
- (ASCellNode *)pagerNode:(ASPagerNode *)pagerNode nodeAtIndex:(NSInteger)index; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// | ||
// ASPagerNode.m | ||
// AsyncDisplayKit | ||
// | ||
// Created by Levi McCallum on 12/7/15. | ||
// Copyright © 2015 Facebook. All rights reserved. | ||
// | ||
|
||
#import "ASPagerNode.h" | ||
|
||
@interface ASPagerNode () <ASCollectionViewDataSource, ASCollectionViewDelegateFlowLayout> { | ||
UICollectionViewFlowLayout *_flowLayout; | ||
} | ||
|
||
@end | ||
|
||
@implementation ASPagerNode | ||
|
||
- (instancetype)init | ||
{ | ||
_flowLayout = [[UICollectionViewFlowLayout alloc] init]; | ||
_flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal; | ||
_flowLayout.minimumInteritemSpacing = 0; | ||
_flowLayout.minimumLineSpacing = 0; | ||
|
||
self = [super initWithCollectionViewLayout:_flowLayout]; | ||
if (self != nil) { | ||
self.view.asyncDataSource = self; | ||
self.view.asyncDelegate = self; | ||
|
||
self.view.pagingEnabled = YES; | ||
self.view.allowsSelection = NO; | ||
self.view.showsVerticalScrollIndicator = NO; | ||
self.view.showsHorizontalScrollIndicator = NO; | ||
|
||
ASRangeTuningParameters tuningParams = { .leadingBufferScreenfuls = 1.0, .trailingBufferScreenfuls = 1.0 }; | ||
[self setTuningParameters:tuningParams forRangeType:ASLayoutRangeTypePreload]; | ||
[self setTuningParameters:tuningParams forRangeType:ASLayoutRangeTypeRender]; | ||
} | ||
return self; | ||
} | ||
|
||
- (void)reloadData | ||
{ | ||
[self.view reloadData]; | ||
} | ||
|
||
- (void)setTuningParameters:(ASRangeTuningParameters)tuningParameters forRangeType:(ASLayoutRangeType)rangeType | ||
{ | ||
[self.view setTuningParameters:tuningParameters forRangeType:rangeType]; | ||
} | ||
|
||
#pragma mark - ASCollectionViewDataSource | ||
|
||
- (ASCellNode *)collectionView:(ASCollectionView *)collectionView nodeForItemAtIndexPath:(NSIndexPath *)indexPath | ||
{ | ||
ASDisplayNodeAssert(self.dataSource != nil, @"ASPagerNode must have a data source to load paging nodes"); | ||
return [self.dataSource pagerNode:self nodeAtIndex:indexPath.item]; | ||
} | ||
|
||
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section | ||
{ | ||
ASDisplayNodeAssert(self.dataSource != nil, @"ASPagerNode must have a data source to load paging nodes"); | ||
return [self.dataSource numberOfPagesInPagerNode:self]; | ||
} | ||
|
||
- (ASSizeRange)collectionView:(ASCollectionView *)collectionView constrainedSizeForNodeAtIndexPath:(NSIndexPath *)indexPath | ||
{ | ||
return ASSizeRangeMake(CGSizeZero, self.view.bounds.size); | ||
} | ||
|
||
@end |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
source 'https://github.com/CocoaPods/Specs.git' | ||
platform :ios, '8.0' | ||
pod 'AsyncDisplayKit', :path => '../..' |
Oops, something went wrong.