Skip to content

Commit aea5a33

Browse files
author
Levi McCallum
committed
Implement simple horizontal paging node
1 parent 8349be2 commit aea5a33

19 files changed

Lines changed: 809 additions & 0 deletions

File tree

AsyncDisplayKit.xcodeproj/project.pbxproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,10 @@
190190
258FF4281C0D152600A83844 /* ASRangeHandlerVisible.mm in Sources */ = {isa = PBXBuildFile; fileRef = 258FF4261C0D152600A83844 /* ASRangeHandlerVisible.mm */; };
191191
25A977EF1C0D2A5500406B62 /* ASRangeHandlerVisible.mm in Sources */ = {isa = PBXBuildFile; fileRef = 258FF4261C0D152600A83844 /* ASRangeHandlerVisible.mm */; };
192192
25BAA16F1C0D18D2002747C7 /* ASRangeHandlerVisible.h in Headers */ = {isa = PBXBuildFile; fileRef = 258FF4251C0D152600A83844 /* ASRangeHandlerVisible.h */; };
193+
25E327561C16819500A2170C /* ASPagerNode.h in Headers */ = {isa = PBXBuildFile; fileRef = 25E327541C16819500A2170C /* ASPagerNode.h */; };
194+
25E327571C16819500A2170C /* ASPagerNode.h in Headers */ = {isa = PBXBuildFile; fileRef = 25E327541C16819500A2170C /* ASPagerNode.h */; };
195+
25E327581C16819500A2170C /* ASPagerNode.m in Sources */ = {isa = PBXBuildFile; fileRef = 25E327551C16819500A2170C /* ASPagerNode.m */; };
196+
25E327591C16819500A2170C /* ASPagerNode.m in Sources */ = {isa = PBXBuildFile; fileRef = 25E327551C16819500A2170C /* ASPagerNode.m */; };
193197
2767E9411BB19BD600EA9B77 /* ASViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = ACC945A81BA9E7A0005E1FB8 /* ASViewController.h */; settings = {ATTRIBUTES = (Public, ); }; };
194198
2767E9421BB19BD600EA9B77 /* ASViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = ACC945AA1BA9E7C1005E1FB8 /* ASViewController.m */; };
195199
2911485C1A77147A005D0878 /* ASControlNodeTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 2911485B1A77147A005D0878 /* ASControlNodeTests.m */; };
@@ -644,6 +648,8 @@
644648
257754BD1BEE458E00737CA5 /* ASTextNodeWordKerner.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ASTextNodeWordKerner.m; path = TextKit/ASTextNodeWordKerner.m; sourceTree = "<group>"; };
645649
258FF4251C0D152600A83844 /* ASRangeHandlerVisible.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASRangeHandlerVisible.h; sourceTree = "<group>"; };
646650
258FF4261C0D152600A83844 /* ASRangeHandlerVisible.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ASRangeHandlerVisible.mm; sourceTree = "<group>"; };
651+
25E327541C16819500A2170C /* ASPagerNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASPagerNode.h; sourceTree = "<group>"; };
652+
25E327551C16819500A2170C /* ASPagerNode.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ASPagerNode.m; sourceTree = "<group>"; };
647653
2911485B1A77147A005D0878 /* ASControlNodeTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ASControlNodeTests.m; sourceTree = "<group>"; };
648654
292C59991A956527007E5DD6 /* ASLayoutRangeType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASLayoutRangeType.h; sourceTree = "<group>"; };
649655
292C599A1A956527007E5DD6 /* ASRangeHandlerPreload.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASRangeHandlerPreload.h; sourceTree = "<group>"; };
@@ -911,6 +917,8 @@
911917
AC6456051B0A333200CF11B8 /* Layout */,
912918
257754661BED245B00737CA5 /* TextKit */,
913919
058D09B2195D04C000B7D73C /* Supporting Files */,
920+
25E327541C16819500A2170C /* ASPagerNode.h */,
921+
25E327551C16819500A2170C /* ASPagerNode.m */,
914922
);
915923
path = AsyncDisplayKit;
916924
sourceTree = "<group>";
@@ -1246,6 +1254,7 @@
12461254
058D0A83195D060300B7D73C /* ASBaseDefines.h in Headers */,
12471255
054963491A1EA066000F8E56 /* ASBasicImageDownloader.h in Headers */,
12481256
2967F9E21AB0A5190072E4AB /* ASBasicImageDownloaderInternal.h in Headers */,
1257+
25E327561C16819500A2170C /* ASPagerNode.h in Headers */,
12491258
299DA1A91A828D2900162D41 /* ASBatchContext.h in Headers */,
12501259
251B8EF91BBB3D690087C538 /* ASCollectionViewFlowLayoutInspector.h in Headers */,
12511260
044285071BAA63FE00D16268 /* ASBatchFetching.h in Headers */,
@@ -1438,6 +1447,7 @@
14381447
B350622D1B010EFD0018CF92 /* ASScrollDirection.h in Headers */,
14391448
254C6B751BF94DF4003EC431 /* ASTextKitHelpers.h in Headers */,
14401449
B35062081B010EFD0018CF92 /* ASScrollNode.h in Headers */,
1450+
25E327571C16819500A2170C /* ASPagerNode.h in Headers */,
14411451
B35062551B010EFD0018CF92 /* ASSentinel.h in Headers */,
14421452
9C8221961BA237B80037F19A /* ASStackBaselinePositionedLayout.h in Headers */,
14431453
9C49C3701B853961000B0DD5 /* ASStackLayoutable.h in Headers */,
@@ -1687,6 +1697,7 @@
16871697
058D0A28195D050800B7D73C /* ASDisplayNode+AsyncDisplay.mm in Sources */,
16881698
058D0A29195D050800B7D73C /* ASDisplayNode+DebugTiming.mm in Sources */,
16891699
058D0A2A195D050800B7D73C /* ASDisplayNode+UIViewBridge.mm in Sources */,
1700+
25E327581C16819500A2170C /* ASPagerNode.m in Sources */,
16901701
058D0A14195D050800B7D73C /* ASDisplayNode.mm in Sources */,
16911702
058D0A15195D050800B7D73C /* ASDisplayNodeExtras.mm in Sources */,
16921703
0587F9BE1A7309ED00AFF0BA /* ASEditableTextNode.mm in Sources */,
@@ -1815,6 +1826,7 @@
18151826
B350621A1B010EFD0018CF92 /* ASDealloc2MainObject.m in Sources */,
18161827
34EFC75C1B701BD200AD841F /* ASDimension.mm in Sources */,
18171828
B350624E1B010EFD0018CF92 /* ASDisplayNode+AsyncDisplay.mm in Sources */,
1829+
25E327591C16819500A2170C /* ASPagerNode.m in Sources */,
18181830
B35062501B010EFD0018CF92 /* ASDisplayNode+DebugTiming.mm in Sources */,
18191831
254C6B891BF94F8A003EC431 /* ASTextKitRenderer+Positioning.mm in Sources */,
18201832
B35062511B010EFD0018CF92 /* ASDisplayNode+UIViewBridge.mm in Sources */,

AsyncDisplayKit/ASPagerNode.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//
2+
// ASPagerNode.h
3+
// AsyncDisplayKit
4+
//
5+
// Created by Levi McCallum on 12/7/15.
6+
// Copyright © 2015 Facebook. All rights reserved.
7+
//
8+
9+
#import <AsyncDisplayKit/AsyncDisplayKit.h>
10+
11+
@protocol ASPagerNodeDataSource;
12+
13+
@interface ASPagerNode : ASCollectionNode
14+
15+
@property (weak, nonatomic) id<ASPagerNodeDataSource> dataSource;
16+
17+
- (void)reloadData;
18+
19+
- (void)setTuningParameters:(ASRangeTuningParameters)tuningParameters forRangeType:(ASLayoutRangeType)rangeType;
20+
21+
@end
22+
23+
@protocol ASPagerNodeDataSource <NSObject>
24+
25+
- (NSInteger)numberOfPagesInPagerNode:(ASPagerNode *)pagerNode;
26+
27+
- (ASCellNode *)pagerNode:(ASPagerNode *)pagerNode nodeAtIndex:(NSInteger)index;
28+
29+
@end

AsyncDisplayKit/ASPagerNode.m

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
//
2+
// ASPagerNode.m
3+
// AsyncDisplayKit
4+
//
5+
// Created by Levi McCallum on 12/7/15.
6+
// Copyright © 2015 Facebook. All rights reserved.
7+
//
8+
9+
#import "ASPagerNode.h"
10+
11+
@interface ASPagerNode () <ASCollectionViewDataSource, ASCollectionViewDelegateFlowLayout> {
12+
UICollectionViewFlowLayout *_flowLayout;
13+
}
14+
15+
@end
16+
17+
@implementation ASPagerNode
18+
19+
- (instancetype)init
20+
{
21+
_flowLayout = [[UICollectionViewFlowLayout alloc] init];
22+
_flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
23+
_flowLayout.minimumInteritemSpacing = 0;
24+
_flowLayout.minimumLineSpacing = 0;
25+
26+
self = [super initWithCollectionViewLayout:_flowLayout];
27+
if (self != nil) {
28+
self.view.asyncDataSource = self;
29+
self.view.asyncDelegate = self;
30+
31+
self.view.pagingEnabled = YES;
32+
self.view.allowsSelection = NO;
33+
self.view.showsVerticalScrollIndicator = NO;
34+
self.view.showsHorizontalScrollIndicator = NO;
35+
36+
ASRangeTuningParameters tuningParams = { .leadingBufferScreenfuls = 1.0, .trailingBufferScreenfuls = 1.0 };
37+
[self setTuningParameters:tuningParams forRangeType:ASLayoutRangeTypePreload];
38+
[self setTuningParameters:tuningParams forRangeType:ASLayoutRangeTypeRender];
39+
}
40+
return self;
41+
}
42+
43+
- (void)reloadData
44+
{
45+
[self.view reloadData];
46+
}
47+
48+
- (void)setTuningParameters:(ASRangeTuningParameters)tuningParameters forRangeType:(ASLayoutRangeType)rangeType
49+
{
50+
[self.view setTuningParameters:tuningParameters forRangeType:rangeType];
51+
}
52+
53+
#pragma mark - ASCollectionViewDataSource
54+
55+
- (ASCellNode *)collectionView:(ASCollectionView *)collectionView nodeForItemAtIndexPath:(NSIndexPath *)indexPath
56+
{
57+
ASDisplayNodeAssert(self.dataSource != nil, @"ASPagerNode must have a data source to load paging nodes");
58+
return [self.dataSource pagerNode:self nodeAtIndex:indexPath.item];
59+
}
60+
61+
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
62+
{
63+
ASDisplayNodeAssert(self.dataSource != nil, @"ASPagerNode must have a data source to load paging nodes");
64+
return [self.dataSource numberOfPagesInPagerNode:self];
65+
}
66+
67+
- (ASSizeRange)collectionView:(ASCollectionView *)collectionView constrainedSizeForNodeAtIndexPath:(NSIndexPath *)indexPath
68+
{
69+
return ASSizeRangeMake(CGSizeZero, self.view.bounds.size);
70+
}
71+
72+
@end
17.1 KB
Loading
17.9 KB
Loading
22.8 KB
Loading

examples/PagerNode/Podfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
source 'https://github.com/CocoaPods/Specs.git'
2+
platform :ios, '8.0'
3+
pod 'AsyncDisplayKit', :path => '../..'

0 commit comments

Comments
 (0)