mirror of
https://github.com/HackPlan/AsyncDisplayKit.git
synced 2026-05-13 00:39:06 +08:00
Revert the giant layout diff
This commit is contained in:
@@ -23,31 +23,26 @@
|
||||
|
||||
#pragma mark - Utility methods
|
||||
|
||||
static NSArray<ASDisplayNode *> *defaultSubnodes()
|
||||
static NSArray *defaultSubnodes()
|
||||
{
|
||||
return defaultSubnodesWithSameSize(CGSizeZero, NO);
|
||||
}
|
||||
|
||||
static NSArray<ASDisplayNode *> *defaultSubnodesWithSameSize(CGSize subnodeSize, BOOL flex)
|
||||
static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize, BOOL flex)
|
||||
{
|
||||
NSArray<ASDisplayNode *> *subnodes = @[
|
||||
ASDisplayNodeWithBackgroundColor([UIColor redColor], subnodeSize),
|
||||
ASDisplayNodeWithBackgroundColor([UIColor blueColor], subnodeSize),
|
||||
ASDisplayNodeWithBackgroundColor([UIColor greenColor], subnodeSize)
|
||||
];
|
||||
for (ASDisplayNode *subnode in subnodes) {
|
||||
NSArray *subnodes = @[
|
||||
ASDisplayNodeWithBackgroundColor([UIColor redColor]),
|
||||
ASDisplayNodeWithBackgroundColor([UIColor blueColor]),
|
||||
ASDisplayNodeWithBackgroundColor([UIColor greenColor])
|
||||
];
|
||||
for (ASStaticSizeDisplayNode *subnode in subnodes) {
|
||||
subnode.staticSize = subnodeSize;
|
||||
subnode.flexGrow = flex;
|
||||
subnode.flexShrink = flex;
|
||||
}
|
||||
return subnodes;
|
||||
}
|
||||
|
||||
static void setCGSizeToNode(CGSize size, ASDisplayNode *node)
|
||||
{
|
||||
node.width = ASDimensionMakeWithPoints(size.width);
|
||||
node.height = ASDimensionMakeWithPoints(size.height);
|
||||
}
|
||||
|
||||
- (void)testStackLayoutSpecWithJustify:(ASStackLayoutJustifyContent)justify
|
||||
flex:(BOOL)flex
|
||||
sizeRange:(ASSizeRange)sizeRange
|
||||
@@ -58,7 +53,7 @@ static void setCGSizeToNode(CGSize size, ASDisplayNode *node)
|
||||
.justifyContent = justify
|
||||
};
|
||||
|
||||
NSArray<ASDisplayNode *> *subnodes = defaultSubnodesWithSameSize({50, 50}, flex);
|
||||
NSArray *subnodes = defaultSubnodesWithSameSize({50, 50}, flex);
|
||||
|
||||
[self testStackLayoutSpecWithStyle:style sizeRange:sizeRange subnodes:subnodes identifier:identifier];
|
||||
}
|
||||
@@ -68,13 +63,13 @@ static void setCGSizeToNode(CGSize size, ASDisplayNode *node)
|
||||
itemsVerticalAlignment:(ASVerticalAlignment)verticalAlignment
|
||||
identifier:(NSString *)identifier
|
||||
{
|
||||
NSArray<ASDisplayNode *> *subnodes = defaultSubnodesWithSameSize({50, 50}, NO);
|
||||
NSArray *subnodes = defaultSubnodesWithSameSize({50, 50}, NO);
|
||||
|
||||
ASStackLayoutSpec *stackLayoutSpec = [[ASStackLayoutSpec alloc] init];
|
||||
stackLayoutSpec.direction = direction;
|
||||
stackLayoutSpec.children = subnodes;
|
||||
stackLayoutSpec.horizontalAlignment = horizontalAlignment;
|
||||
stackLayoutSpec.verticalAlignment = verticalAlignment;
|
||||
[stackLayoutSpec setHorizontalAlignment:horizontalAlignment];
|
||||
[stackLayoutSpec setVerticalAlignment:verticalAlignment];
|
||||
|
||||
CGSize exactSize = CGSizeMake(200, 200);
|
||||
static ASSizeRange kSize = ASSizeRangeMake(exactSize, exactSize);
|
||||
@@ -95,14 +90,11 @@ static void setCGSizeToNode(CGSize size, ASDisplayNode *node)
|
||||
subnodes:(NSArray *)subnodes
|
||||
identifier:(NSString *)identifier
|
||||
{
|
||||
ASStackLayoutSpec *stackLayoutSpec =
|
||||
[ASStackLayoutSpec
|
||||
stackLayoutSpecWithDirection:style.direction
|
||||
spacing:style.spacing
|
||||
justifyContent:style.justifyContent
|
||||
alignItems:style.alignItems
|
||||
children:children];
|
||||
|
||||
ASStackLayoutSpec *stackLayoutSpec = [ASStackLayoutSpec stackLayoutSpecWithDirection:style.direction
|
||||
spacing:style.spacing
|
||||
justifyContent:style.justifyContent
|
||||
alignItems:style.alignItems
|
||||
children:children];
|
||||
[self testStackLayoutSpec:stackLayoutSpec sizeRange:sizeRange subnodes:subnodes identifier:identifier];
|
||||
}
|
||||
|
||||
@@ -112,6 +104,7 @@ static void setCGSizeToNode(CGSize size, ASDisplayNode *node)
|
||||
identifier:(NSString *)identifier
|
||||
{
|
||||
ASDisplayNode *backgroundNode = ASDisplayNodeWithBackgroundColor([UIColor whiteColor]);
|
||||
|
||||
ASLayoutSpec *layoutSpec = [ASBackgroundLayoutSpec backgroundLayoutSpecWithChild:stackLayoutSpec background:backgroundNode];
|
||||
|
||||
NSMutableArray *newSubnodes = [NSMutableArray arrayWithObject:backgroundNode];
|
||||
@@ -152,8 +145,8 @@ static void setCGSizeToNode(CGSize size, ASDisplayNode *node)
|
||||
{
|
||||
ASStackLayoutSpecStyle style = {.direction = ASStackLayoutDirectionHorizontal};
|
||||
|
||||
NSArray<ASDisplayNode *> *subnodes = defaultSubnodesWithSameSize({50, 50}, NO);
|
||||
subnodes[1].flexShrink = YES;
|
||||
NSArray *subnodes = defaultSubnodesWithSameSize({50, 50}, NO);
|
||||
((ASDisplayNode *)subnodes[1]).flexShrink = YES;
|
||||
|
||||
// Width is 75px--that's less than the sum of the widths of the children, which is 100px.
|
||||
static ASSizeRange kSize = {{75, 0}, {75, 150}};
|
||||
@@ -164,8 +157,8 @@ static void setCGSizeToNode(CGSize size, ASDisplayNode *node)
|
||||
{
|
||||
ASStackLayoutSpecStyle style = {.direction = ASStackLayoutDirectionHorizontal};
|
||||
|
||||
NSArray<ASDisplayNode *> *subnodes = defaultSubnodesWithSameSize({50, 50}, YES);
|
||||
setCGSizeToNode({150, 150}, subnodes[1]);
|
||||
NSArray *subnodes = defaultSubnodesWithSameSize({50, 50}, YES);
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {150, 150};
|
||||
|
||||
// width 300px; height 0-150px.
|
||||
static ASSizeRange kUnderflowSize = {{300, 0}, {300, 150}};
|
||||
@@ -180,10 +173,10 @@ static void setCGSizeToNode(CGSize size, ASDisplayNode *node)
|
||||
{
|
||||
ASStackLayoutSpecStyle style = {.direction = ASStackLayoutDirectionVertical};
|
||||
|
||||
NSArray<ASDisplayNode *> *subnodes = defaultSubnodes();
|
||||
setCGSizeToNode({50, 50}, subnodes[0]);
|
||||
setCGSizeToNode({100, 50}, subnodes[1]);
|
||||
setCGSizeToNode({150, 50}, subnodes[2]);
|
||||
NSArray *subnodes = defaultSubnodes();
|
||||
((ASStaticSizeDisplayNode *)subnodes[0]).staticSize = {50, 50};
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {100, 50};
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).staticSize = {150, 50};
|
||||
|
||||
// width 0-300px; height 300px
|
||||
static ASSizeRange kVariableHeight = {{0, 300}, {300, 300}};
|
||||
@@ -201,10 +194,10 @@ static void setCGSizeToNode(CGSize size, ASDisplayNode *node)
|
||||
.spacing = 10
|
||||
};
|
||||
|
||||
NSArray<ASDisplayNode *> *subnodes = defaultSubnodes();
|
||||
setCGSizeToNode({50, 50}, subnodes[0]);
|
||||
setCGSizeToNode({100, 50}, subnodes[1]);
|
||||
setCGSizeToNode({150, 50}, subnodes[2]);
|
||||
NSArray *subnodes = defaultSubnodes();
|
||||
((ASStaticSizeDisplayNode *)subnodes[0]).staticSize = {50, 50};
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {100, 50};
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).staticSize = {150, 50};
|
||||
|
||||
// width 0-300px; height 300px
|
||||
static ASSizeRange kVariableHeight = {{0, 300}, {300, 300}};
|
||||
@@ -219,16 +212,12 @@ static void setCGSizeToNode(CGSize size, ASDisplayNode *node)
|
||||
|
||||
ASLayoutSpec *layoutSpec =
|
||||
[ASInsetLayoutSpec
|
||||
insetLayoutSpecWithInsets:{10, 10, 10, 10}
|
||||
insetLayoutSpecWithInsets:{10, 10, 10 ,10}
|
||||
child:
|
||||
[ASBackgroundLayoutSpec
|
||||
backgroundLayoutSpecWithChild:
|
||||
[ASStackLayoutSpec
|
||||
stackLayoutSpecWithDirection:ASStackLayoutDirectionVertical
|
||||
spacing:10
|
||||
justifyContent:ASStackLayoutJustifyContentStart
|
||||
alignItems:ASStackLayoutAlignItemsStretch
|
||||
children:@[]]
|
||||
stackLayoutSpecWithDirection:ASStackLayoutDirectionVertical spacing:10 justifyContent:ASStackLayoutJustifyContentStart alignItems:ASStackLayoutAlignItemsStretch children:@[]]
|
||||
background:backgroundNode]];
|
||||
|
||||
// width 300px; height 0-300px
|
||||
@@ -242,28 +231,28 @@ static void setCGSizeToNode(CGSize size, ASDisplayNode *node)
|
||||
static ASSizeRange kAnySize = {{0, 0}, {INFINITY, INFINITY}};
|
||||
ASStackLayoutSpecStyle style = {.direction = ASStackLayoutDirectionVertical};
|
||||
|
||||
NSArray<ASDisplayNode *> *subnodes = defaultSubnodes();
|
||||
setCGSizeToNode({50, 50}, subnodes[0]);
|
||||
setCGSizeToNode({100, 70}, subnodes[1]);
|
||||
setCGSizeToNode({150, 90}, subnodes[2]);
|
||||
NSArray *subnodes = defaultSubnodes();
|
||||
((ASStaticSizeDisplayNode *)subnodes[0]).staticSize = {50, 50};
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {100, 70};
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).staticSize = {150, 90};
|
||||
|
||||
subnodes[1].spacingBefore = 10;
|
||||
subnodes[2].spacingBefore = 20;
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).spacingBefore = 10;
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).spacingBefore = 20;
|
||||
[self testStackLayoutSpecWithStyle:style sizeRange:kAnySize subnodes:subnodes identifier:@"spacingBefore"];
|
||||
// Reset above spacing values
|
||||
subnodes[1].spacingBefore = 0;
|
||||
subnodes[2].spacingBefore = 0;
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).spacingBefore = 0;
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).spacingBefore = 0;
|
||||
|
||||
subnodes[1].spacingAfter = 10;
|
||||
subnodes[2].spacingAfter = 20;
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).spacingAfter = 10;
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).spacingAfter = 20;
|
||||
[self testStackLayoutSpecWithStyle:style sizeRange:kAnySize subnodes:subnodes identifier:@"spacingAfter"];
|
||||
// Reset above spacing values
|
||||
subnodes[1].spacingAfter = 0;
|
||||
subnodes[2].spacingAfter = 0;
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).spacingAfter = 0;
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).spacingAfter = 0;
|
||||
|
||||
style.spacing = 10;
|
||||
subnodes[1].spacingBefore = -10;
|
||||
subnodes[1].spacingAfter = -10;
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).spacingBefore = -10;
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).spacingAfter = -10;
|
||||
[self testStackLayoutSpecWithStyle:style sizeRange:kAnySize subnodes:subnodes identifier:@"spacingBalancedOut"];
|
||||
}
|
||||
|
||||
@@ -274,14 +263,14 @@ static void setCGSizeToNode(CGSize size, ASDisplayNode *node)
|
||||
.justifyContent = ASStackLayoutJustifyContentCenter
|
||||
};
|
||||
|
||||
NSArray<ASDisplayNode *> *subnodes = defaultSubnodes();
|
||||
setCGSizeToNode({50, 50}, subnodes[0]);
|
||||
setCGSizeToNode({100, 70}, subnodes[1]);
|
||||
setCGSizeToNode({150, 90}, subnodes[2]);
|
||||
NSArray *subnodes = defaultSubnodes();
|
||||
((ASStaticSizeDisplayNode *)subnodes[0]).staticSize = {50, 50};
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {100, 70};
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).staticSize = {150, 90};
|
||||
|
||||
subnodes[0].spacingBefore = 0;
|
||||
subnodes[1].spacingBefore = 20;
|
||||
subnodes[2].spacingBefore = 30;
|
||||
((ASStaticSizeDisplayNode *)subnodes[0]).spacingBefore = 0;
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).spacingBefore = 20;
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).spacingBefore = 30;
|
||||
|
||||
// width 0-300px; height 300px
|
||||
static ASSizeRange kVariableHeight = {{0, 300}, {300, 300}};
|
||||
@@ -295,7 +284,8 @@ static void setCGSizeToNode(CGSize size, ASDisplayNode *node)
|
||||
.justifyContent = ASStackLayoutJustifyContentSpaceBetween
|
||||
};
|
||||
|
||||
ASDisplayNode *child = ASDisplayNodeWithBackgroundColor([UIColor redColor], {50, 50});
|
||||
ASStaticSizeDisplayNode *child = ASDisplayNodeWithBackgroundColor([UIColor redColor]);
|
||||
child.staticSize = {50, 50};
|
||||
|
||||
// width 300px; height 0-INF
|
||||
static ASSizeRange kVariableHeight = {{300, 0}, {300, INFINITY}};
|
||||
@@ -309,7 +299,8 @@ static void setCGSizeToNode(CGSize size, ASDisplayNode *node)
|
||||
.justifyContent = ASStackLayoutJustifyContentSpaceAround
|
||||
};
|
||||
|
||||
ASDisplayNode *child = ASDisplayNodeWithBackgroundColor([UIColor redColor], {50, 50});
|
||||
ASStaticSizeDisplayNode *child = ASDisplayNodeWithBackgroundColor([UIColor redColor]);
|
||||
child.staticSize = {50, 50};
|
||||
|
||||
// width 300px; height 0-INF
|
||||
static ASSizeRange kVariableHeight = {{300, 0}, {300, INFINITY}};
|
||||
@@ -334,11 +325,12 @@ static void setCGSizeToNode(CGSize size, ASDisplayNode *node)
|
||||
{
|
||||
ASStackLayoutSpecStyle style = {.direction = ASStackLayoutDirectionHorizontal};
|
||||
|
||||
ASDisplayNode * subnode1 = ASDisplayNodeWithBackgroundColor([UIColor blueColor]);
|
||||
ASDisplayNode * subnode2 = ASDisplayNodeWithBackgroundColor([UIColor redColor], {50, 50});
|
||||
ASStaticSizeDisplayNode * subnode1 = ASDisplayNodeWithBackgroundColor([UIColor blueColor]);
|
||||
ASStaticSizeDisplayNode * subnode2 = ASDisplayNodeWithBackgroundColor([UIColor redColor]);
|
||||
subnode2.staticSize = {50, 50};
|
||||
|
||||
ASRatioLayoutSpec *child1 = [ASRatioLayoutSpec ratioLayoutSpecWithRatio:1.5 child:subnode1];
|
||||
child1.flexBasis = ASDimensionMakeWithFraction(1);
|
||||
child1.flexBasis = ASRelativeDimensionMakeWithFraction(1);
|
||||
child1.flexGrow = YES;
|
||||
child1.flexShrink = YES;
|
||||
|
||||
@@ -353,13 +345,15 @@ static void setCGSizeToNode(CGSize size, ASDisplayNode *node)
|
||||
.alignItems = ASStackLayoutAlignItemsCenter
|
||||
};
|
||||
|
||||
ASDisplayNode *subnode1 = ASDisplayNodeWithBackgroundColor([UIColor redColor], {100, 100});
|
||||
ASStaticSizeDisplayNode *subnode1 = ASDisplayNodeWithBackgroundColor([UIColor redColor]);
|
||||
subnode1.staticSize = {100, 100};
|
||||
subnode1.flexShrink = YES;
|
||||
|
||||
ASDisplayNode *subnode2 = ASDisplayNodeWithBackgroundColor([UIColor blueColor], {50, 50});
|
||||
ASStaticSizeDisplayNode *subnode2 = ASDisplayNodeWithBackgroundColor([UIColor blueColor]);
|
||||
subnode2.staticSize = {50, 50};
|
||||
subnode2.flexShrink = YES;
|
||||
|
||||
NSArray<ASDisplayNode *> *subnodes = @[subnode1, subnode2];
|
||||
NSArray *subnodes = @[subnode1, subnode2];
|
||||
static ASSizeRange kFixedWidth = {{150, 0}, {150, 100}};
|
||||
[self testStackLayoutSpecWithStyle:style sizeRange:kFixedWidth subnodes:subnodes identifier:nil];
|
||||
}
|
||||
@@ -368,12 +362,14 @@ static void setCGSizeToNode(CGSize size, ASDisplayNode *node)
|
||||
{
|
||||
ASStackLayoutSpecStyle style = {.direction = ASStackLayoutDirectionHorizontal};
|
||||
|
||||
ASDisplayNode *subnode1 = ASDisplayNodeWithBackgroundColor([UIColor redColor], {100, 100});
|
||||
ASStaticSizeDisplayNode *subnode1 = ASDisplayNodeWithBackgroundColor([UIColor redColor]);
|
||||
subnode1.staticSize = {100, 100};
|
||||
|
||||
ASDisplayNode *subnode2 = ASDisplayNodeWithBackgroundColor([UIColor blueColor], {50, 50});
|
||||
ASStaticSizeDisplayNode *subnode2 = ASDisplayNodeWithBackgroundColor([UIColor blueColor]);
|
||||
subnode2.staticSize = {50, 50};
|
||||
subnode2.alignSelf = ASStackLayoutAlignSelfCenter;
|
||||
|
||||
NSArray<ASDisplayNode *> *subnodes = @[subnode1, subnode2];
|
||||
NSArray *subnodes = @[subnode1, subnode2];
|
||||
static ASSizeRange kFixedWidth = {{150, 0}, {150, INFINITY}};
|
||||
[self testStackLayoutSpecWithStyle:style sizeRange:kFixedWidth subnodes:subnodes identifier:nil];
|
||||
}
|
||||
@@ -386,14 +382,14 @@ static void setCGSizeToNode(CGSize size, ASDisplayNode *node)
|
||||
.alignItems = ASStackLayoutAlignItemsStart
|
||||
};
|
||||
|
||||
NSArray<ASDisplayNode *> *subnodes = defaultSubnodes();
|
||||
setCGSizeToNode({50, 50}, subnodes[0]);
|
||||
setCGSizeToNode({100, 70}, subnodes[1]);
|
||||
setCGSizeToNode({150, 90}, subnodes[2]);
|
||||
NSArray *subnodes = defaultSubnodes();
|
||||
((ASStaticSizeDisplayNode *)subnodes[0]).staticSize = {50, 50};
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {100, 70};
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).staticSize = {150, 90};
|
||||
|
||||
subnodes[0].spacingBefore = 0;
|
||||
subnodes[1].spacingBefore = 20;
|
||||
subnodes[2].spacingBefore = 30;
|
||||
((ASStaticSizeDisplayNode *)subnodes[0]).spacingBefore = 0;
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).spacingBefore = 20;
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).spacingBefore = 30;
|
||||
|
||||
static ASSizeRange kExactSize = {{300, 300}, {300, 300}};
|
||||
[self testStackLayoutSpecWithStyle:style sizeRange:kExactSize subnodes:subnodes identifier:nil];
|
||||
@@ -407,14 +403,14 @@ static void setCGSizeToNode(CGSize size, ASDisplayNode *node)
|
||||
.alignItems = ASStackLayoutAlignItemsEnd
|
||||
};
|
||||
|
||||
NSArray<ASDisplayNode *> *subnodes = defaultSubnodes();
|
||||
setCGSizeToNode({50, 50}, subnodes[0]);
|
||||
setCGSizeToNode({100, 70}, subnodes[1]);
|
||||
setCGSizeToNode({150, 90}, subnodes[2]);
|
||||
NSArray *subnodes = defaultSubnodes();
|
||||
((ASStaticSizeDisplayNode *)subnodes[0]).staticSize = {50, 50};
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {100, 70};
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).staticSize = {150, 90};
|
||||
|
||||
subnodes[0].spacingBefore = 0;
|
||||
subnodes[1].spacingBefore = 20;
|
||||
subnodes[2].spacingBefore = 30;
|
||||
((ASStaticSizeDisplayNode *)subnodes[0]).spacingBefore = 0;
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).spacingBefore = 20;
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).spacingBefore = 30;
|
||||
|
||||
static ASSizeRange kExactSize = {{300, 300}, {300, 300}};
|
||||
[self testStackLayoutSpecWithStyle:style sizeRange:kExactSize subnodes:subnodes identifier:nil];
|
||||
@@ -428,14 +424,14 @@ static void setCGSizeToNode(CGSize size, ASDisplayNode *node)
|
||||
.alignItems = ASStackLayoutAlignItemsCenter
|
||||
};
|
||||
|
||||
NSArray<ASDisplayNode *> *subnodes = defaultSubnodes();
|
||||
setCGSizeToNode({50, 50}, subnodes[0]);
|
||||
setCGSizeToNode({100, 70}, subnodes[1]);
|
||||
setCGSizeToNode({150, 90}, subnodes[2]);
|
||||
NSArray *subnodes = defaultSubnodes();
|
||||
((ASStaticSizeDisplayNode *)subnodes[0]).staticSize = {50, 50};
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {100, 70};
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).staticSize = {150, 90};
|
||||
|
||||
subnodes[0].spacingBefore = 0;
|
||||
subnodes[1].spacingBefore = 20;
|
||||
subnodes[2].spacingBefore = 30;
|
||||
((ASStaticSizeDisplayNode *)subnodes[0]).spacingBefore = 0;
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).spacingBefore = 20;
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).spacingBefore = 30;
|
||||
|
||||
static ASSizeRange kExactSize = {{300, 300}, {300, 300}};
|
||||
[self testStackLayoutSpecWithStyle:style sizeRange:kExactSize subnodes:subnodes identifier:nil];
|
||||
@@ -449,14 +445,14 @@ static void setCGSizeToNode(CGSize size, ASDisplayNode *node)
|
||||
.alignItems = ASStackLayoutAlignItemsStretch
|
||||
};
|
||||
|
||||
NSArray<ASDisplayNode *> *subnodes = defaultSubnodes();
|
||||
setCGSizeToNode({50, 50}, subnodes[0]);
|
||||
setCGSizeToNode({100, 70}, subnodes[1]);
|
||||
setCGSizeToNode({150, 90}, subnodes[2]);
|
||||
NSArray *subnodes = defaultSubnodes();
|
||||
((ASStaticSizeDisplayNode *)subnodes[0]).staticSize = {50, 50};
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {100, 70};
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).staticSize = {150, 90};
|
||||
|
||||
subnodes[0].spacingBefore = 0;
|
||||
subnodes[1].spacingBefore = 20;
|
||||
subnodes[2].spacingBefore = 30;
|
||||
((ASStaticSizeDisplayNode *)subnodes[0]).spacingBefore = 0;
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).spacingBefore = 20;
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).spacingBefore = 30;
|
||||
|
||||
static ASSizeRange kVariableSize = {{200, 200}, {300, 300}};
|
||||
// all children should be 200px wide
|
||||
@@ -471,14 +467,14 @@ static void setCGSizeToNode(CGSize size, ASDisplayNode *node)
|
||||
.alignItems = ASStackLayoutAlignItemsStretch
|
||||
};
|
||||
|
||||
NSArray<ASDisplayNode *> *subnodes = defaultSubnodes();
|
||||
setCGSizeToNode({50, 50}, subnodes[0]);
|
||||
setCGSizeToNode({100, 70}, subnodes[1]);
|
||||
setCGSizeToNode({150, 90}, subnodes[2]);
|
||||
NSArray *subnodes = defaultSubnodes();
|
||||
((ASStaticSizeDisplayNode *)subnodes[0]).staticSize = {50, 50};
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {100, 70};
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).staticSize = {150, 90};
|
||||
|
||||
subnodes[0].spacingBefore = 0;
|
||||
subnodes[1].spacingBefore = 20;
|
||||
subnodes[2].spacingBefore = 30;
|
||||
((ASStaticSizeDisplayNode *)subnodes[0]).spacingBefore = 0;
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).spacingBefore = 20;
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).spacingBefore = 30;
|
||||
|
||||
static ASSizeRange kVariableSize = {{50, 50}, {300, 300}};
|
||||
// all children should be 150px wide
|
||||
@@ -495,12 +491,12 @@ static void setCGSizeToNode(CGSize size, ASDisplayNode *node)
|
||||
{
|
||||
ASStackLayoutSpecStyle style = {.direction = ASStackLayoutDirectionHorizontal};
|
||||
|
||||
NSArray<ASDisplayNode *> *subnodes = defaultSubnodesWithSameSize({50, 50}, NO);
|
||||
setCGSizeToNode({150, 150}, subnodes[1]);
|
||||
NSArray *subnodes = defaultSubnodesWithSameSize({50, 50}, NO);
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {150, 150};
|
||||
|
||||
for (ASDisplayNode *subnode in subnodes) {
|
||||
for (ASStaticSizeDisplayNode *subnode in subnodes) {
|
||||
subnode.flexGrow = YES;
|
||||
subnode.flexBasis = ASDimensionMakeWithPoints(10);
|
||||
subnode.flexBasis = ASRelativeDimensionMakeWithPoints(10);
|
||||
}
|
||||
|
||||
// width 300px; height 0-150px.
|
||||
@@ -516,14 +512,15 @@ static void setCGSizeToNode(CGSize size, ASDisplayNode *node)
|
||||
{
|
||||
ASStackLayoutSpecStyle style = {.direction = ASStackLayoutDirectionHorizontal};
|
||||
|
||||
NSArray<ASDisplayNode *> *subnodes = defaultSubnodesWithSameSize({50, 50}, NO);
|
||||
for (ASDisplayNode *subnode in subnodes) {
|
||||
NSArray *subnodes = defaultSubnodesWithSameSize({50, 50}, NO);
|
||||
|
||||
for (ASStaticSizeDisplayNode *subnode in subnodes) {
|
||||
subnode.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.
|
||||
subnodes[0].flexBasis = ASDimensionMakeWithFraction(0.5);
|
||||
((ASStaticSizeDisplayNode *)subnodes[0]).flexBasis = ASRelativeDimensionMakeWithFraction(0.5);
|
||||
|
||||
static ASSizeRange kSize = {{200, 0}, {200, INFINITY}};
|
||||
[self testStackLayoutSpecWithStyle:style sizeRange:kSize subnodes:subnodes identifier:nil];
|
||||
@@ -533,13 +530,13 @@ static void setCGSizeToNode(CGSize size, ASDisplayNode *node)
|
||||
{
|
||||
ASStackLayoutSpecStyle style = {.direction = ASStackLayoutDirectionHorizontal};
|
||||
|
||||
NSArray<ASDisplayNode *> *subnodes = defaultSubnodes();
|
||||
setCGSizeToNode({50, 50}, subnodes[0]);
|
||||
setCGSizeToNode({150, 150}, subnodes[1]);
|
||||
setCGSizeToNode({150, 50}, subnodes[2]);
|
||||
NSArray *subnodes = defaultSubnodes();
|
||||
((ASStaticSizeDisplayNode *)subnodes[0]).staticSize = {50, 50};
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {150, 150};
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).staticSize = {50, 50};
|
||||
|
||||
for (ASDisplayNode *subnode in subnodes) {
|
||||
subnode.flexBasis = ASDimensionMakeWithPoints(20);
|
||||
for (ASStaticSizeDisplayNode *subnode in subnodes) {
|
||||
subnode.flexBasis = ASRelativeDimensionMakeWithPoints(20);
|
||||
}
|
||||
|
||||
static ASSizeRange kSize = {{300, 0}, {300, 150}};
|
||||
@@ -548,11 +545,13 @@ static void setCGSizeToNode(CGSize size, ASDisplayNode *node)
|
||||
|
||||
- (void)testCrossAxisStretchingOccursAfterStackAxisFlexing
|
||||
{
|
||||
NSArray<ASDisplayNode *> *subnodes = @[
|
||||
ASDisplayNodeWithBackgroundColor([UIColor greenColor]),
|
||||
ASDisplayNodeWithBackgroundColor([UIColor blueColor], {10, 0}),
|
||||
ASDisplayNodeWithBackgroundColor([UIColor redColor], {3000, 3000})
|
||||
];
|
||||
NSArray *subnodes = @[
|
||||
ASDisplayNodeWithBackgroundColor([UIColor greenColor]),
|
||||
ASDisplayNodeWithBackgroundColor([UIColor blueColor]),
|
||||
ASDisplayNodeWithBackgroundColor([UIColor redColor])
|
||||
];
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {10, 0};
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).staticSize = {3000, 3000};
|
||||
|
||||
ASRatioLayoutSpec *child2 = [ASRatioLayoutSpec ratioLayoutSpecWithRatio:1.0 child:subnodes[2]];
|
||||
child2.flexGrow = YES;
|
||||
@@ -566,12 +565,7 @@ static void setCGSizeToNode(CGSize size, ASDisplayNode *node)
|
||||
[ASInsetLayoutSpec
|
||||
insetLayoutSpecWithInsets:UIEdgeInsetsMake(10, 10, 10, 10)
|
||||
child:
|
||||
[ASStackLayoutSpec
|
||||
stackLayoutSpecWithDirection:ASStackLayoutDirectionHorizontal
|
||||
spacing:0
|
||||
justifyContent:ASStackLayoutJustifyContentStart
|
||||
alignItems:ASStackLayoutAlignItemsStretch
|
||||
children:@[subnodes[1], child2]]
|
||||
[ASStackLayoutSpec stackLayoutSpecWithDirection:ASStackLayoutDirectionHorizontal spacing:0 justifyContent:ASStackLayoutJustifyContentStart alignItems:ASStackLayoutAlignItemsStretch children:@[subnodes[1], child2,]]
|
||||
]
|
||||
background:subnodes[0]];
|
||||
|
||||
@@ -582,16 +576,17 @@ static void setCGSizeToNode(CGSize size, ASDisplayNode *node)
|
||||
- (void)testViolationIsDistributedEquallyAmongFlexibleChildren
|
||||
{
|
||||
ASStackLayoutSpecStyle style = {.direction = ASStackLayoutDirectionHorizontal};
|
||||
|
||||
NSArray<ASDisplayNode *> *subnodes = defaultSubnodes();
|
||||
|
||||
setCGSizeToNode({300, 50}, subnodes[0]);
|
||||
setCGSizeToNode({100, 50}, subnodes[1]);
|
||||
setCGSizeToNode({200, 50}, subnodes[2]);
|
||||
NSArray *subnodes = defaultSubnodes();
|
||||
|
||||
subnodes[0].flexShrink = YES;
|
||||
subnodes[1].flexShrink = NO;
|
||||
subnodes[2].flexShrink = YES;
|
||||
((ASStaticSizeDisplayNode *)subnodes[0]).staticSize = {300, 50};
|
||||
((ASStaticSizeDisplayNode *)subnodes[0]).flexShrink = YES;
|
||||
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {100, 50};
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).flexShrink = NO;
|
||||
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).staticSize = {200, 50};
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).flexShrink = YES;
|
||||
|
||||
// A width of 400px results in a violation of 200px. This is distributed equally among each flexible child,
|
||||
// causing both of them to be shrunk by 100px, resulting in widths of 300px, 100px, and 50px.
|
||||
|
||||
Reference in New Issue
Block a user