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

Commit 2754af3

Browse files
lappp9Adlai Holler
authored andcommitted
added index of page with node method to ASPagerNode along with some tests (#2561)
1 parent 9949c63 commit 2754af3

File tree

4 files changed

+116
-3
lines changed

4 files changed

+116
-3
lines changed

AsyncDisplayKit.xcodeproj/project.pbxproj

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,10 @@
196196
68FC85EA1CE29C7D00EDD713 /* ASVisibilityProtocols.h in Headers */ = {isa = PBXBuildFile; fileRef = 68FC85E71CE29C7D00EDD713 /* ASVisibilityProtocols.h */; settings = {ATTRIBUTES = (Public, ); }; };
197197
68FC85EB1CE29C7D00EDD713 /* ASVisibilityProtocols.m in Sources */ = {isa = PBXBuildFile; fileRef = 68FC85E81CE29C7D00EDD713 /* ASVisibilityProtocols.m */; };
198198
68FC85EC1CE29C7D00EDD713 /* ASVisibilityProtocols.m in Sources */ = {isa = PBXBuildFile; fileRef = 68FC85E81CE29C7D00EDD713 /* ASVisibilityProtocols.m */; };
199-
693117CE1DC7C72700DE4784 /* ASDisplayNode+Deprecated.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 683489271D70DE3400327501 /* ASDisplayNode+Deprecated.h */; };
200199
6907C2581DC4ECFE00374C66 /* ASObjectDescriptionHelpers.h in Headers */ = {isa = PBXBuildFile; fileRef = 6907C2561DC4ECFE00374C66 /* ASObjectDescriptionHelpers.h */; settings = {ATTRIBUTES = (Public, ); }; };
201200
6907C2591DC4ECFE00374C66 /* ASObjectDescriptionHelpers.m in Sources */ = {isa = PBXBuildFile; fileRef = 6907C2571DC4ECFE00374C66 /* ASObjectDescriptionHelpers.m */; };
202201
6907C25A1DC4ECFE00374C66 /* ASObjectDescriptionHelpers.m in Sources */ = {isa = PBXBuildFile; fileRef = 6907C2571DC4ECFE00374C66 /* ASObjectDescriptionHelpers.m */; };
202+
693117CE1DC7C72700DE4784 /* ASDisplayNode+Deprecated.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 683489271D70DE3400327501 /* ASDisplayNode+Deprecated.h */; };
203203
69527B121DC84292004785FB /* ASLayoutElementStylePrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 69527B111DC84292004785FB /* ASLayoutElementStylePrivate.h */; };
204204
6959433E1D70815300B0EE1F /* ASDisplayNodeLayout.mm in Sources */ = {isa = PBXBuildFile; fileRef = 6959433C1D70815300B0EE1F /* ASDisplayNodeLayout.mm */; };
205205
6959433F1D70815300B0EE1F /* ASDisplayNodeLayout.mm in Sources */ = {isa = PBXBuildFile; fileRef = 6959433C1D70815300B0EE1F /* ASDisplayNodeLayout.mm */; };
@@ -334,6 +334,7 @@
334334
ACF6ED611B178DC700DA7C62 /* ASOverlayLayoutSpecSnapshotTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = ACF6ED591B178DC700DA7C62 /* ASOverlayLayoutSpecSnapshotTests.mm */; };
335335
ACF6ED621B178DC700DA7C62 /* ASRatioLayoutSpecSnapshotTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = ACF6ED5A1B178DC700DA7C62 /* ASRatioLayoutSpecSnapshotTests.mm */; };
336336
ACF6ED631B178DC700DA7C62 /* ASStackLayoutSpecSnapshotTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = ACF6ED5B1B178DC700DA7C62 /* ASStackLayoutSpecSnapshotTests.mm */; };
337+
AE6987C11DD04E1000B9E458 /* ASPagerNodeTests.m in Sources */ = {isa = PBXBuildFile; fileRef = AE6987C01DD04E1000B9E458 /* ASPagerNodeTests.m */; };
337338
AEB7B01B1C5962EA00662EF4 /* ASDefaultPlayButton.m in Sources */ = {isa = PBXBuildFile; fileRef = AEB7B0191C5962EA00662EF4 /* ASDefaultPlayButton.m */; };
338339
AEEC47E21C20C2DD00EC1693 /* ASVideoNode.mm in Sources */ = {isa = PBXBuildFile; fileRef = AEEC47E01C20C2DD00EC1693 /* ASVideoNode.mm */; };
339340
AEEC47E41C21D3D200EC1693 /* ASVideoNodeTests.m in Sources */ = {isa = PBXBuildFile; fileRef = AEEC47E31C21D3D200EC1693 /* ASVideoNodeTests.m */; };
@@ -1104,6 +1105,7 @@
11041105
ACF6ED591B178DC700DA7C62 /* ASOverlayLayoutSpecSnapshotTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ASOverlayLayoutSpecSnapshotTests.mm; sourceTree = "<group>"; };
11051106
ACF6ED5A1B178DC700DA7C62 /* ASRatioLayoutSpecSnapshotTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ASRatioLayoutSpecSnapshotTests.mm; sourceTree = "<group>"; };
11061107
ACF6ED5B1B178DC700DA7C62 /* ASStackLayoutSpecSnapshotTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ASStackLayoutSpecSnapshotTests.mm; sourceTree = "<group>"; };
1108+
AE6987C01DD04E1000B9E458 /* ASPagerNodeTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ASPagerNodeTests.m; sourceTree = "<group>"; };
11071109
AEB7B0181C5962EA00662EF4 /* ASDefaultPlayButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASDefaultPlayButton.h; sourceTree = "<group>"; };
11081110
AEB7B0191C5962EA00662EF4 /* ASDefaultPlayButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ASDefaultPlayButton.m; sourceTree = "<group>"; };
11091111
AEEC47DF1C20C2DD00EC1693 /* ASVideoNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASVideoNode.h; sourceTree = "<group>"; };
@@ -1414,6 +1416,7 @@
14141416
CC7FD9E01BB5F750005CCB2B /* ASPhotosFrameworkImageRequestTests.m */,
14151417
296A0A341A951ABF005ACEAA /* ASBatchFetchingTests.m */,
14161418
9F06E5CC1B4CAF4200F015D8 /* ASCollectionViewTests.mm */,
1419+
AE6987C01DD04E1000B9E458 /* ASPagerNodeTests.m */,
14171420
2911485B1A77147A005D0878 /* ASControlNodeTests.m */,
14181421
ACF6ED541B178DC700DA7C62 /* ASDimensionTests.mm */,
14191422
058D0A2D195D057000B7D73C /* ASDisplayLayerTests.m */,
@@ -1546,8 +1549,6 @@
15461549
058D0A01195D050800B7D73C /* Private */ = {
15471550
isa = PBXGroup;
15481551
children = (
1549-
9F98C0231DBDF2A300476D92 /* ASControlTargetAction.h */,
1550-
9F98C0241DBDF2A300476D92 /* ASControlTargetAction.m */,
15511552
69C4CAF51DA3147000B1EC9B /* ASLayoutElementStylePrivate.h */,
15521553
058D0A02195D050800B7D73C /* _AS-objc-internal.h */,
15531554
058D0A03195D050800B7D73C /* _ASCoreAnimationExtras.h */,
@@ -2283,6 +2284,7 @@
22832284
2538B6F31BC5D2A2003CA0B4 /* ASCollectionViewFlowLayoutInspectorTests.m in Sources */,
22842285
058D0A39195D057000B7D73C /* ASDisplayNodeAppearanceTests.m in Sources */,
22852286
CCB2F34D1D63CCC6004E6DE9 /* ASDisplayNodeSnapshotTests.m in Sources */,
2287+
AE6987C11DD04E1000B9E458 /* ASPagerNodeTests.m in Sources */,
22862288
058D0A3A195D057000B7D73C /* ASDisplayNodeTests.m in Sources */,
22872289
696FCB311D6E46050093471E /* ASBackgroundLayoutSpecSnapshotTests.mm in Sources */,
22882290
69FEE53D1D95A9AF0086F066 /* ASLayoutElementStyleTests.m in Sources */,

AsyncDisplayKit/ASPagerNode.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ NS_ASSUME_NONNULL_BEGIN
116116
*/
117117
- (ASCellNode *)nodeForPageAtIndex:(NSInteger)index AS_WARN_UNUSED_RESULT;
118118

119+
/**
120+
* Returns the index of the page for the cell passed or NSNotFound
121+
*/
122+
- (NSInteger)indexOfPageWithNode:(ASCellNode *)node;
123+
119124
@end
120125

121126
NS_ASSUME_NONNULL_END

AsyncDisplayKit/ASPagerNode.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,15 @@ - (ASCellNode *)nodeForPageAtIndex:(NSInteger)index
109109
return [self nodeForItemAtIndexPath:[NSIndexPath indexPathForItem:index inSection:0]];
110110
}
111111

112+
- (NSInteger)indexOfPageWithNode:(ASCellNode *)node
113+
{
114+
NSIndexPath *indexPath = [self indexPathForNode:node];
115+
if (!indexPath) {
116+
return NSNotFound;
117+
}
118+
return indexPath.row;
119+
}
120+
112121
#pragma mark - ASCollectionDataSource
113122

114123
- (ASCellNodeBlock)collectionNode:(ASCollectionNode *)collectionNode nodeBlockForItemAtIndexPath:(NSIndexPath *)indexPath
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
//
2+
// ASPagerNodeTests.m
3+
// AsyncDisplayKit
4+
//
5+
// Created by Luke Parham on 11/6/16.
6+
// Copyright © 2016 Facebook. All rights reserved.
7+
//
8+
9+
#import <XCTest/XCTest.h>
10+
#import "ASPagerNode.h"
11+
#import "ASCellNode.h"
12+
13+
@interface ASPagerNodeTestDataSource : NSObject <ASPagerDataSource>
14+
@end
15+
16+
@implementation ASPagerNodeTestDataSource
17+
18+
- (instancetype)init
19+
{
20+
if (!(self = [super init])) {
21+
return nil;
22+
}
23+
return self;
24+
}
25+
26+
- (NSInteger)numberOfPagesInPagerNode:(ASPagerNode *)pagerNode
27+
{
28+
return 2;
29+
}
30+
31+
- (ASCellNode *)pagerNode:(ASPagerNode *)pagerNode nodeAtIndex:(NSInteger)index
32+
{
33+
return [[ASCellNode alloc] init];
34+
}
35+
36+
@end
37+
38+
@interface ASPagerNodeTestController: UIViewController
39+
@property (nonatomic, strong) ASPagerNodeTestDataSource *testDataSource;
40+
@property (nonatomic, strong) ASPagerNode *pagerNode;
41+
@end
42+
43+
@implementation ASPagerNodeTestController
44+
45+
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
46+
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
47+
if (self) {
48+
// Populate these immediately so that they're not unexpectedly nil during tests.
49+
self.testDataSource = [[ASPagerNodeTestDataSource alloc] init];
50+
51+
self.pagerNode = [[ASPagerNode alloc] init];
52+
self.pagerNode.dataSource = self.testDataSource;
53+
54+
[self.view addSubnode:self.pagerNode];
55+
}
56+
return self;
57+
}
58+
59+
@end
60+
61+
@interface ASPagerNodeTests : XCTestCase
62+
@property (nonatomic, strong) ASPagerNode *pagerNode;
63+
64+
@property (nonatomic, strong) ASPagerNodeTestDataSource *testDataSource;
65+
@end
66+
67+
@implementation ASPagerNodeTests
68+
69+
- (void)testPagerReturnsIndexOfPages {
70+
ASPagerNodeTestController *testController = [self testController];
71+
72+
ASCellNode *cellNode = [testController.pagerNode nodeForPageAtIndex:0];
73+
74+
XCTAssertEqual([testController.pagerNode indexOfPageWithNode:cellNode], 0);
75+
}
76+
77+
- (void)testPagerReturnsNotFoundForCellThatDontExistInPager {
78+
ASPagerNodeTestController *testController = [self testController];
79+
80+
ASCellNode *badNode = [[ASCellNode alloc] init];
81+
82+
XCTAssertEqual([testController.pagerNode indexOfPageWithNode:badNode], NSNotFound);
83+
}
84+
85+
- (ASPagerNodeTestController *)testController {
86+
ASPagerNodeTestController *testController = [[ASPagerNodeTestController alloc] initWithNibName:nil bundle:nil];
87+
UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
88+
[window makeKeyAndVisible];
89+
window.rootViewController = testController;
90+
91+
[testController.pagerNode reloadData];
92+
[testController.pagerNode setNeedsLayout];
93+
94+
return testController;
95+
}
96+
97+
@end

0 commit comments

Comments
 (0)