Add 'submodules/AsyncDisplayKit/' from commit '02bedc12816e251ad71777f9d2578329b6d2bef6'

git-subtree-dir: submodules/AsyncDisplayKit
git-subtree-mainline: d06f423e0e
git-subtree-split: 02bedc1281
This commit is contained in:
Peter
2019-06-11 18:42:43 +01:00
2160 changed files with 232035 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
//
// AppDelegate.h
// Texture
//
// Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
// Changes after 4/13/2017 are: Copyright (c) Pinterest, Inc. All rights reserved.
// Licensed under Apache 2.0: http://www.apache.org/licenses/LICENSE-2.0
//
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end

View File

@@ -0,0 +1,24 @@
//
// AppDelegate.m
// Texture
//
// Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
// Changes after 4/13/2017 are: Copyright (c) Pinterest, Inc. All rights reserved.
// Licensed under Apache 2.0: http://www.apache.org/licenses/LICENSE-2.0
//
#import "AppDelegate.h"
#import "ViewController.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:[[ViewController alloc] init]];
[self.window makeKeyAndVisible];
return YES;
}
@end

View File

@@ -0,0 +1,38 @@
{
"images" : [
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}

View File

@@ -0,0 +1,16 @@
//
// CommentsNode.h
// Texture
//
// Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
// Changes after 4/13/2017 are: Copyright (c) Pinterest, Inc. All rights reserved.
// Licensed under Apache 2.0: http://www.apache.org/licenses/LICENSE-2.0
//
#import <AsyncDisplayKit/AsyncDisplayKit.h>
@interface CommentsNode : ASControlNode
- (instancetype)initWithCommentsCount:(NSInteger)comentsCount;
@end

View File

@@ -0,0 +1,62 @@
//
// CommentsNode.m
// Texture
//
// Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
// Changes after 4/13/2017 are: Copyright (c) Pinterest, Inc. All rights reserved.
// Licensed under Apache 2.0: http://www.apache.org/licenses/LICENSE-2.0
//
#import "CommentsNode.h"
#import "TextStyles.h"
@interface CommentsNode ()
@property (nonatomic, strong) ASImageNode *iconNode;
@property (nonatomic, strong) ASTextNode *countNode;
@property (nonatomic, assign) NSInteger commentsCount;
@end
@implementation CommentsNode
- (instancetype)initWithCommentsCount:(NSInteger)comentsCount
{
self = [super init];
if (self) {
_commentsCount = comentsCount;
_iconNode = [[ASImageNode alloc] init];
_iconNode.image = [UIImage imageNamed:@"icon_comment.png"];
[self addSubnode:_iconNode];
_countNode = [[ASTextNode alloc] init];
if (_commentsCount > 0) {
_countNode.attributedText = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"%zd", _commentsCount] attributes:[TextStyles cellControlStyle]];
}
[self addSubnode:_countNode];
// make it tappable easily
self.hitTestSlop = UIEdgeInsetsMake(-10, -10, -10, -10);
}
return self;
}
- (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize
{
ASStackLayoutSpec *mainStack =
[ASStackLayoutSpec
stackLayoutSpecWithDirection:ASStackLayoutDirectionHorizontal
spacing:6.0
justifyContent:ASStackLayoutJustifyContentStart
alignItems:ASStackLayoutAlignItemsCenter
children:@[_iconNode, _countNode]];
// Adjust size
mainStack.style.minWidth = ASDimensionMakeWithPoints(60.0);
mainStack.style.maxHeight = ASDimensionMakeWithPoints(40.0);
return mainStack;
}
@end

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

View File

@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>

View File

@@ -0,0 +1,16 @@
//
// LikesNode.h
// Texture
//
// Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
// Changes after 4/13/2017 are: Copyright (c) Pinterest, Inc. All rights reserved.
// Licensed under Apache 2.0: http://www.apache.org/licenses/LICENSE-2.0
//
#import <AsyncDisplayKit/AsyncDisplayKit.h>
@interface LikesNode : ASControlNode
- (instancetype)initWithLikesCount:(NSInteger)likesCount;
@end

View File

@@ -0,0 +1,75 @@
//
// LikesNode.m
// Texture
//
// Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
// Changes after 4/13/2017 are: Copyright (c) Pinterest, Inc. All rights reserved.
// Licensed under Apache 2.0: http://www.apache.org/licenses/LICENSE-2.0
//
#import "LikesNode.h"
#import "TextStyles.h"
@interface LikesNode ()
@property (nonatomic, strong) ASImageNode *iconNode;
@property (nonatomic, strong) ASTextNode *countNode;
@property (nonatomic, assign) NSInteger likesCount;
@property (nonatomic, assign) BOOL liked;
@end
@implementation LikesNode
- (instancetype)initWithLikesCount:(NSInteger)likesCount
{
self = [super init];
if (self) {
_likesCount = likesCount;
_liked = (_likesCount > 0) ? [LikesNode getYesOrNo] : NO;
_iconNode = [[ASImageNode alloc] init];
_iconNode.image = (_liked) ? [UIImage imageNamed:@"icon_liked.png"] : [UIImage imageNamed:@"icon_like.png"];
[self addSubnode:_iconNode];
_countNode = [[ASTextNode alloc] init];
if (_likesCount > 0) {
NSDictionary *attributes = _liked ? [TextStyles cellControlColoredStyle] : [TextStyles cellControlStyle];
_countNode.attributedText = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"%ld", (long)_likesCount] attributes:attributes];
}
[self addSubnode:_countNode];
// make it tappable easily
self.hitTestSlop = UIEdgeInsetsMake(-10, -10, -10, -10);
}
return self;
}
+ (BOOL)getYesOrNo
{
int tmp = (arc4random() % 30)+1;
if (tmp % 5 == 0) {
return YES;
}
return NO;
}
- (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize
{
ASStackLayoutSpec *mainStack =
[ASStackLayoutSpec
stackLayoutSpecWithDirection:ASStackLayoutDirectionHorizontal
spacing:6.0
justifyContent:ASStackLayoutJustifyContentStart
alignItems:ASStackLayoutAlignItemsCenter
children:@[_iconNode, _countNode]];
mainStack.style.minWidth = ASDimensionMakeWithPoints(60.0);
mainStack.style.maxHeight = ASDimensionMakeWithPoints(40.0);
return mainStack;
}
@end

View File

@@ -0,0 +1,25 @@
//
// Post.h
// Texture
//
// Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
// Changes after 4/13/2017 are: Copyright (c) Pinterest, Inc. All rights reserved.
// Licensed under Apache 2.0: http://www.apache.org/licenses/LICENSE-2.0
//
#import <Foundation/Foundation.h>
@interface Post : NSObject
@property (nonatomic, copy) NSString *username;
@property (nonatomic, copy) NSString *name;
@property (nonatomic, copy) NSString *photo;
@property (nonatomic, copy) NSString *post;
@property (nonatomic, copy) NSString *time;
@property (nonatomic, copy) NSString *media;
@property (nonatomic, assign) NSInteger via;
@property (nonatomic, assign) NSInteger likes;
@property (nonatomic, assign) NSInteger comments;
@end

View File

@@ -0,0 +1,13 @@
//
// Post.m
// Texture
//
// Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
// Changes after 4/13/2017 are: Copyright (c) Pinterest, Inc. All rights reserved.
// Licensed under Apache 2.0: http://www.apache.org/licenses/LICENSE-2.0
//
#import "Post.h"
@implementation Post
@end

View File

@@ -0,0 +1,18 @@
//
// PostNode.h
// Texture
//
// Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
// Changes after 4/13/2017 are: Copyright (c) Pinterest, Inc. All rights reserved.
// Licensed under Apache 2.0: http://www.apache.org/licenses/LICENSE-2.0
//
#import <AsyncDisplayKit/AsyncDisplayKit.h>
@class Post;
@interface PostNode : ASCellNode
- (instancetype)initWithPost:(Post *)post;
@end

View File

@@ -0,0 +1,337 @@
//
// PostNode.m
// Texture
//
// Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
// Changes after 4/13/2017 are: Copyright (c) Pinterest, Inc. All rights reserved.
// Licensed under Apache 2.0: http://www.apache.org/licenses/LICENSE-2.0
//
#import "PostNode.h"
#import "Post.h"
#import "TextStyles.h"
#import "LikesNode.h"
#import "CommentsNode.h"
#define PostNodeDividerColor [UIColor lightGrayColor]
@interface PostNode() <ASNetworkImageNodeDelegate, ASTextNodeDelegate>
@property (strong, nonatomic) Post *post;
@property (strong, nonatomic) ASDisplayNode *divider;
@property (strong, nonatomic) ASTextNode *nameNode;
@property (strong, nonatomic) ASTextNode *usernameNode;
@property (strong, nonatomic) ASTextNode *timeNode;
@property (strong, nonatomic) ASTextNode *postNode;
@property (strong, nonatomic) ASImageNode *viaNode;
@property (strong, nonatomic) ASNetworkImageNode *avatarNode;
@property (strong, nonatomic) ASNetworkImageNode *mediaNode;
@property (strong, nonatomic) LikesNode *likesNode;
@property (strong, nonatomic) CommentsNode *commentsNode;
@property (strong, nonatomic) ASImageNode *optionsNode;
@end
@implementation PostNode
#pragma mark - Lifecycle
- (instancetype)initWithPost:(Post *)post
{
self = [super init];
if (self) {
_post = post;
self.selectionStyle = UITableViewCellSelectionStyleNone;
// Name node
_nameNode = [[ASTextNode alloc] init];
_nameNode.attributedText = [[NSAttributedString alloc] initWithString:_post.name attributes:[TextStyles nameStyle]];
_nameNode.maximumNumberOfLines = 1;
[self addSubnode:_nameNode];
// Username node
_usernameNode = [[ASTextNode alloc] init];
_usernameNode.attributedText = [[NSAttributedString alloc] initWithString:_post.username attributes:[TextStyles usernameStyle]];
_usernameNode.style.flexShrink = 1.0; //if name and username don't fit to cell width, allow username shrink
_usernameNode.truncationMode = NSLineBreakByTruncatingTail;
_usernameNode.maximumNumberOfLines = 1;
[self addSubnode:_usernameNode];
// Time node
_timeNode = [[ASTextNode alloc] init];
_timeNode.attributedText = [[NSAttributedString alloc] initWithString:_post.time attributes:[TextStyles timeStyle]];
[self addSubnode:_timeNode];
// Post node
_postNode = [[ASTextNode alloc] init];
// Processing URLs in post
NSString *kLinkAttributeName = @"TextLinkAttributeName";
if (![_post.post isEqualToString:@""]) {
NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:_post.post attributes:[TextStyles postStyle]];
NSDataDetector *urlDetector = [NSDataDetector dataDetectorWithTypes:NSTextCheckingTypeLink error:nil];
[urlDetector enumerateMatchesInString:attrString.string options:kNilOptions range:NSMakeRange(0, attrString.string.length) usingBlock:^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop){
if (result.resultType == NSTextCheckingTypeLink) {
NSMutableDictionary *linkAttributes = [[NSMutableDictionary alloc] initWithDictionary:[TextStyles postLinkStyle]];
linkAttributes[kLinkAttributeName] = [NSURL URLWithString:result.URL.absoluteString];
[attrString addAttributes:linkAttributes range:result.range];
}
}];
// Configure node to support tappable links
_postNode.delegate = self;
_postNode.userInteractionEnabled = YES;
_postNode.linkAttributeNames = @[ kLinkAttributeName ];
_postNode.attributedText = attrString;
_postNode.passthroughNonlinkTouches = YES; // passes touches through when they aren't on a link
}
[self addSubnode:_postNode];
// Media
if (![_post.media isEqualToString:@""]) {
_mediaNode = [[ASNetworkImageNode alloc] init];
_mediaNode.backgroundColor = ASDisplayNodeDefaultPlaceholderColor();
_mediaNode.cornerRadius = 4.0;
_mediaNode.URL = [NSURL URLWithString:_post.media];
_mediaNode.delegate = self;
_mediaNode.imageModificationBlock = ^UIImage *(UIImage *image) {
UIImage *modifiedImage;
CGRect rect = CGRectMake(0, 0, image.size.width, image.size.height);
UIGraphicsBeginImageContextWithOptions(image.size, false, [[UIScreen mainScreen] scale]);
[[UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:8.0] addClip];
[image drawInRect:rect];
modifiedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return modifiedImage;
};
[self addSubnode:_mediaNode];
}
// User pic
_avatarNode = [[ASNetworkImageNode alloc] init];
_avatarNode.backgroundColor = ASDisplayNodeDefaultPlaceholderColor();
_avatarNode.style.width = ASDimensionMakeWithPoints(44);
_avatarNode.style.height = ASDimensionMakeWithPoints(44);
_avatarNode.cornerRadius = 22.0;
_avatarNode.URL = [NSURL URLWithString:_post.photo];
_avatarNode.imageModificationBlock = ^UIImage *(UIImage *image) {
UIImage *modifiedImage;
CGRect rect = CGRectMake(0, 0, image.size.width, image.size.height);
UIGraphicsBeginImageContextWithOptions(image.size, false, [[UIScreen mainScreen] scale]);
[[UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:44.0] addClip];
[image drawInRect:rect];
modifiedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return modifiedImage;
};
[self addSubnode:_avatarNode];
// Hairline cell separator
_divider = [[ASDisplayNode alloc] init];
[self updateDividerColor];
[self addSubnode:_divider];
// Via
if (_post.via != 0) {
_viaNode = [[ASImageNode alloc] init];
_viaNode.image = (_post.via == 1) ? [UIImage imageNamed:@"icon_ios.png"] : [UIImage imageNamed:@"icon_android.png"];
[self addSubnode:_viaNode];
}
// Bottom controls
_likesNode = [[LikesNode alloc] initWithLikesCount:_post.likes];
[self addSubnode:_likesNode];
_commentsNode = [[CommentsNode alloc] initWithCommentsCount:_post.comments];
[self addSubnode:_commentsNode];
_optionsNode = [[ASImageNode alloc] init];
_optionsNode.image = [UIImage imageNamed:@"icon_more"];
[self addSubnode:_optionsNode];
for (ASDisplayNode *node in self.subnodes) {
// ASTextNode with embedded links doesn't support layer backing
if (node.supportsLayerBacking) {
node.layerBacked = YES;
}
}
}
return self;
}
- (void)updateDividerColor
{
/*
* UITableViewCell traverses through all its descendant views and adjusts their background color accordingly
* either to [UIColor clearColor], although potentially it could use the same color as the selection highlight itself.
* After selection, the same trick is performed again in reverse, putting all the backgrounds back as they used to be.
* But in our case, we don't want to have the background color disappearing so we reset it after highlighting or
* selection is done.
*/
_divider.backgroundColor = PostNodeDividerColor;
}
#pragma mark - ASDisplayNode
- (void)didLoad
{
// enable highlighting now that self.layer has loaded -- see ASHighlightOverlayLayer.h
self.layer.as_allowsHighlightDrawing = YES;
[super didLoad];
}
- (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize
{
// Flexible spacer between username and time
ASLayoutSpec *spacer = [[ASLayoutSpec alloc] init];
spacer.style.flexGrow = 1.0;
// Horizontal stack for name, username, via icon and time
NSMutableArray *layoutSpecChildren = [@[_nameNode, _usernameNode, spacer] mutableCopy];
if (_post.via != 0) {
[layoutSpecChildren addObject:_viaNode];
}
[layoutSpecChildren addObject:_timeNode];
ASStackLayoutSpec *nameStack =
[ASStackLayoutSpec
stackLayoutSpecWithDirection:ASStackLayoutDirectionHorizontal
spacing:5.0
justifyContent:ASStackLayoutJustifyContentStart
alignItems:ASStackLayoutAlignItemsCenter
children:layoutSpecChildren];
nameStack.style.alignSelf = ASStackLayoutAlignSelfStretch;
// bottom controls horizontal stack
ASStackLayoutSpec *controlsStack =
[ASStackLayoutSpec
stackLayoutSpecWithDirection:ASStackLayoutDirectionHorizontal
spacing:10
justifyContent:ASStackLayoutJustifyContentStart
alignItems:ASStackLayoutAlignItemsCenter
children:@[_likesNode, _commentsNode, _optionsNode]];
// Add more gaps for control line
controlsStack.style.spacingAfter = 3.0;
controlsStack.style.spacingBefore = 3.0;
NSMutableArray *mainStackContent = [[NSMutableArray alloc] init];
[mainStackContent addObject:nameStack];
[mainStackContent addObject:_postNode];
if (![_post.media isEqualToString:@""]){
// Only add the media node if an image is present
if (_mediaNode.image != nil) {
ASRatioLayoutSpec *imagePlace =
[ASRatioLayoutSpec
ratioLayoutSpecWithRatio:0.5
child:_mediaNode];
imagePlace.style.spacingAfter = 3.0;
imagePlace.style.spacingBefore = 3.0;
[mainStackContent addObject:imagePlace];
}
}
[mainStackContent addObject:controlsStack];
// Vertical spec of cell main content
ASStackLayoutSpec *contentSpec =
[ASStackLayoutSpec
stackLayoutSpecWithDirection:ASStackLayoutDirectionVertical
spacing:8.0
justifyContent:ASStackLayoutJustifyContentStart
alignItems:ASStackLayoutAlignItemsStretch
children:mainStackContent];
contentSpec.style.flexShrink = 1.0;
// Horizontal spec for avatar
ASStackLayoutSpec *avatarContentSpec =
[ASStackLayoutSpec
stackLayoutSpecWithDirection:ASStackLayoutDirectionHorizontal
spacing:8.0
justifyContent:ASStackLayoutJustifyContentStart
alignItems:ASStackLayoutAlignItemsStart
children:@[_avatarNode, contentSpec]];
return [ASInsetLayoutSpec
insetLayoutSpecWithInsets:UIEdgeInsetsMake(10, 10, 10, 10)
child:avatarContentSpec];
}
- (void)layout
{
[super layout];
// Manually layout the divider.
CGFloat pixelHeight = 1.0f / [[UIScreen mainScreen] scale];
_divider.frame = CGRectMake(0.0f, 0.0f, self.calculatedSize.width, pixelHeight);
}
#pragma mark - ASCellNode
- (void)setHighlighted:(BOOL)highlighted
{
[super setHighlighted:highlighted];
[self updateDividerColor];
}
- (void)setSelected:(BOOL)selected
{
[super setSelected:selected];
[self updateDividerColor];
}
#pragma mark - <ASTextNodeDelegate>
- (BOOL)textNode:(ASTextNode *)richTextNode shouldHighlightLinkAttribute:(NSString *)attribute value:(id)value atPoint:(CGPoint)point
{
// Opt into link highlighting -- tap and hold the link to try it! must enable highlighting on a layer, see -didLoad
return YES;
}
- (void)textNode:(ASTextNode *)richTextNode tappedLinkAttribute:(NSString *)attribute value:(NSURL *)URL atPoint:(CGPoint)point textRange:(NSRange)textRange
{
// The node tapped a link, open it
[[UIApplication sharedApplication] openURL:URL];
}
#pragma mark - ASNetworkImageNodeDelegate methods.
- (void)imageNode:(ASNetworkImageNode *)imageNode didLoadImage:(UIImage *)image
{
[self setNeedsLayout];
}
@end

View File

@@ -0,0 +1,23 @@
//
// TextStyles.h
// Texture
//
// Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
// Changes after 4/13/2017 are: Copyright (c) Pinterest, Inc. All rights reserved.
// Licensed under Apache 2.0: http://www.apache.org/licenses/LICENSE-2.0
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface TextStyles : NSObject
+ (NSDictionary *)nameStyle;
+ (NSDictionary *)usernameStyle;
+ (NSDictionary *)timeStyle;
+ (NSDictionary *)postStyle;
+ (NSDictionary *)postLinkStyle;
+ (NSDictionary *)cellControlStyle;
+ (NSDictionary *)cellControlColoredStyle;
@end

View File

@@ -0,0 +1,71 @@
//
// TextStyles.m
// Texture
//
// Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
// Changes after 4/13/2017 are: Copyright (c) Pinterest, Inc. All rights reserved.
// Licensed under Apache 2.0: http://www.apache.org/licenses/LICENSE-2.0
//
#import "TextStyles.h"
@implementation TextStyles
+ (NSDictionary *)nameStyle
{
return @{
NSFontAttributeName : [UIFont boldSystemFontOfSize:15.0],
NSForegroundColorAttributeName: [UIColor blackColor]
};
}
+ (NSDictionary *)usernameStyle
{
return @{
NSFontAttributeName : [UIFont systemFontOfSize:13.0],
NSForegroundColorAttributeName: [UIColor lightGrayColor]
};
}
+ (NSDictionary *)timeStyle
{
return @{
NSFontAttributeName : [UIFont systemFontOfSize:13.0],
NSForegroundColorAttributeName: [UIColor grayColor]
};
}
+ (NSDictionary *)postStyle
{
return @{
NSFontAttributeName : [UIFont systemFontOfSize:15.0],
NSForegroundColorAttributeName: [UIColor blackColor]
};
}
+ (NSDictionary *)postLinkStyle
{
return @{
NSFontAttributeName : [UIFont systemFontOfSize:15.0],
NSForegroundColorAttributeName: [UIColor colorWithRed:59.0/255.0 green:89.0/255.0 blue:152.0/255.0 alpha:1.0],
NSUnderlineStyleAttributeName: @(NSUnderlineStyleSingle)
};
}
+ (NSDictionary *)cellControlStyle
{
return @{
NSFontAttributeName : [UIFont systemFontOfSize:13.0],
NSForegroundColorAttributeName: [UIColor lightGrayColor]
};
}
+ (NSDictionary *)cellControlColoredStyle
{
return @{
NSFontAttributeName : [UIFont systemFontOfSize:13.0],
NSForegroundColorAttributeName: [UIColor colorWithRed:59.0/255.0 green:89.0/255.0 blue:152.0/255.0 alpha:1.0]
};
}
@end

View File

@@ -0,0 +1,13 @@
//
// ViewController.h
// Texture
//
// Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
// Changes after 4/13/2017 are: Copyright (c) Pinterest, Inc. All rights reserved.
// Licensed under Apache 2.0: http://www.apache.org/licenses/LICENSE-2.0
//
#import <AsyncDisplayKit/AsyncDisplayKit.h>
@interface ViewController : ASViewController
@end

View File

@@ -0,0 +1,144 @@
//
// ViewController.m
// Texture
//
// Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
// Changes after 4/13/2017 are: Copyright (c) Pinterest, Inc. All rights reserved.
// Licensed under Apache 2.0: http://www.apache.org/licenses/LICENSE-2.0
//
#import "ViewController.h"
#import "Post.h"
#import "PostNode.h"
#import <AsyncDisplayKit/AsyncDisplayKit.h>
#import <AsyncDisplayKit/ASAssert.h>
#include <stdlib.h>
@interface ViewController () <ASTableDataSource, ASTableDelegate>
@property (nonatomic, strong) ASTableNode *tableNode;
@property (nonatomic, strong) NSMutableArray *socialAppDataSource;
@end
#pragma mark - Lifecycle
@implementation ViewController
- (instancetype)init
{
_tableNode = [[ASTableNode alloc] initWithStyle:UITableViewStylePlain];
_tableNode.inverted = YES;
self = [super initWithNode:_tableNode];
if (self) {
_tableNode.delegate = self;
_tableNode.dataSource = self;
self.title = @"Timeline";
[self createSocialAppDataSource];
}
return self;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
CGFloat inset = [self topBarsHeight];
self.tableNode.view.contentInset = UIEdgeInsetsMake(-inset, 0, inset, 0);
self.tableNode.view.scrollIndicatorInsets = UIEdgeInsetsMake(-inset, 0, inset, 0);
}
- (void)viewDidLoad
{
[super viewDidLoad];
// SocialAppNode has its own separator
self.tableNode.view.separatorStyle = UITableViewCellSeparatorStyleNone;
}
- (CGFloat)topBarsHeight
{
// No need to adjust if the edge isn't available
if ((self.edgesForExtendedLayout & UIRectEdgeTop) == 0) {
return 0.0;
}
return CGRectGetHeight(self.navigationController.navigationBar.frame) + CGRectGetHeight([UIApplication sharedApplication].statusBarFrame);
}
#pragma mark - Data Model
- (void)createSocialAppDataSource
{
_socialAppDataSource = [[NSMutableArray alloc] init];
Post *newPost = [[Post alloc] init];
newPost.name = @"Apple Guy";
newPost.username = @"@appleguy";
newPost.photo = @"https://avatars1.githubusercontent.com/u/565251?v=3&s=96";
newPost.post = @"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.";
newPost.time = @"3s";
newPost.media = @"";
newPost.via = 0;
newPost.likes = arc4random_uniform(74);
newPost.comments = arc4random_uniform(40);
[_socialAppDataSource addObject:newPost];
newPost = [[Post alloc] init];
newPost.name = @"Huy Nguyen";
newPost.username = @"@nguyenhuy";
newPost.photo = @"https://avatars2.githubusercontent.com/u/587874?v=3&s=96";
newPost.post = @"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.";
newPost.time = @"1m";
newPost.media = @"";
newPost.via = 1;
newPost.likes = arc4random_uniform(74);
newPost.comments = arc4random_uniform(40);
[_socialAppDataSource addObject:newPost];
newPost = [[Post alloc] init];
newPost.name = @"Alex Long Name";
newPost.username = @"@veryyyylongusername";
newPost.photo = @"https://avatars1.githubusercontent.com/u/8086633?v=3&s=96";
newPost.post = @"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.";
newPost.time = @"3:02";
newPost.media = @"http://www.ngmag.ru/upload/iblock/f93/f9390efc34151456598077c1ba44a94d.jpg";
newPost.via = 2;
newPost.likes = arc4random_uniform(74);
newPost.comments = arc4random_uniform(40);
[_socialAppDataSource addObject:newPost];
newPost = [[Post alloc] init];
newPost.name = @"Vitaly Baev";
newPost.username = @"@vitalybaev";
newPost.photo = @"https://avatars0.githubusercontent.com/u/724423?v=3&s=96";
newPost.post = @"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. https://github.com/facebook/AsyncDisplayKit Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.";
newPost.time = @"yesterday";
newPost.media = @"";
newPost.via = 1;
newPost.likes = arc4random_uniform(74);
newPost.comments = arc4random_uniform(40);
[_socialAppDataSource addObject:newPost];
}
#pragma mark - ASTableNode
- (ASCellNodeBlock)tableNode:(ASTableNode *)tableNode nodeBlockForRowAtIndexPath:(NSIndexPath *)indexPath
{
Post *post = self.socialAppDataSource[indexPath.row];
return ^{
return [[PostNode alloc] initWithPost:post];
};
}
- (NSInteger)tableNode:(ASTableNode *)tableNode numberOfRowsInSection:(NSInteger)section
{
return self.socialAppDataSource.count;
}
@end

Binary file not shown.

After

Width:  |  Height:  |  Size: 387 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 733 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 262 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 358 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 490 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 340 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 706 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 348 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 728 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 400 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 781 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 205 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 418 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 594 B

View File

@@ -0,0 +1,17 @@
//
// main.m
// Texture
//
// Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
// Changes after 4/13/2017 are: Copyright (c) Pinterest, Inc. All rights reserved.
// Licensed under Apache 2.0: http://www.apache.org/licenses/LICENSE-2.0
//
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
int main(int argc, char * argv[]) {
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}