sample layout examples

This commit is contained in:
Hannah Trosi
2016-07-09 12:27:22 -07:00
parent 28f497cd7c
commit 5d41c0a141
6 changed files with 187 additions and 16 deletions

View File

@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="8150" systemVersion="15A204g" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" initialViewController="01J-lp-oVM">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10117" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" initialViewController="01J-lp-oVM">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8122"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
</dependencies>
<scenes>
<!--View Controller-->
@@ -15,7 +16,6 @@
<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"/>
<animations/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
</view>
</viewController>

View File

@@ -0,0 +1,23 @@
//
// LayoutExamplesViewController.h
// Sample
//
// Created by Hannah Troisi on 7/7/16.
//
// Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree. An additional grant
// of patent rights can be found in the PATENTS file in the same directory.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#import <AsyncDisplayKit/AsyncDisplayKit.h>
@interface LayoutExamplesViewController : ASViewController
@end

View File

@@ -0,0 +1,114 @@
//
// LayoutExamplesViewController.m
// Sample
//
// Created by Hannah Troisi on 7/7/16.
//
// Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree. An additional grant
// of patent rights can be found in the PATENTS file in the same directory.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#import "LayoutExamplesViewController.h"
@interface LayoutExamplesViewController () <ASCollectionDataSource, ASCollectionDelegate>
@end
@implementation LayoutExamplesViewController
{
ASCollectionNode *_collectionNode;
}
#pragma mark - Lifecycle
- (instancetype)init
{
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
_collectionNode = [[ASCollectionNode alloc] initWithCollectionViewLayout:flowLayout];
self = [super initWithNode:_collectionNode];
if (self == nil) { return self; }
_collectionNode.dataSource = self;
_collectionNode.delegate = self;
return self;
}
#pragma mark - ASCollectionDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return 1;
}
//- (ASSizeRange)collectionView:(ASCollectionView *)collectionView constrainedSizeForNodeAtIndexPath:(NSIndexPath *)indexPath
//{
//}
- (ASCellNodeBlock)collectionView:(ASCollectionView *)collectionView nodeBlockForItemAtIndexPath:(NSIndexPath *)indexPath
{
return ^{
ASCellNode *cellNode = [[ASCellNode alloc] init];
cellNode.backgroundColor = [UIColor lightGrayColor];
ASTextNode *textNodeOne = [[ASTextNode alloc] init];
textNodeOne.attributedText = [[NSAttributedString alloc] initWithString:@"firstname lastname"];
ASTextNode *textNodeTwo = [[ASTextNode alloc] init];
textNodeTwo.attributedText = [[NSAttributedString alloc] initWithString:@"This is a longer text string."];
ASTextNode *textNodeThree = [[ASTextNode alloc] init];
textNodeThree.attributedText = [[NSAttributedString alloc] initWithString:@"2d"];
ASNetworkImageNode *imageNode = [[ASNetworkImageNode alloc] init];
imageNode.URL = [NSURL URLWithString:@"https://avatars0.githubusercontent.com/u/565251?v=3&s=400"];
ASLayoutSpecBlock layoutSpecBlock = nil;
// Picture with text overlay
if (indexPath.row == 0) {
[cellNode addSubnode:textNodeOne];
[cellNode addSubnode:textNodeTwo];
[cellNode addSubnode:textNodeThree];
[cellNode addSubnode:imageNode];
imageNode.preferredFrameSize = CGSizeMake(50, 50);
imageNode.cornerRadius = 25;
layoutSpecBlock = ^ASLayoutSpec *(ASDisplayNode * _Nonnull node, ASSizeRange constrainedSize) {
ASStackLayoutSpec *verticalStack = [ASStackLayoutSpec verticalStackLayoutSpec];
verticalStack.children = @[textNodeOne, textNodeTwo];
ASLayoutSpec *spacer = [[ASLayoutSpec alloc] init];
spacer.f
spacer.flexGrow = YES;
ASStackLayoutSpec *horizontalStack = [ASStackLayoutSpec horizontalStackLayoutSpec];
horizontalStack.children = @[imageNode, verticalStack, spacer, textNodeThree];
UIEdgeInsets insets = UIEdgeInsetsMake(10, 10, 10, 10);
ASInsetLayoutSpec *insetSpec = [ASInsetLayoutSpec insetLayoutSpecWithInsets:insets child:horizontalStack];
return insetSpec;
};
} else if (indexPath.row == 1) {
}
cellNode.layoutSpecBlock = layoutSpecBlock;
return cellNode;
};
}
@end

View File

@@ -24,6 +24,8 @@
#import "OverviewASTableNode.h"
#import "OverviewASPagerNode.h"
#import "LayoutExamplesViewController.h"
#import <AsyncDisplayKit/AsyncDisplayKit.h>
@@ -439,7 +441,16 @@ typedef ASLayoutSpec *(^OverviewDisplayNodeSizeThatFitsBlock)(ASSizeRange constr
[parentNode addSubnode:childNode2];
[parentNode addSubnode:childNode3];
[mutableLayoutSpecData addObject:parentNode];
// Layout Specs
// ---------------------------------------------------------------------------------------------------------
NSMutableArray *mutableLayoutExamplesData = [NSMutableArray array];
#pragma mark Layout Examples
parentNode = [self parentNodeWithChild:nil];
parentNode.entryTitle = @"Layout Examples";
parentNode.entryDescription = @"layoutSpec building block examples that can be used in your app.";
[mutableLayoutExamplesData addObject:parentNode];
// Setup Data
// ---------------------------------------------------------------------------------------------------------
@@ -447,6 +458,8 @@ typedef ASLayoutSpec *(^OverviewDisplayNodeSizeThatFitsBlock)(ASSizeRange constr
[mutableData addObject:@{@"title" : @"Node Containers", @"data" : mutableNodesContainerData}];
[mutableData addObject:@{@"title" : @"Nodes", @"data" : mutableNodesData}];
[mutableData addObject:@{@"title" : @"Layout Specs", @"data" : [mutableLayoutSpecData copy]}];
[mutableData addObject:@{@"title" : @"Layout Examples", @"data" : [mutableLayoutExamplesData copy]}];
self.data = mutableData;
}
@@ -542,9 +555,14 @@ typedef ASLayoutSpec *(^OverviewDisplayNodeSizeThatFitsBlock)(ASSizeRange constr
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
ASDisplayNode *node = self.data[indexPath.section][@"data"][indexPath.row];
OverviewDetailViewController *detail = [[OverviewDetailViewController alloc] initWithNode:node];
[self.navigationController pushViewController:detail animated:YES];
if (indexPath.section == 3) {
LayoutExamplesViewController *exampleVC = [[LayoutExamplesViewController alloc] init];
[self.navigationController pushViewController:exampleVC animated:YES];
} else {
ASDisplayNode *node = self.data[indexPath.section][@"data"][indexPath.row];
OverviewDetailViewController *detail = [[OverviewDetailViewController alloc] initWithNode:node];
[self.navigationController pushViewController:detail animated:YES];
}
}
@end