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

Commit 3b4785c

Browse files
committed
Added sample project using networking and infinite scrolling and random cats
1 parent 64ad48a commit 3b4785c

31 files changed

Lines changed: 1915 additions & 0 deletions
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 => '../..'

examples/CatDealsCollectionView/Sample.xcodeproj/project.pbxproj

Lines changed: 405 additions & 0 deletions
Large diffs are not rendered by default.

examples/CatDealsCollectionView/Sample.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "0620"
4+
version = "1.3">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES">
8+
<BuildActionEntries>
9+
<BuildActionEntry
10+
buildForTesting = "YES"
11+
buildForRunning = "YES"
12+
buildForProfiling = "YES"
13+
buildForArchiving = "YES"
14+
buildForAnalyzing = "YES">
15+
<BuildableReference
16+
BuildableIdentifier = "primary"
17+
BlueprintIdentifier = "AC3C4A5D1A11F47200143C57"
18+
BuildableName = "Sample.app"
19+
BlueprintName = "Sample"
20+
ReferencedContainer = "container:Sample.xcodeproj">
21+
</BuildableReference>
22+
</BuildActionEntry>
23+
</BuildActionEntries>
24+
</BuildAction>
25+
<TestAction
26+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
27+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
28+
shouldUseLaunchSchemeArgsEnv = "YES"
29+
buildConfiguration = "Debug">
30+
<Testables>
31+
</Testables>
32+
<MacroExpansion>
33+
<BuildableReference
34+
BuildableIdentifier = "primary"
35+
BlueprintIdentifier = "AC3C4A5D1A11F47200143C57"
36+
BuildableName = "Sample.app"
37+
BlueprintName = "Sample"
38+
ReferencedContainer = "container:Sample.xcodeproj">
39+
</BuildableReference>
40+
</MacroExpansion>
41+
</TestAction>
42+
<LaunchAction
43+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
44+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
45+
launchStyle = "0"
46+
useCustomWorkingDirectory = "NO"
47+
buildConfiguration = "Debug"
48+
ignoresPersistentStateOnLaunch = "NO"
49+
debugDocumentVersioning = "YES"
50+
allowLocationSimulation = "YES">
51+
<BuildableProductRunnable
52+
runnableDebuggingMode = "0">
53+
<BuildableReference
54+
BuildableIdentifier = "primary"
55+
BlueprintIdentifier = "AC3C4A5D1A11F47200143C57"
56+
BuildableName = "Sample.app"
57+
BlueprintName = "Sample"
58+
ReferencedContainer = "container:Sample.xcodeproj">
59+
</BuildableReference>
60+
</BuildableProductRunnable>
61+
<AdditionalOptions>
62+
</AdditionalOptions>
63+
</LaunchAction>
64+
<ProfileAction
65+
shouldUseLaunchSchemeArgsEnv = "YES"
66+
savedToolIdentifier = ""
67+
useCustomWorkingDirectory = "NO"
68+
buildConfiguration = "Release"
69+
debugDocumentVersioning = "YES">
70+
<BuildableProductRunnable
71+
runnableDebuggingMode = "0">
72+
<BuildableReference
73+
BuildableIdentifier = "primary"
74+
BlueprintIdentifier = "AC3C4A5D1A11F47200143C57"
75+
BuildableName = "Sample.app"
76+
BlueprintName = "Sample"
77+
ReferencedContainer = "container:Sample.xcodeproj">
78+
</BuildableReference>
79+
</BuildableProductRunnable>
80+
</ProfileAction>
81+
<AnalyzeAction
82+
buildConfiguration = "Debug">
83+
</AnalyzeAction>
84+
<ArchiveAction
85+
buildConfiguration = "Release"
86+
revealArchiveInOrganizer = "YES">
87+
</ArchiveAction>
88+
</Scheme>

examples/CatDealsCollectionView/Sample.xcworkspace/contents.xcworkspacedata

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* This file provided by Facebook is for non-commercial testing and evaluation
2+
* purposes only. Facebook reserves all rights not expressly granted.
3+
*
4+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
5+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
6+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
7+
* FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
8+
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
9+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10+
*/
11+
12+
#import <UIKit/UIKit.h>
13+
14+
#define SIMULATE_WEB_RESPONSE 0
15+
16+
@interface AppDelegate : UIResponder <UIApplicationDelegate>
17+
18+
@property (strong, nonatomic) UIWindow *window;
19+
20+
@end
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/* This file provided by Facebook is for non-commercial testing and evaluation
2+
* purposes only. Facebook reserves all rights not expressly granted.
3+
*
4+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
5+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
6+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
7+
* FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
8+
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
9+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10+
*/
11+
12+
#import "AppDelegate.h"
13+
14+
#import "PresentingViewController.h"
15+
#import "ViewController.h"
16+
17+
@implementation AppDelegate
18+
19+
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
20+
{
21+
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
22+
self.window.backgroundColor = [UIColor whiteColor];
23+
self.window.rootViewController = [[UINavigationController alloc] init];
24+
25+
[self pushNewViewControllerAnimated:NO];
26+
27+
[self.window makeKeyAndVisible];
28+
29+
return YES;
30+
}
31+
32+
- (void)pushNewViewControllerAnimated:(BOOL)animated
33+
{
34+
UINavigationController *navController = (UINavigationController *)self.window.rootViewController;
35+
36+
#if SIMULATE_WEB_RESPONSE
37+
UIViewController *viewController = [[PresentingViewController alloc] init];
38+
#else
39+
UIViewController *viewController = [[ViewController alloc] init];
40+
viewController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Push Another Copy" style:UIBarButtonItemStylePlain target:self action:@selector(pushNewViewController)];
41+
#endif
42+
43+
[navController pushViewController:viewController animated:animated];
44+
}
45+
46+
- (void)pushNewViewController
47+
{
48+
[self pushNewViewControllerAnimated:YES];
49+
}
50+
51+
@end
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/* This file provided by Facebook is for non-commercial testing and evaluation
2+
* purposes only. Facebook reserves all rights not expressly granted.
3+
*
4+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
5+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
6+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
7+
* FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
8+
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
9+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10+
*/
11+
12+
#import <AsyncDisplayKit/AsyncDisplayKit.h>
13+
14+
/**
15+
* Simple node that displays a placekitten.com attribution.
16+
*/
17+
@interface BlurbNode : ASCellNode
18+
19+
+ (CGFloat)desiredHeightForWidth:(CGFloat)width;
20+
21+
@end
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/* This file provided by Facebook is for non-commercial testing and evaluation
2+
* purposes only. Facebook reserves all rights not expressly granted.
3+
*
4+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
5+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
6+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
7+
* FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
8+
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
9+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10+
*/
11+
12+
#import "BlurbNode.h"
13+
14+
#import <AsyncDisplayKit/ASDisplayNode+Subclasses.h>
15+
#import <AsyncDisplayKit/ASHighlightOverlayLayer.h>
16+
17+
#import <AsyncDisplayKit/ASInsetLayoutSpec.h>
18+
#import <AsyncDisplayKit/ASCenterLayoutSpec.h>
19+
20+
static CGFloat kFixedHeight = 75.0f;
21+
static CGFloat kTextPadding = 10.0f;
22+
23+
@interface BlurbNode () <ASTextNodeDelegate>
24+
{
25+
ASTextNode *_textNode;
26+
}
27+
28+
@end
29+
30+
31+
@implementation BlurbNode
32+
33+
#pragma mark -
34+
#pragma mark ASCellNode.
35+
36+
+ (CGFloat)desiredHeightForWidth:(CGFloat)width {
37+
return kFixedHeight;
38+
}
39+
40+
- (instancetype)init
41+
{
42+
if (!(self = [super init]))
43+
return nil;
44+
45+
self.backgroundColor = [UIColor lightGrayColor];
46+
// create a text node
47+
_textNode = [[ASTextNode alloc] init];
48+
_textNode.maximumNumberOfLines = 2;
49+
50+
// configure the node to support tappable links
51+
_textNode.delegate = self;
52+
_textNode.userInteractionEnabled = YES;
53+
54+
// generate an attributed string using the custom link attribute specified above
55+
NSString *blurb = @"Kittens courtesy lorempixel.com \U0001F638 \nTitles courtesy of catipsum.com";
56+
NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:blurb];
57+
[string addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"HelveticaNeue-Light" size:16.0f] range:NSMakeRange(0, blurb.length)];
58+
[string addAttributes:@{
59+
NSLinkAttributeName: [NSURL URLWithString:@"http://lorempixel.com/"],
60+
NSForegroundColorAttributeName: [UIColor blueColor],
61+
NSUnderlineStyleAttributeName: @(NSUnderlineStyleSingle | NSUnderlinePatternDot),
62+
}
63+
range:[blurb rangeOfString:@"lorempixel.com"]];
64+
[string addAttributes:@{
65+
NSLinkAttributeName: [NSURL URLWithString:@"http://www.catipsum.com/"],
66+
NSForegroundColorAttributeName: [UIColor blueColor],
67+
NSUnderlineStyleAttributeName: @(NSUnderlineStyleSingle | NSUnderlinePatternDot),
68+
} range:[blurb rangeOfString:@"catipsum.com"]];
69+
_textNode.attributedString = string;
70+
71+
// add it as a subnode, and we're done
72+
[self addSubnode:_textNode];
73+
74+
return self;
75+
}
76+
77+
- (void)didLoad
78+
{
79+
// enable highlighting now that self.layer has loaded -- see ASHighlightOverlayLayer.h
80+
self.layer.as_allowsHighlightDrawing = YES;
81+
82+
[super didLoad];
83+
}
84+
85+
- (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize
86+
{
87+
ASCenterLayoutSpec *centerSpec = [[ASCenterLayoutSpec alloc] init];
88+
centerSpec.centeringOptions = ASCenterLayoutSpecCenteringX;
89+
centerSpec.sizingOptions = ASCenterLayoutSpecSizingOptionMinimumY;
90+
centerSpec.child = _textNode;
91+
92+
UIEdgeInsets padding =UIEdgeInsetsMake(kTextPadding, kTextPadding, kTextPadding, kTextPadding);
93+
return [ASInsetLayoutSpec insetLayoutSpecWithInsets:padding child:centerSpec];
94+
}
95+
96+
97+
#pragma mark -
98+
#pragma mark ASTextNodeDelegate methods.
99+
100+
- (BOOL)textNode:(ASTextNode *)richTextNode shouldHighlightLinkAttribute:(NSString *)attribute value:(id)value atPoint:(CGPoint)point
101+
{
102+
// opt into link highlighting -- tap and hold the link to try it! must enable highlighting on a layer, see -didLoad
103+
return YES;
104+
}
105+
106+
- (void)textNode:(ASTextNode *)richTextNode tappedLinkAttribute:(NSString *)attribute value:(NSURL *)URL atPoint:(CGPoint)point textRange:(NSRange)textRange
107+
{
108+
// the node tapped a link, open it
109+
[[UIApplication sharedApplication] openURL:URL];
110+
}
111+
112+
@end
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"images" : [
3+
{
4+
"orientation" : "portrait",
5+
"idiom" : "iphone",
6+
"filename" : "Default-568h@2x.png",
7+
"minimum-system-version" : "7.0",
8+
"subtype" : "retina4",
9+
"scale" : "2x"
10+
},
11+
{
12+
"idiom" : "iphone",
13+
"scale" : "1x",
14+
"orientation" : "portrait"
15+
},
16+
{
17+
"idiom" : "iphone",
18+
"scale" : "2x",
19+
"orientation" : "portrait"
20+
},
21+
{
22+
"orientation" : "portrait",
23+
"idiom" : "iphone",
24+
"filename" : "Default-568h@2x.png",
25+
"subtype" : "retina4",
26+
"scale" : "2x"
27+
},
28+
{
29+
"orientation" : "portrait",
30+
"idiom" : "iphone",
31+
"minimum-system-version" : "7.0",
32+
"scale" : "2x"
33+
}
34+
],
35+
"info" : {
36+
"version" : 1,
37+
"author" : "xcode"
38+
}
39+
}

0 commit comments

Comments
 (0)