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,18 @@
//
// 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,28 @@
//
// 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"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:[ViewController new]];
[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,27 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9532" systemVersion="15D21" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" initialViewController="01J-lp-oVM">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9530"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="EHf-IW-A2E">
<objects>
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="Llm-lL-Icb"/>
<viewControllerLayoutGuide type="bottom" id="xb3-aO-Qok"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="53" y="375"/>
</scene>
</scenes>
</document>

View File

@@ -0,0 +1,18 @@
//
// DetailCellNode.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/ASCellNode.h>
@class ASNetworkImageNode;
@interface DetailCellNode : ASCellNode
@property (nonatomic, assign) NSInteger row;
@property (nonatomic, copy) NSString *imageCategory;
@property (nonatomic, strong) ASNetworkImageNode *imageNode;
@end

View File

@@ -0,0 +1,57 @@
//
// DetailCellNode.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 "DetailCellNode.h"
#import <AsyncDisplayKit/AsyncDisplayKit.h>
@implementation DetailCellNode
#pragma mark - Lifecycle
- (instancetype)init
{
self = [super init];
if (self == nil) { return self; }
self.automaticallyManagesSubnodes = YES;
_imageNode = [[ASNetworkImageNode alloc] init];
_imageNode.backgroundColor = ASDisplayNodeDefaultPlaceholderColor();
return self;
}
#pragma mark - ASDisplayNode
- (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize
{
return [ASRatioLayoutSpec ratioLayoutSpecWithRatio:1.0 child:self.imageNode];
}
- (void)layoutDidFinish
{
[super layoutDidFinish];
// In general set URL of ASNetworkImageNode as soon as possible. Ideally in init or a
// view model setter method.
// In this case as we need to know the size of the node the url is set in layoutDidFinish so
// we have the calculatedSize available
self.imageNode.URL = [self imageURL];
}
#pragma mark - Image
- (NSURL *)imageURL
{
CGSize imageSize = self.calculatedSize;
NSString *imageURLString = [NSString stringWithFormat:@"http://lorempixel.com/%ld/%ld/%@/%ld", (NSInteger)imageSize.width, (NSInteger)imageSize.height, self.imageCategory, self.row];
return [NSURL URLWithString:imageURLString];
}
@end

View File

@@ -0,0 +1,20 @@
//
// DetailRootNode.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/ASDisplayNode.h>
@class ASCollectionNode;
@interface DetailRootNode : ASDisplayNode
@property (nonatomic, strong, readonly) ASCollectionNode *collectionNode;
- (instancetype)initWithImageCategory:(NSString *)imageCategory;
@end

View File

@@ -0,0 +1,88 @@
//
// DetailRootNode.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 "DetailRootNode.h"
#import "DetailCellNode.h"
#import <AsyncDisplayKit/AsyncDisplayKit.h>
static const NSInteger kImageHeight = 200;
@interface DetailRootNode () <ASCollectionDataSource, ASCollectionDelegate>
@property (nonatomic, copy) NSString *imageCategory;
@property (nonatomic, strong) ASCollectionNode *collectionNode;
@end
@implementation DetailRootNode
#pragma mark - Lifecycle
- (instancetype)initWithImageCategory:(NSString *)imageCategory
{
self = [super init];
if (self) {
// Enable automaticallyManagesSubnodes so the first time the layout pass of the node is happening all nodes that are referenced
// in the laaout specification within layoutSpecThatFits: will be added automatically
self.automaticallyManagesSubnodes = YES;
_imageCategory = imageCategory;
// Create ASCollectionView. We don't have to add it explicitly as subnode as we will set usesImplicitHierarchyManagement to YES
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
_collectionNode = [[ASCollectionNode alloc] initWithCollectionViewLayout:layout];
_collectionNode.delegate = self;
_collectionNode.dataSource = self;
_collectionNode.backgroundColor = [UIColor whiteColor];
}
return self;
}
- (void)dealloc
{
_collectionNode.delegate = nil;
_collectionNode.dataSource = nil;
}
#pragma mark - ASDisplayNode
- (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize
{
return [ASWrapperLayoutSpec wrapperWithLayoutElement:self.collectionNode];
}
#pragma mark - ASCollectionDataSource
- (NSInteger)collectionNode:(ASCollectionNode *)collectionNode numberOfItemsInSection:(NSInteger)section
{
return 10;
}
- (ASCellNodeBlock)collectionNode:(ASCollectionNode *)collectionNode nodeBlockForItemAtIndexPath:(NSIndexPath *)indexPath
{
NSString *imageCategory = self.imageCategory;
return ^{
DetailCellNode *node = [[DetailCellNode alloc] init];
node.row = indexPath.row;
node.imageCategory = imageCategory;
return node;
};
}
- (ASSizeRange)collectionNode:(ASCollectionNode *)collectionNode constrainedSizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
CGSize imageSize = CGSizeMake(CGRectGetWidth(collectionNode.view.frame), kImageHeight);
return ASSizeRangeMake(imageSize, imageSize);
}
@end

View File

@@ -0,0 +1,15 @@
//
// DetailViewController.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/ASViewController.h>
#import "DetailRootNode.h"
@interface DetailViewController : ASViewController<DetailRootNode *>
@end

View File

@@ -0,0 +1,26 @@
//
// DetailViewController.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 "DetailViewController.h"
#import <AsyncDisplayKit/AsyncDisplayKit.h>
#import "DetailRootNode.h"
@implementation DetailViewController
#pragma mark - Rotation
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
{
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
[self.node.collectionNode.view.collectionViewLayout invalidateLayout];
}
@end

View File

@@ -0,0 +1,43 @@
<?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>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<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,17 @@
//
// 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/ASViewController.h>
#import <AsyncDisplayKit/ASTableNode.h>
@interface ViewController : ASViewController<ASTableNode *>
@end

View File

@@ -0,0 +1,92 @@
//
// 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 <AsyncDisplayKit/AsyncDisplayKit.h>
#import "DetailViewController.h"
@interface ViewController () <ASTableDataSource, ASTableDelegate>
@property (nonatomic, copy) NSArray *imageCategories;
@property (nonatomic, strong, readonly) ASTableNode *tableNode;
@end
@implementation ViewController
#pragma mark - Lifecycle
- (instancetype)init
{
self = [super initWithNode:[ASTableNode new]];
if (self == nil) { return self; }
_imageCategories = @[@"abstract", @"animals", @"business", @"cats", @"city", @"food", @"nightlife", @"fashion", @"people", @"nature", @"sports", @"technics", @"transport"];
return self;
}
- (void)dealloc
{
self.node.delegate = nil;
self.node.dataSource = nil;
}
#pragma mark - UIViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = @"Image Categories";
self.node.delegate = self;
self.node.dataSource = self;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.node deselectRowAtIndexPath:self.node.indexPathForSelectedRow animated:YES];
}
#pragma mark - ASTableDataSource / ASTableDelegate
- (NSInteger)tableNode:(ASTableNode *)tableNode numberOfRowsInSection:(NSInteger)section
{
return self.imageCategories.count;
}
- (ASCellNodeBlock)tableNode:(ASTableNode *)tableNode nodeBlockForRowAtIndexPath:(NSIndexPath *)indexPath
{
// As the block is executed on a background thread we need to cache the image category string outside
NSString *imageCategory = self.imageCategories[indexPath.row];
return ^{
ASTextCellNode *textCellNode = [ASTextCellNode new];
textCellNode.text = [imageCategory capitalizedString];
return textCellNode;
};
}
- (void)tableNode:(ASTableNode *)tableNode didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *imageCategory = self.imageCategories[indexPath.row];
DetailRootNode *detailRootNode = [[DetailRootNode alloc] initWithImageCategory:imageCategory];
DetailViewController *detailViewController = [[DetailViewController alloc] initWithNode:detailRootNode];
detailViewController.title = [imageCategory capitalizedString];
[self.navigationController pushViewController:detailViewController animated:YES];
}
@end

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]));
}
}