Skip to content

Commit 78293ad

Browse files
author
Vitaly Baev
committed
Added example of typical social app layout example
1 parent b1784bc commit 78293ad

42 files changed

Lines changed: 1390 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

examples/SocialAppLayout/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 => '../..'

examples/SocialAppLayout/Sample.xcodeproj/project.pbxproj

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

examples/SocialAppLayout/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.

examples/SocialAppLayout/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: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// AppDelegate.h
3+
// Sample
4+
//
5+
// Created by Vitaly Baev on 06.11.15.
6+
// Copyright © 2015 Facebook. All rights reserved.
7+
//
8+
9+
#import <UIKit/UIKit.h>
10+
11+
@interface AppDelegate : UIResponder <UIApplicationDelegate>
12+
13+
@property (strong, nonatomic) UIWindow *window;
14+
15+
16+
@end
17+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//
2+
// AppDelegate.m
3+
// Sample
4+
//
5+
// Created by Vitaly Baev on 06.11.15.
6+
// Copyright © 2015 Facebook. All rights reserved.
7+
//
8+
9+
#import "AppDelegate.h"
10+
11+
#import "ViewController.h"
12+
13+
@interface AppDelegate ()
14+
15+
@end
16+
17+
@implementation AppDelegate
18+
19+
20+
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
21+
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
22+
self.window.backgroundColor = [UIColor whiteColor];
23+
self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:[[ViewController alloc] init]];
24+
[self.window makeKeyAndVisible];
25+
return YES;
26+
27+
}
28+
29+
@end
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "iphone",
5+
"size" : "29x29",
6+
"scale" : "2x"
7+
},
8+
{
9+
"idiom" : "iphone",
10+
"size" : "29x29",
11+
"scale" : "3x"
12+
},
13+
{
14+
"idiom" : "iphone",
15+
"size" : "40x40",
16+
"scale" : "2x"
17+
},
18+
{
19+
"idiom" : "iphone",
20+
"size" : "40x40",
21+
"scale" : "3x"
22+
},
23+
{
24+
"idiom" : "iphone",
25+
"size" : "60x60",
26+
"scale" : "2x"
27+
},
28+
{
29+
"idiom" : "iphone",
30+
"size" : "60x60",
31+
"scale" : "3x"
32+
}
33+
],
34+
"info" : {
35+
"version" : 1,
36+
"author" : "xcode"
37+
}
38+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//
2+
// CommentsNode.h
3+
// Sample
4+
//
5+
// Created by Vitaly Baev on 06.11.15.
6+
// Copyright © 2015 Facebook. All rights reserved.
7+
//
8+
9+
#import <AsyncDisplayKit/AsyncDisplayKit.h>
10+
11+
@interface CommentsNode : ASControlNode {
12+
13+
ASImageNode *_iconNode;
14+
ASTextNode *_countNode;
15+
16+
NSInteger _comentsCount;
17+
18+
}
19+
20+
- (instancetype)initWithCommentsCount:(NSInteger)comentsCount;
21+
22+
@end
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//
2+
// CommentsNode.m
3+
// Sample
4+
//
5+
// Created by Vitaly Baev on 06.11.15.
6+
// Copyright © 2015 Facebook. All rights reserved.
7+
//
8+
9+
#import "CommentsNode.h"
10+
#import "TextStyles.h"
11+
12+
@implementation CommentsNode
13+
14+
- (instancetype)initWithCommentsCount:(NSInteger)comentsCount {
15+
16+
self = [super init];
17+
18+
if(self) {
19+
20+
_comentsCount = comentsCount;
21+
22+
_iconNode = [[ASImageNode alloc] init];
23+
_iconNode.image = [UIImage imageNamed:@"icon_comment.png"];
24+
[self addSubnode:_iconNode];
25+
26+
_countNode = [[ASTextNode alloc] init];
27+
if(_comentsCount > 0) {
28+
29+
_countNode.attributedString = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"%ld", (long)_comentsCount] attributes:[TextStyles cellControlStyle]];
30+
31+
}
32+
33+
[self addSubnode:_countNode];
34+
35+
// make it tappable easily
36+
self.hitTestSlop = UIEdgeInsetsMake(-10, -10, -10, -10);
37+
38+
}
39+
40+
return self;
41+
42+
}
43+
44+
- (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize {
45+
46+
ASStackLayoutSpec *mainStack = [ASStackLayoutSpec stackLayoutSpecWithDirection:ASStackLayoutDirectionHorizontal spacing:6.0 justifyContent:ASStackLayoutJustifyContentStart alignItems:ASStackLayoutAlignItemsCenter children:@[_iconNode, _countNode]];
47+
48+
// set sizeRange to make width fixed to 60
49+
mainStack.sizeRange = ASRelativeSizeRangeMake(ASRelativeSizeMake(
50+
ASRelativeDimensionMakeWithPoints(60.0),
51+
ASRelativeDimensionMakeWithPoints(0.0)
52+
), ASRelativeSizeMake(
53+
ASRelativeDimensionMakeWithPoints(60.0),
54+
ASRelativeDimensionMakeWithPoints(40.0)
55+
));
56+
return [ASStaticLayoutSpec staticLayoutSpecWithChildren:@[mainStack]];
57+
58+
}
59+
60+
61+
@end
17.1 KB
Loading

0 commit comments

Comments
 (0)