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

Commit e15a7db

Browse files
committed
Merge pull request #925 from levi/levi/pager-node
[ASPagerNode] Initial implementation of a paging-specific ASCollectionNode subclass.
2 parents 8a216dd + 669fd38 commit e15a7db

22 files changed

Lines changed: 815 additions & 1 deletion

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 */; settings = {ATTRIBUTES = (Public, ); }; };
194+
25E327571C16819500A2170C /* ASPagerNode.h in Headers */ = {isa = PBXBuildFile; fileRef = 25E327541C16819500A2170C /* ASPagerNode.h */; settings = {ATTRIBUTES = (Public, ); }; };
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>"; };
@@ -893,6 +899,8 @@
893899
0516FA3F1A1563D200B4EBED /* ASMultiplexImageNode.mm */,
894900
055B9FA61A1C154B00035D6D /* ASNetworkImageNode.h */,
895901
055B9FA71A1C154B00035D6D /* ASNetworkImageNode.mm */,
902+
25E327541C16819500A2170C /* ASPagerNode.h */,
903+
25E327551C16819500A2170C /* ASPagerNode.m */,
896904
D785F6601A74327E00291744 /* ASScrollNode.h */,
897905
D785F6611A74327E00291744 /* ASScrollNode.m */,
898906
B0F880581BEAEC7500D17647 /* ASTableNode.h */,
@@ -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/ASCollectionNode.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// Copyright (c) 2015 Facebook. All rights reserved.
77
//
88

9-
#import <AsyncDisplayKit/AsyncDisplayKit.h>
9+
#import <AsyncDisplayKit/ASCollectionView.h>
1010

1111
/**
1212
* ASCollectionNode is a node based class that wraps an ASCollectionView. It can be used

AsyncDisplayKit/ASCollectionNode.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//
88

99
#import "ASCollectionNode.h"
10+
#import "ASDisplayNode+Subclasses.h"
1011

1112
@implementation ASCollectionNode
1213

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/ASCollectionNode.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: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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+
#import <AsyncDisplayKit/AsyncDisplayKit.h>
12+
13+
@interface ASPagerNode () <ASCollectionViewDataSource, ASCollectionViewDelegateFlowLayout> {
14+
UICollectionViewFlowLayout *_flowLayout;
15+
}
16+
17+
@end
18+
19+
@implementation ASPagerNode
20+
21+
- (instancetype)init
22+
{
23+
_flowLayout = [[UICollectionViewFlowLayout alloc] init];
24+
_flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
25+
_flowLayout.minimumInteritemSpacing = 0;
26+
_flowLayout.minimumLineSpacing = 0;
27+
28+
self = [super initWithCollectionViewLayout:_flowLayout];
29+
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];
41+
}
42+
return self;
43+
}
44+
45+
- (void)reloadData
46+
{
47+
[self.view reloadData];
48+
}
49+
50+
- (void)setTuningParameters:(ASRangeTuningParameters)tuningParameters forRangeType:(ASLayoutRangeType)rangeType
51+
{
52+
[self.view setTuningParameters:tuningParameters forRangeType:rangeType];
53+
}
54+
55+
#pragma mark - ASCollectionViewDataSource
56+
57+
- (ASCellNode *)collectionView:(ASCollectionView *)collectionView nodeForItemAtIndexPath:(NSIndexPath *)indexPath
58+
{
59+
ASDisplayNodeAssert(self.dataSource != nil, @"ASPagerNode must have a data source to load paging nodes");
60+
return [self.dataSource pagerNode:self nodeAtIndex:indexPath.item];
61+
}
62+
63+
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
64+
{
65+
ASDisplayNodeAssert(self.dataSource != nil, @"ASPagerNode must have a data source to load paging nodes");
66+
return [self.dataSource numberOfPagesInPagerNode:self];
67+
}
68+
69+
- (ASSizeRange)collectionView:(ASCollectionView *)collectionView constrainedSizeForNodeAtIndexPath:(NSIndexPath *)indexPath
70+
{
71+
return ASSizeRangeMake(CGSizeZero, self.view.bounds.size);
72+
}
73+
74+
@end

AsyncDisplayKit/AsyncDisplayKit.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030

3131
#import <AsyncDisplayKit/ASScrollNode.h>
3232

33+
#import <AsyncDisplayKit/ASPagerNode.h>
34+
3335
#import <AsyncDisplayKit/ASViewController.h>
3436

3537
#import <AsyncDisplayKit/ASChangeSetDataController.h>
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)