Introduce ASLayoutable and eliminate ASCompositeNode:

- Both ASDisplayNode and ASLayoutNode conforms to this protocol.
- ASDisplayNode can be embeded directly into layout graph.
- Eliminate ASCompositeNode.
- Fix ASStaticSizeDisplayNode not recpect min constrained size.
- Updated tests.
This commit is contained in:
Huy Nguyen
2015-06-26 08:41:51 +07:00
parent 697b9f4c3c
commit f588bceb4d
40 changed files with 262 additions and 363 deletions

View File

@@ -53,12 +53,12 @@ static const ASSizeRange kSize = {{100, 120}, {320, 160}};
ASLayoutNode *layoutNode =
[ASBackgroundLayoutNode
newWithNode:
newWithChild:
[ASCenterLayoutNode
newWithCenteringOptions:options
sizingOptions:sizingOptions
child:[ASCompositeNode newWithDisplayNode:foregroundNode]]
background:[ASCompositeNode newWithDisplayNode:backgroundNode]];
child:foregroundNode]
background:backgroundNode];
[self testLayoutNode:layoutNode
sizeRange:kSize
@@ -102,14 +102,14 @@ static NSString *suffixForCenteringOptions(ASCenterLayoutNodeCenteringOptions ce
sizingOptions:{}
child:
[ASBackgroundLayoutNode
newWithNode:
newWithChild:
[ASStackLayoutNode
newWithStyle:{}
children:@[[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithDisplayNode:foregroundNode];
mutableChild.node = foregroundNode;
mutableChild.flexGrow = YES;
}]]]
background: [ASCompositeNode newWithDisplayNode:backgroundNode]]];
background:backgroundNode]];
[self testLayoutNode:layoutNode sizeRange:kSize subnodes:@[backgroundNode, foregroundNode] identifier:nil];
}

View File

@@ -63,11 +63,8 @@ static NSString *nameForInsets(UIEdgeInsets insets)
ASLayoutNode *layoutNode =
[ASBackgroundLayoutNode
newWithNode:
[ASInsetLayoutNode
newWithInsets:insets
node:[ASCompositeNode newWithDisplayNode:foregroundNode]]
background:[ASCompositeNode newWithDisplayNode:backgroundNode]];
newWithChild:[ASInsetLayoutNode newWithInsets:insets child:foregroundNode]
background:backgroundNode];
static ASSizeRange kVariableSize = {{0, 0}, {300, 300}};
[self testLayoutNode:layoutNode
@@ -87,11 +84,8 @@ static NSString *nameForInsets(UIEdgeInsets insets)
ASLayoutNode *layoutNode =
[ASBackgroundLayoutNode
newWithNode:
[ASInsetLayoutNode
newWithInsets:insets
node:[ASCompositeNode newWithDisplayNode:foregroundNode]]
background:[ASCompositeNode newWithDisplayNode:backgroundNode]];
newWithChild:[ASInsetLayoutNode newWithInsets:insets child:foregroundNode]
background:backgroundNode];
static ASSizeRange kFixedSize = {{300, 300}, {300, 300}};
[self testLayoutNode:layoutNode
@@ -112,11 +106,8 @@ static NSString *nameForInsets(UIEdgeInsets insets)
ASLayoutNode *layoutNode =
[ASBackgroundLayoutNode
newWithNode:
[ASInsetLayoutNode
newWithInsets:insets
node:[ASCompositeNode newWithDisplayNode:foregroundNode]]
background:[ASCompositeNode newWithDisplayNode:backgroundNode]];
newWithChild:[ASInsetLayoutNode newWithInsets:insets child:foregroundNode]
background:backgroundNode];
static ASSizeRange kFixedSize = {{300, 300}, {300, 300}};
[self testLayoutNode:layoutNode

View File

@@ -7,7 +7,8 @@
//
#import "ASSnapshotTestCase.h"
#import "ASCompositeNode.h"
@class ASLayoutNode;
@interface ASLayoutNodeSnapshotTestCase: ASSnapshotTestCase
/**
@@ -18,7 +19,7 @@
@param identifier An optional identifier, used to identify this snapshot test.
@discussion In order to make the layout node visible, it is embeded to a ASDisplayNode host.
Any display nodes used within the layout (via ASCompositeNode) must be provided.
Any display nodes used within the layout must be provided.
They will be added to the host in the same order as the subnodes array.
*/
- (void)testLayoutNode:(ASLayoutNode *)layoutNode

View File

@@ -8,8 +8,8 @@
#import "ASLayoutNodeSnapshotTestsHelper.h"
#import "ASDisplayNode+Subclasses.h"
#import "ASLayoutNodeSubclass.h"
#import "ASDisplayNode.h"
#import "ASLayoutNode.h"
@interface ASTestNode : ASDisplayNode
- (void)setLayoutNodeUnderTest:(ASLayoutNode *)layoutNodeUnderTest sizeRange:(ASSizeRange)sizeRange;
@@ -55,7 +55,7 @@
[self measure:_layoutUnderTest.size];
}
- (ASLayout *)calculateLayoutThatFits:(CGSize)constrainedSize
- (ASLayout *)calculateLayoutThatFits:(ASSizeRange)constrainedSize
{
return _layoutUnderTest;
}
@@ -64,11 +64,11 @@
@implementation ASStaticSizeDisplayNode
- (ASLayout *)calculateLayoutThatFits:(CGSize)constrainedSize
- (ASLayout *)calculateLayoutThatFits:(ASSizeRange)constrainedSize
{
return CGSizeEqualToSize(_staticSize, CGSizeZero)
? [super calculateLayoutThatFits:constrainedSize]
: [ASLayout newWithNode:[ASLayoutNode new] size:_staticSize];
: [ASLayout newWithLayoutableObject:self size:ASSizeRangeClamp(constrainedSize, _staticSize)];
}
@end

View File

@@ -34,12 +34,12 @@ static const ASSizeRange kSize = {{320, 320}, {320, 320}};
ASLayoutNode *layoutNode =
[ASOverlayLayoutNode
newWithNode:[ASCompositeNode newWithDisplayNode:backgroundNode]
newWithChild:backgroundNode
overlay:
[ASCenterLayoutNode
newWithCenteringOptions:ASCenterLayoutNodeCenteringXY
sizingOptions:{}
child:[ASCompositeNode newWithDisplayNode:foregroundNode]]];
child:foregroundNode]];
[self testLayoutNode:layoutNode sizeRange:kSize subnodes:@[backgroundNode, foregroundNode] identifier: nil];
}

View File

@@ -30,9 +30,7 @@ static const ASSizeRange kFixedSize = {{0, 0}, {100, 100}};
ASStaticSizeDisplayNode *subnode = ASDisplayNodeWithBackgroundColor([UIColor greenColor]);
subnode.staticSize = childNodeSize;
ASLayoutNode *layoutNode = [ASRatioLayoutNode
newWithRatio:ratio
node:[ASCompositeNode newWithDisplayNode:subnode]];
ASLayoutNode *layoutNode = [ASRatioLayoutNode newWithRatio:ratio child:subnode];
[self testLayoutNode:layoutNode sizeRange:kFixedSize subnodes:@[subnode] identifier:identifier];
}

View File

@@ -26,10 +26,10 @@
self.recordMode = NO;
}
static ASStackLayoutNodeChild *flexChild(ASLayoutNode *n, BOOL flex)
static ASStackLayoutNodeChild *flexChild(id<ASLayoutable> child, BOOL flex)
{
return [ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = n;
mutableChild.node = child;
mutableChild.flexGrow = flex;
mutableChild.flexShrink = flex;
}];
@@ -64,9 +64,9 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize)
};
NSArray *subnodes = defaultSubnodesWithSameSize({50, 50});
NSArray *children = @[
flexChild([ASCompositeNode newWithDisplayNode:subnodes[0]], flex),
flexChild([ASCompositeNode newWithDisplayNode:subnodes[1]], flex),
flexChild([ASCompositeNode newWithDisplayNode:subnodes[2]], flex)
flexChild(subnodes[0], flex),
flexChild(subnodes[1], flex),
flexChild(subnodes[2], flex)
];
[self testStackLayoutNodeWithStyle:style children:children sizeRange:sizeRange subnodes:subnodes identifier:identifier];
@@ -82,8 +82,8 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize)
ASLayoutNode *layoutNode =
[ASBackgroundLayoutNode
newWithNode:[ASStackLayoutNode newWithStyle:style children:children]
background:[ASCompositeNode newWithDisplayNode:backgroundNode]];
newWithChild:[ASStackLayoutNode newWithStyle:style children:children]
background:backgroundNode];
NSMutableArray *newSubnodes = [NSMutableArray arrayWithObject:backgroundNode];
[newSubnodes addObjectsFromArray:subnodes];
@@ -118,15 +118,15 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize)
NSArray *children = @[
// After flexShrink-able children are all clamped to zero, the sum of their widths is 100px.
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[0]];
mutableChild.node = subnodes[0];
mutableChild.flexShrink = NO;
}],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[1]];
mutableChild.node = subnodes[1];
mutableChild.flexShrink = YES;
}],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[2]];
mutableChild.node = subnodes[2];
mutableChild.flexShrink = NO;
}]
];
@@ -145,9 +145,9 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize)
((ASStaticSizeDisplayNode *)subnodes[2]).staticSize = {50, 50};
NSArray *children = @[
flexChild([ASCompositeNode newWithDisplayNode:subnodes[0]], YES),
flexChild([ASCompositeNode newWithDisplayNode:subnodes[1]], YES),
flexChild([ASCompositeNode newWithDisplayNode:subnodes[2]], YES)
flexChild(subnodes[0], YES),
flexChild(subnodes[1], YES),
flexChild(subnodes[2], YES)
];
// width 300px; height 0-150px.
@@ -170,13 +170,13 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize)
NSArray *children = @[
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[0]];
mutableChild.node = subnodes[0];
}],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[1]];
mutableChild.node = subnodes[1];
}],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[2]];
mutableChild.node = subnodes[2];
}]
];
@@ -203,13 +203,13 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize)
NSArray *children = @[
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[0]];
mutableChild.node = subnodes[0];
}],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[1]];
mutableChild.node = subnodes[1];
}],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[2]];
mutableChild.node = subnodes[2];
}]
];
// width 0-300px; height 300px
@@ -226,9 +226,9 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize)
ASLayoutNode *layoutNode =
[ASInsetLayoutNode
newWithInsets:{10, 10, 10 ,10}
node:
child:
[ASBackgroundLayoutNode
newWithNode:
newWithChild:
[ASStackLayoutNode
newWithStyle:{
.direction = ASStackLayoutDirectionVertical,
@@ -239,7 +239,7 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize)
[ASStackLayoutNodeChild new],
[ASStackLayoutNodeChild new]
]]
background:[ASCompositeNode newWithDisplayNode:backgroundNode]]];
background:backgroundNode]];
// width 300px; height 0-300px
static ASSizeRange kVariableHeight = {{300, 0}, {300, 300}};
@@ -259,14 +259,14 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize)
NSArray *children = @[
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[0]];
mutableChild.node = subnodes[0];
}],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[1]];
mutableChild.node = subnodes[1];
mutableChild.spacingBefore = 10;
}],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[2]];
mutableChild.node = subnodes[2];
mutableChild.spacingBefore = 20;
}]
];
@@ -274,14 +274,14 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize)
children = @[
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[0]];
mutableChild.node = subnodes[0];
}],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[1]];
mutableChild.node = subnodes[1];
mutableChild.spacingAfter = 10;
}],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[2]];
mutableChild.node = subnodes[2];
mutableChild.spacingAfter = 20;
}]
];
@@ -290,15 +290,15 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize)
style.spacing = 10;
children = @[
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[0]];
mutableChild.node = subnodes[0];
}],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[1]];
mutableChild.node = subnodes[1];
mutableChild.spacingBefore = -10;
mutableChild.spacingAfter = -10;
}],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[2]];
mutableChild.node = subnodes[2];
}]
];
[self testStackLayoutNodeWithStyle:style children:children sizeRange:kAnySize subnodes:subnodes identifier:@"spacingBalancedOut"];
@@ -318,15 +318,15 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize)
NSArray *children = @[
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[0]];
mutableChild.node = subnodes[0];
mutableChild.spacingBefore = 0;
}],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[1]];
mutableChild.node = subnodes[1];
mutableChild.spacingBefore = 20;
}],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[2]];
mutableChild.node = subnodes[2];
mutableChild.spacingBefore = 30;
}]
];
@@ -348,15 +348,13 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize)
NSArray *children = @[
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASRatioLayoutNode
newWithRatio:1.5
node:[ASCompositeNode newWithDisplayNode:subnodes[0]]];
mutableChild.node = [ASRatioLayoutNode newWithRatio:1.5 child:subnodes[0]];
mutableChild.flexBasis = ASRelativeDimensionMakeWithPercent(1);
mutableChild.flexGrow = YES;
mutableChild.flexShrink = YES;
}],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[1]];
mutableChild.node = subnodes[1];
}]
];
static ASSizeRange kFixedWidth = {{150, 0}, {150, INFINITY}};
@@ -379,11 +377,11 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize)
NSArray *children = @[
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[0]];
mutableChild.node = subnodes[0];
mutableChild.flexShrink = YES;
}],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[1]];
mutableChild.node = subnodes[1];
mutableChild.flexShrink = YES;
}],
];
@@ -404,10 +402,10 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize)
NSArray *children = @[
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[0]];
mutableChild.node = subnodes[0];
}],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[1]];
mutableChild.node = subnodes[1];
mutableChild.alignSelf = ASStackLayoutAlignSelfCenter;
}],
];
@@ -430,15 +428,15 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize)
NSArray *children = @[
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[0]];
mutableChild.node = subnodes[0];
mutableChild.spacingBefore = 0;
}],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[1]];
mutableChild.node = subnodes[1];
mutableChild.spacingBefore = 20;
}],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[2]];
mutableChild.node = subnodes[2];
mutableChild.spacingBefore = 30;
}]
];
@@ -461,15 +459,15 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize)
NSArray *children = @[
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[0]];
mutableChild.node = subnodes[0];
mutableChild.spacingBefore = 0;
}],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[1]];
mutableChild.node = subnodes[1];
mutableChild.spacingBefore = 20;
}],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[2]];
mutableChild.node = subnodes[2];
mutableChild.spacingBefore = 30;
}]
];
@@ -492,15 +490,15 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize)
NSArray *children = @[
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[0]];
mutableChild.node = subnodes[0];
mutableChild.spacingBefore = 0;
}],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[1]];
mutableChild.node = subnodes[1];
mutableChild.spacingBefore = 20;
}],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[2]];
mutableChild.node = subnodes[2];
mutableChild.spacingBefore = 30;
}]
];
@@ -523,15 +521,15 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize)
NSArray *children = @[
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[0]];
mutableChild.node = subnodes[0];
mutableChild.spacingBefore = 0;
}],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[1]];
mutableChild.node = subnodes[1];
mutableChild.spacingBefore = 20;
}],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[2]];
mutableChild.node = subnodes[2];
mutableChild.spacingBefore = 30;
}]
];
@@ -555,15 +553,15 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize)
NSArray *children = @[
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[0]];
mutableChild.node = subnodes[0];
mutableChild.spacingBefore = 0;
}],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[1]];
mutableChild.node = subnodes[1];
mutableChild.spacingBefore = 20;
}],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[2]];
mutableChild.node = subnodes[2];
mutableChild.spacingBefore = 30;
}]
];
@@ -589,17 +587,17 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize)
NSArray *children = @[
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[0]];
mutableChild.node = subnodes[0];
mutableChild.flexGrow = YES;
mutableChild.flexBasis = ASRelativeDimensionMakeWithPoints(10);
}],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[1]];
mutableChild.node = subnodes[1];
mutableChild.flexGrow = YES;
mutableChild.flexBasis = ASRelativeDimensionMakeWithPoints(10);
}],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[2]];
mutableChild.node = subnodes[2];
mutableChild.flexGrow = YES;
mutableChild.flexBasis = ASRelativeDimensionMakeWithPoints(10);
}]
@@ -619,18 +617,18 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize)
NSArray *subnodes = defaultSubnodesWithSameSize({50, 50});
NSArray *children = @[
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[0]];
mutableChild.node = subnodes[0];
mutableChild.flexGrow = YES;
// This should override the intrinsic size of 50pts and instead compute to 50% = 100pts.
// The result should be that the red box is twice as wide as the blue and gree boxes after flexing.
mutableChild.flexBasis = ASRelativeDimensionMakeWithPercent(0.5);
}],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[1]];
mutableChild.node = subnodes[1];
mutableChild.flexGrow = YES;
}],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[2]];
mutableChild.node = subnodes[2];
mutableChild.flexGrow = YES;
}]
];
@@ -649,15 +647,15 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize)
NSArray *children = @[
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[0]];
mutableChild.node = subnodes[0];
mutableChild.flexBasis = ASRelativeDimensionMakeWithPoints(20);
}],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[1]];
mutableChild.node = subnodes[1];
mutableChild.flexBasis = ASRelativeDimensionMakeWithPoints(20);
}],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[2]];
mutableChild.node = subnodes[2];
mutableChild.flexBasis = ASRelativeDimensionMakeWithPoints(20);
}]
];
@@ -679,26 +677,23 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize)
// Instead it should be stretched to 300 points tall, matching the red child and not overlapping the green inset.
ASLayoutNode *layoutNode =
[ASBackgroundLayoutNode
newWithNode:
newWithChild:
[ASInsetLayoutNode
newWithInsets:UIEdgeInsetsMake(10, 10, 10, 10)
node:
[ASStackLayoutNode
newWithStyle:{
child:
[ASStackLayoutNode
newWithStyle:{
.direction = ASStackLayoutDirectionHorizontal,
.alignItems = ASStackLayoutAlignItemsStretch,
}
children:
@[
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[1]];
}],
flexChild([ASRatioLayoutNode
newWithRatio:1.0
node:[ASCompositeNode newWithDisplayNode:subnodes[2]]],
YES),
]]]
background:[ASCompositeNode newWithDisplayNode:subnodes[0]]];
}
children:
@[
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = subnodes[1];
}],
flexChild([ASRatioLayoutNode newWithRatio:1.0 child:subnodes[2]], YES),
]]]
background:subnodes[0]];
static ASSizeRange kSize = {{300, 0}, {300, INFINITY}};
[self testLayoutNode:layoutNode sizeRange:kSize subnodes:subnodes identifier:nil];
@@ -715,15 +710,15 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize)
NSArray *children = @[
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[0]];
mutableChild.node = subnodes[0];
mutableChild.flexShrink = YES;
}],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[1]];
mutableChild.node = subnodes[1];
mutableChild.flexShrink = NO;
}],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[2]];
mutableChild.node = subnodes[2];
mutableChild.flexShrink = YES;
}]
];