mirror of
https://github.com/HackPlan/AsyncDisplayKit.git
synced 2026-04-05 16:51:10 +08:00
Revert "[Layout] Layout API based on content area (#2110)"
This reverts commit 8897614f0e.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user