Revert the giant layout diff

This commit is contained in:
Adlai Holler
2016-09-14 11:03:21 -07:00
parent 025af5d594
commit a4b6942f00
109 changed files with 1322 additions and 2087 deletions

View File

@@ -45,10 +45,8 @@
- (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize
{
// 100% of container
_node.width = ASDimensionMakeWithFraction(1.0);
_node.height = ASDimensionMakeWithFraction(1.0);
return [ASWrapperLayoutSpec wrapperWithLayoutable:_node];
self.node.sizeRange = ASRelativeSizeRangeMakeWithExactCGSize(constrainedSize.max);
return [ASStaticLayoutSpec staticLayoutSpecWithChildren:@[self.node]];
}
#pragma mark - <ASCollectionDataSource, ASCollectionDelegate>

View File

@@ -37,7 +37,9 @@ static UIColor *OverViewASPagerNodeRandomColor() {
- (ASLayout *)calculateLayoutThatFits:(ASSizeRange)constrainedSize
{
return [ASLayout layoutWithLayoutable:self size:constrainedSize.max];
return [ASLayout layoutWithLayoutableObject:self
constrainedSizeRange:constrainedSize
size:constrainedSize.max];
}
@end
@@ -67,10 +69,8 @@ static UIColor *OverViewASPagerNodeRandomColor() {
- (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize
{
// 100% of container
_node.width = ASDimensionMakeWithFraction(1.0);
_node.height = ASDimensionMakeWithFraction(1.0);
return [ASWrapperLayoutSpec wrapperWithLayoutable:_node];
_node.sizeRange = ASRelativeSizeRangeMakeWithExactCGSize(constrainedSize.max);
return [ASStaticLayoutSpec staticLayoutSpecWithChildren:@[_node]];
}
- (NSInteger)numberOfPagesInPagerNode:(ASPagerNode *)pagerNode

View File

@@ -42,10 +42,8 @@
- (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize
{
// 100% of container
_node.width = ASDimensionMakeWithFraction(1.0);
_node.height = ASDimensionMakeWithFraction(1.0);
return [ASWrapperLayoutSpec wrapperWithLayoutable:_node];
_node.sizeRange = ASRelativeSizeRangeMakeWithExactCGSize(constrainedSize.max);
return [ASStaticLayoutSpec staticLayoutSpecWithChildren:@[_node]];
}

View File

@@ -82,7 +82,6 @@ typedef ASLayoutSpec *(^OverviewDisplayNodeSizeThatFitsBlock)(ASSizeRange constr
BOOL hasDescription = self.descriptionNode.attributedText.length > 0;
ASStackLayoutSpec *verticalStackLayoutSpec = [ASStackLayoutSpec verticalStackLayoutSpec];
verticalStackLayoutSpec.alignItems = ASStackLayoutAlignItemsStart;
verticalStackLayoutSpec.spacing = 5.0;
verticalStackLayoutSpec.children = hasDescription ? @[self.titleNode, self.descriptionNode] : @[self.titleNode];
@@ -204,11 +203,8 @@ typedef ASLayoutSpec *(^OverviewDisplayNodeSizeThatFitsBlock)(ASSizeRange constr
#pragma mark ASImageNode
ASImageNode *imageNode = [ASImageNode new];
imageNode.image = [UIImage imageNamed:@"image.jpg"];
CGSize imageNetworkImageNodeSize = (CGSize){imageNode.image.size.width / 7, imageNode.image.size.height / 7};
[imageNode setSizeWithCGSize:imageNetworkImageNodeSize];
imageNode.image = [UIImage imageNamed:@"image"];
imageNode.preferredFrameSize = CGSizeMake(imageNode.image.size.width / 7, imageNode.image.size.height / 7);
parentNode = [self centeringParentNodeWithChild:imageNode];
parentNode.entryTitle = @"ASImageNode";
@@ -218,7 +214,7 @@ typedef ASLayoutSpec *(^OverviewDisplayNodeSizeThatFitsBlock)(ASSizeRange constr
#pragma mark ASNetworkImageNode
ASNetworkImageNode *networkImageNode = [ASNetworkImageNode new];
networkImageNode.URL = [NSURL URLWithString:@"http://i.imgur.com/FjOR9kX.jpg"];
[networkImageNode setSizeWithCGSize:imageNetworkImageNodeSize];
networkImageNode.preferredFrameSize = CGSizeMake(imageNode.image.size.width / 7, imageNode.image.size.height / 7);
parentNode = [self centeringParentNodeWithChild:networkImageNode];
parentNode.entryTitle = @"ASNetworkImageNode";
@@ -227,7 +223,7 @@ typedef ASLayoutSpec *(^OverviewDisplayNodeSizeThatFitsBlock)(ASSizeRange constr
#pragma mark ASMapNode
ASMapNode *mapNode = [ASMapNode new];
[mapNode setSizeWithCGSize:(CGSize){300.0, 300.0}];
mapNode.preferredFrameSize = CGSizeMake(300.0, 300.0);
// San Francisco
CLLocationCoordinate2D coord = CLLocationCoordinate2DMake(37.7749, -122.4194);
@@ -240,7 +236,7 @@ typedef ASLayoutSpec *(^OverviewDisplayNodeSizeThatFitsBlock)(ASSizeRange constr
#pragma mark ASVideoNode
ASVideoNode *videoNode = [ASVideoNode new];
[videoNode setSizeWithCGSize:(CGSize){300.0, 400.0}];
videoNode.preferredFrameSize = CGSizeMake(300.0, 400.0);
AVAsset *asset = [AVAsset assetWithURL:[NSURL URLWithString:@"http://www.w3schools.com/html/mov_bbb.mp4"]];
videoNode.asset = asset;
@@ -254,7 +250,7 @@ typedef ASLayoutSpec *(^OverviewDisplayNodeSizeThatFitsBlock)(ASSizeRange constr
UIImage *scrollNodeImage = [UIImage imageNamed:@"image"];
ASScrollNode *scrollNode = [ASScrollNode new];
[scrollNode setSizeWithCGSize:(CGSize){300.0, 400.0}];
scrollNode.preferredFrameSize = CGSizeMake(300.0, 400.0);
UIScrollView *scrollNodeView = scrollNode.view;
[scrollNodeView addSubview:[[UIImageView alloc] initWithImage:scrollNodeImage]];
@@ -395,7 +391,6 @@ typedef ASLayoutSpec *(^OverviewDisplayNodeSizeThatFitsBlock)(ASSizeRange constr
parentNode.entryDescription = @"Is based on a simplified version of CSS flexbox. It allows you to stack components vertically or horizontally and specify how they should be flexed and aligned to fit in the available space.";
parentNode.sizeThatFitsBlock = ^ASLayoutSpec *(ASSizeRange constrainedSize) {
ASStackLayoutSpec *verticalStackLayoutSpec = [ASStackLayoutSpec verticalStackLayoutSpec];
verticalStackLayoutSpec.alignItems = ASStackLayoutAlignItemsStart;
verticalStackLayoutSpec.children = @[childNode1, childNode2, childNode3];
return verticalStackLayoutSpec;
};
@@ -406,17 +401,17 @@ typedef ASLayoutSpec *(^OverviewDisplayNodeSizeThatFitsBlock)(ASSizeRange constr
#pragma mark Horizontal ASStackLayoutSpec
childNode1 = [ASDisplayNode new];
[childNode1 setSizeWithCGSize:(CGSize){10.0, 20.0}];
childNode1.preferredFrameSize = CGSizeMake(10.0, 20);
childNode1.flexGrow = YES;
childNode1.backgroundColor = [UIColor greenColor];
childNode2 = [ASDisplayNode new];
[childNode2 setSizeWithCGSize:(CGSize){10.0, 20.0}];
childNode2.preferredFrameSize = CGSizeMake(10.0, 20.0);
childNode2.alignSelf = ASStackLayoutAlignSelfStretch;
childNode2.backgroundColor = [UIColor blueColor];
childNode3 = [ASDisplayNode new];
[childNode3 setSizeWithCGSize:(CGSize){10.0, 20.0}];
childNode3.preferredFrameSize = CGSizeMake(10.0, 20.0);
childNode3.backgroundColor = [UIColor yellowColor];
parentNode = [self parentNodeWithChild:childNode];
@@ -425,17 +420,20 @@ typedef ASLayoutSpec *(^OverviewDisplayNodeSizeThatFitsBlock)(ASSizeRange constr
parentNode.sizeThatFitsBlock = ^ASLayoutSpec *(ASSizeRange constrainedSize) {
// Create stack alyout spec to layout children
ASStackLayoutSpec *horizontalStackSpec = [ASStackLayoutSpec horizontalStackLayoutSpec];
horizontalStackSpec.alignItems = ASStackLayoutAlignItemsStart;
horizontalStackSpec.children = @[childNode1, childNode2, childNode3];
horizontalStackSpec.spacing = 5.0; // Spacing between children
ASStackLayoutSpec *verticalStackLayoutSpec = [ASStackLayoutSpec horizontalStackLayoutSpec];
verticalStackLayoutSpec.children = @[childNode1, childNode2, childNode3];
verticalStackLayoutSpec.spacing = 5.0; // Spacing between children
// Layout the stack layout with 100% width and 100% height of the parent node
horizontalStackSpec.height = ASDimensionMakeWithFraction(1.0);
horizontalStackSpec.width = ASDimensionMakeWithFraction(1.0);
ASRelativeSizeRange sizeRange = ASRelativeSizeRangeMakeWithExactRelativeDimensions(ASRelativeDimensionMakeWithFraction(1),
ASRelativeDimensionMakeWithFraction(1));
verticalStackLayoutSpec.sizeRange = sizeRange;
// Wrap the static stack layout in a static spec so it will grow to the whole parent node size
ASStaticLayoutSpec *staticLayoutSpec = [ASStaticLayoutSpec staticLayoutSpecWithChildren:@[verticalStackLayoutSpec]];
// Add a bit of inset
return [ASInsetLayoutSpec insetLayoutSpecWithInsets:UIEdgeInsetsMake(0.0, 5.0, 0.0, 5.0) child:horizontalStackSpec];
return [ASInsetLayoutSpec insetLayoutSpecWithInsets:UIEdgeInsetsMake(0.0, 5.0, 0.0, 5.0) child:staticLayoutSpec];
};
[parentNode addSubnode:childNode1];
[parentNode addSubnode:childNode2];
@@ -467,7 +465,7 @@ typedef ASLayoutSpec *(^OverviewDisplayNodeSizeThatFitsBlock)(ASSizeRange constr
- (OverviewDisplayNodeWithSizeBlock *)parentNodeWithChild:(ASDisplayNode *)child
{
OverviewDisplayNodeWithSizeBlock *parentNode = [OverviewDisplayNodeWithSizeBlock new];
[parentNode setSizeWithCGSize:(CGSize){100, 100}];
parentNode.preferredFrameSize = CGSizeMake(100, 100);
parentNode.backgroundColor = [UIColor redColor];
return parentNode;
}
@@ -491,7 +489,7 @@ typedef ASLayoutSpec *(^OverviewDisplayNodeSizeThatFitsBlock)(ASSizeRange constr
- (ASDisplayNode *)childNode
{
ASDisplayNode *childNode = [ASDisplayNode new];
[childNode setSizeWithCGSize:(CGSize){50, 50}];
childNode.preferredFrameSize = CGSizeMake(50, 50);
childNode.backgroundColor = [UIColor blueColor];
return childNode;
}

View File

@@ -51,11 +51,12 @@
// Center node frame
CGRect bounds = self.view.bounds;
CGSize nodeSize = [self.node layoutThatFits:ASSizeRangeMake(CGSizeZero, bounds.size)].size;
self.node.frame = CGRectMake(CGRectGetMidX(bounds) - (nodeSize.width / 2.0),
CGRectGetMidY(bounds) - (nodeSize.height / 2.0),
nodeSize.width,
nodeSize.height);
CGSize nodeSize = self.node.preferredFrameSize;
if (CGSizeEqualToSize(nodeSize, CGSizeZero)) {
nodeSize = self.view.bounds.size;
}
self.node.frame = CGRectMake(CGRectGetMidX(bounds) - (nodeSize.width / 2.0), CGRectGetMidY(bounds) - (nodeSize.height / 2.0), nodeSize.width, nodeSize.height);
[self.node measure:self.node.bounds.size];
}
@end