mirror of
https://github.com/HackPlan/AsyncDisplayKit.git
synced 2026-04-24 03:45:58 +08:00
[Layout] Layout API based on content area (#2110)
* Initial commit for adding a size constraint to ASLayoutable's * Some more commits * Fix sample projects in extra/ * Remove preferredFrameSize test of ASEditableTextNode * Remove preferredFrameSize from examples_extra * Add deprecation warning to -[ASDisplayNode preferredFrameSize] * Add deprecation warning to -[ASDisplayNode measureWithSizeRange:] * Commit * Commit * Remove ASRelativeSizeRange * Make ASRelativeSize private * Adjust examples * Improve setting of -[ASLayoutable size] with points or fractions * Add ASWrapperLayoutSpec * Improve creation of ASRelativeDimension * Add `preferredFrameSize` back and add deprecated logging * Add `layoutSpecBlock` setter and getter and add locking for it * Add better documentation and fix macros to create ASRelativeDimension * Create new ASSizeRangeMake with just a CGSize as parameter * Update Kitten and Social App Layout example * Add layoutThatFits: and deprecate measure: * Rename ASRelativeDimension to ASDimension * Fix examples for ASDimension renaming * Remove fancy height and width setter * Fix ASDimension helper * Rename -[ASLayout layoutableObject] to -[ASLayout layoutable] * Update layout related methods and more clearer documentation around how to use it * Deprecate old ASLayout class constructors * Don't unnecessary recalculate layout if constrained or parent size did not change * Use shared pointer for ASDisplayNodeLayout * Fix rebase conflicts * Add documentation and move implementation in mm file of ASDisplayNodeLayout * Fix test errors * Rename ASSize to ASLayoutableSize * Address comments * Rename setSizeFromCGSize to setSizeWithCGSize * Improve inline functions in ASDimension * Fix rebase conflicts
This commit is contained in:
committed by
Adlai Holler
parent
2bfeb6de92
commit
8897614f0e
@@ -23,26 +23,31 @@
|
||||
|
||||
#pragma mark - Utility methods
|
||||
|
||||
static NSArray *defaultSubnodes()
|
||||
static NSArray<ASDisplayNode *> *defaultSubnodes()
|
||||
{
|
||||
return defaultSubnodesWithSameSize(CGSizeZero, NO);
|
||||
}
|
||||
|
||||
static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize, BOOL flex)
|
||||
static NSArray<ASDisplayNode *> *defaultSubnodesWithSameSize(CGSize subnodeSize, BOOL flex)
|
||||
{
|
||||
NSArray *subnodes = @[
|
||||
ASDisplayNodeWithBackgroundColor([UIColor redColor]),
|
||||
ASDisplayNodeWithBackgroundColor([UIColor blueColor]),
|
||||
ASDisplayNodeWithBackgroundColor([UIColor greenColor])
|
||||
];
|
||||
for (ASStaticSizeDisplayNode *subnode in subnodes) {
|
||||
subnode.staticSize = subnodeSize;
|
||||
NSArray<ASDisplayNode *> *subnodes = @[
|
||||
ASDisplayNodeWithBackgroundColor([UIColor redColor], subnodeSize),
|
||||
ASDisplayNodeWithBackgroundColor([UIColor blueColor], subnodeSize),
|
||||
ASDisplayNodeWithBackgroundColor([UIColor greenColor], subnodeSize)
|
||||
];
|
||||
for (ASDisplayNode *subnode in subnodes) {
|
||||
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
|
||||
@@ -53,7 +58,7 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize, BOOL flex)
|
||||
.justifyContent = justify
|
||||
};
|
||||
|
||||
NSArray *subnodes = defaultSubnodesWithSameSize({50, 50}, flex);
|
||||
NSArray<ASDisplayNode *> *subnodes = defaultSubnodesWithSameSize({50, 50}, flex);
|
||||
|
||||
[self testStackLayoutSpecWithStyle:style sizeRange:sizeRange subnodes:subnodes identifier:identifier];
|
||||
}
|
||||
@@ -63,13 +68,13 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize, BOOL flex)
|
||||
itemsVerticalAlignment:(ASVerticalAlignment)verticalAlignment
|
||||
identifier:(NSString *)identifier
|
||||
{
|
||||
NSArray *subnodes = defaultSubnodesWithSameSize({50, 50}, NO);
|
||||
NSArray<ASDisplayNode *> *subnodes = defaultSubnodesWithSameSize({50, 50}, NO);
|
||||
|
||||
ASStackLayoutSpec *stackLayoutSpec = [[ASStackLayoutSpec alloc] init];
|
||||
stackLayoutSpec.direction = direction;
|
||||
stackLayoutSpec.children = subnodes;
|
||||
[stackLayoutSpec setHorizontalAlignment:horizontalAlignment];
|
||||
[stackLayoutSpec setVerticalAlignment:verticalAlignment];
|
||||
stackLayoutSpec.horizontalAlignment = horizontalAlignment;
|
||||
stackLayoutSpec.verticalAlignment = verticalAlignment;
|
||||
|
||||
CGSize exactSize = CGSizeMake(200, 200);
|
||||
static ASSizeRange kSize = ASSizeRangeMake(exactSize, exactSize);
|
||||
@@ -90,11 +95,14 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize, BOOL flex)
|
||||
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];
|
||||
}
|
||||
|
||||
@@ -104,7 +112,6 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize, BOOL flex)
|
||||
identifier:(NSString *)identifier
|
||||
{
|
||||
ASDisplayNode *backgroundNode = ASDisplayNodeWithBackgroundColor([UIColor whiteColor]);
|
||||
|
||||
ASLayoutSpec *layoutSpec = [ASBackgroundLayoutSpec backgroundLayoutSpecWithChild:stackLayoutSpec background:backgroundNode];
|
||||
|
||||
NSMutableArray *newSubnodes = [NSMutableArray arrayWithObject:backgroundNode];
|
||||
@@ -145,8 +152,8 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize, BOOL flex)
|
||||
{
|
||||
ASStackLayoutSpecStyle style = {.direction = ASStackLayoutDirectionHorizontal};
|
||||
|
||||
NSArray *subnodes = defaultSubnodesWithSameSize({50, 50}, NO);
|
||||
((ASDisplayNode *)subnodes[1]).flexShrink = YES;
|
||||
NSArray<ASDisplayNode *> *subnodes = defaultSubnodesWithSameSize({50, 50}, NO);
|
||||
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}};
|
||||
@@ -157,8 +164,8 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize, BOOL flex)
|
||||
{
|
||||
ASStackLayoutSpecStyle style = {.direction = ASStackLayoutDirectionHorizontal};
|
||||
|
||||
NSArray *subnodes = defaultSubnodesWithSameSize({50, 50}, YES);
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {150, 150};
|
||||
NSArray<ASDisplayNode *> *subnodes = defaultSubnodesWithSameSize({50, 50}, YES);
|
||||
setCGSizeToNode({150, 150}, subnodes[1]);
|
||||
|
||||
// width 300px; height 0-150px.
|
||||
static ASSizeRange kUnderflowSize = {{300, 0}, {300, 150}};
|
||||
@@ -173,10 +180,10 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize, BOOL flex)
|
||||
{
|
||||
ASStackLayoutSpecStyle style = {.direction = ASStackLayoutDirectionVertical};
|
||||
|
||||
NSArray *subnodes = defaultSubnodes();
|
||||
((ASStaticSizeDisplayNode *)subnodes[0]).staticSize = {50, 50};
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {100, 50};
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).staticSize = {150, 50};
|
||||
NSArray<ASDisplayNode *> *subnodes = defaultSubnodes();
|
||||
setCGSizeToNode({50, 50}, subnodes[0]);
|
||||
setCGSizeToNode({100, 50}, subnodes[1]);
|
||||
setCGSizeToNode({150, 50}, subnodes[2]);
|
||||
|
||||
// width 0-300px; height 300px
|
||||
static ASSizeRange kVariableHeight = {{0, 300}, {300, 300}};
|
||||
@@ -194,10 +201,10 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize, BOOL flex)
|
||||
.spacing = 10
|
||||
};
|
||||
|
||||
NSArray *subnodes = defaultSubnodes();
|
||||
((ASStaticSizeDisplayNode *)subnodes[0]).staticSize = {50, 50};
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {100, 50};
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).staticSize = {150, 50};
|
||||
NSArray<ASDisplayNode *> *subnodes = defaultSubnodes();
|
||||
setCGSizeToNode({50, 50}, subnodes[0]);
|
||||
setCGSizeToNode({100, 50}, subnodes[1]);
|
||||
setCGSizeToNode({150, 50}, subnodes[2]);
|
||||
|
||||
// width 0-300px; height 300px
|
||||
static ASSizeRange kVariableHeight = {{0, 300}, {300, 300}};
|
||||
@@ -212,12 +219,16 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize, BOOL flex)
|
||||
|
||||
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
|
||||
@@ -231,28 +242,28 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize, BOOL flex)
|
||||
static ASSizeRange kAnySize = {{0, 0}, {INFINITY, INFINITY}};
|
||||
ASStackLayoutSpecStyle style = {.direction = ASStackLayoutDirectionVertical};
|
||||
|
||||
NSArray *subnodes = defaultSubnodes();
|
||||
((ASStaticSizeDisplayNode *)subnodes[0]).staticSize = {50, 50};
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {100, 70};
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).staticSize = {150, 90};
|
||||
NSArray<ASDisplayNode *> *subnodes = defaultSubnodes();
|
||||
setCGSizeToNode({50, 50}, subnodes[0]);
|
||||
setCGSizeToNode({100, 70}, subnodes[1]);
|
||||
setCGSizeToNode({150, 90}, subnodes[2]);
|
||||
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).spacingBefore = 10;
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).spacingBefore = 20;
|
||||
subnodes[1].spacingBefore = 10;
|
||||
subnodes[2].spacingBefore = 20;
|
||||
[self testStackLayoutSpecWithStyle:style sizeRange:kAnySize subnodes:subnodes identifier:@"spacingBefore"];
|
||||
// Reset above spacing values
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).spacingBefore = 0;
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).spacingBefore = 0;
|
||||
subnodes[1].spacingBefore = 0;
|
||||
subnodes[2].spacingBefore = 0;
|
||||
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).spacingAfter = 10;
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).spacingAfter = 20;
|
||||
subnodes[1].spacingAfter = 10;
|
||||
subnodes[2].spacingAfter = 20;
|
||||
[self testStackLayoutSpecWithStyle:style sizeRange:kAnySize subnodes:subnodes identifier:@"spacingAfter"];
|
||||
// Reset above spacing values
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).spacingAfter = 0;
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).spacingAfter = 0;
|
||||
subnodes[1].spacingAfter = 0;
|
||||
subnodes[2].spacingAfter = 0;
|
||||
|
||||
style.spacing = 10;
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).spacingBefore = -10;
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).spacingAfter = -10;
|
||||
subnodes[1].spacingBefore = -10;
|
||||
subnodes[1].spacingAfter = -10;
|
||||
[self testStackLayoutSpecWithStyle:style sizeRange:kAnySize subnodes:subnodes identifier:@"spacingBalancedOut"];
|
||||
}
|
||||
|
||||
@@ -263,14 +274,14 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize, BOOL flex)
|
||||
.justifyContent = ASStackLayoutJustifyContentCenter
|
||||
};
|
||||
|
||||
NSArray *subnodes = defaultSubnodes();
|
||||
((ASStaticSizeDisplayNode *)subnodes[0]).staticSize = {50, 50};
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {100, 70};
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).staticSize = {150, 90};
|
||||
NSArray<ASDisplayNode *> *subnodes = defaultSubnodes();
|
||||
setCGSizeToNode({50, 50}, subnodes[0]);
|
||||
setCGSizeToNode({100, 70}, subnodes[1]);
|
||||
setCGSizeToNode({150, 90}, subnodes[2]);
|
||||
|
||||
((ASStaticSizeDisplayNode *)subnodes[0]).spacingBefore = 0;
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).spacingBefore = 20;
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).spacingBefore = 30;
|
||||
subnodes[0].spacingBefore = 0;
|
||||
subnodes[1].spacingBefore = 20;
|
||||
subnodes[2].spacingBefore = 30;
|
||||
|
||||
// width 0-300px; height 300px
|
||||
static ASSizeRange kVariableHeight = {{0, 300}, {300, 300}};
|
||||
@@ -284,8 +295,7 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize, BOOL flex)
|
||||
.justifyContent = ASStackLayoutJustifyContentSpaceBetween
|
||||
};
|
||||
|
||||
ASStaticSizeDisplayNode *child = ASDisplayNodeWithBackgroundColor([UIColor redColor]);
|
||||
child.staticSize = {50, 50};
|
||||
ASDisplayNode *child = ASDisplayNodeWithBackgroundColor([UIColor redColor], {50, 50});
|
||||
|
||||
// width 300px; height 0-INF
|
||||
static ASSizeRange kVariableHeight = {{300, 0}, {300, INFINITY}};
|
||||
@@ -299,8 +309,7 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize, BOOL flex)
|
||||
.justifyContent = ASStackLayoutJustifyContentSpaceAround
|
||||
};
|
||||
|
||||
ASStaticSizeDisplayNode *child = ASDisplayNodeWithBackgroundColor([UIColor redColor]);
|
||||
child.staticSize = {50, 50};
|
||||
ASDisplayNode *child = ASDisplayNodeWithBackgroundColor([UIColor redColor], {50, 50});
|
||||
|
||||
// width 300px; height 0-INF
|
||||
static ASSizeRange kVariableHeight = {{300, 0}, {300, INFINITY}};
|
||||
@@ -325,12 +334,11 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize, BOOL flex)
|
||||
{
|
||||
ASStackLayoutSpecStyle style = {.direction = ASStackLayoutDirectionHorizontal};
|
||||
|
||||
ASStaticSizeDisplayNode * subnode1 = ASDisplayNodeWithBackgroundColor([UIColor blueColor]);
|
||||
ASStaticSizeDisplayNode * subnode2 = ASDisplayNodeWithBackgroundColor([UIColor redColor]);
|
||||
subnode2.staticSize = {50, 50};
|
||||
ASDisplayNode * subnode1 = ASDisplayNodeWithBackgroundColor([UIColor blueColor]);
|
||||
ASDisplayNode * subnode2 = ASDisplayNodeWithBackgroundColor([UIColor redColor], {50, 50});
|
||||
|
||||
ASRatioLayoutSpec *child1 = [ASRatioLayoutSpec ratioLayoutSpecWithRatio:1.5 child:subnode1];
|
||||
child1.flexBasis = ASRelativeDimensionMakeWithFraction(1);
|
||||
child1.flexBasis = ASDimensionMakeWithFraction(1);
|
||||
child1.flexGrow = YES;
|
||||
child1.flexShrink = YES;
|
||||
|
||||
@@ -345,15 +353,13 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize, BOOL flex)
|
||||
.alignItems = ASStackLayoutAlignItemsCenter
|
||||
};
|
||||
|
||||
ASStaticSizeDisplayNode *subnode1 = ASDisplayNodeWithBackgroundColor([UIColor redColor]);
|
||||
subnode1.staticSize = {100, 100};
|
||||
ASDisplayNode *subnode1 = ASDisplayNodeWithBackgroundColor([UIColor redColor], {100, 100});
|
||||
subnode1.flexShrink = YES;
|
||||
|
||||
ASStaticSizeDisplayNode *subnode2 = ASDisplayNodeWithBackgroundColor([UIColor blueColor]);
|
||||
subnode2.staticSize = {50, 50};
|
||||
ASDisplayNode *subnode2 = ASDisplayNodeWithBackgroundColor([UIColor blueColor], {50, 50});
|
||||
subnode2.flexShrink = YES;
|
||||
|
||||
NSArray *subnodes = @[subnode1, subnode2];
|
||||
NSArray<ASDisplayNode *> *subnodes = @[subnode1, subnode2];
|
||||
static ASSizeRange kFixedWidth = {{150, 0}, {150, 100}};
|
||||
[self testStackLayoutSpecWithStyle:style sizeRange:kFixedWidth subnodes:subnodes identifier:nil];
|
||||
}
|
||||
@@ -362,14 +368,12 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize, BOOL flex)
|
||||
{
|
||||
ASStackLayoutSpecStyle style = {.direction = ASStackLayoutDirectionHorizontal};
|
||||
|
||||
ASStaticSizeDisplayNode *subnode1 = ASDisplayNodeWithBackgroundColor([UIColor redColor]);
|
||||
subnode1.staticSize = {100, 100};
|
||||
ASDisplayNode *subnode1 = ASDisplayNodeWithBackgroundColor([UIColor redColor], {100, 100});
|
||||
|
||||
ASStaticSizeDisplayNode *subnode2 = ASDisplayNodeWithBackgroundColor([UIColor blueColor]);
|
||||
subnode2.staticSize = {50, 50};
|
||||
ASDisplayNode *subnode2 = ASDisplayNodeWithBackgroundColor([UIColor blueColor], {50, 50});
|
||||
subnode2.alignSelf = ASStackLayoutAlignSelfCenter;
|
||||
|
||||
NSArray *subnodes = @[subnode1, subnode2];
|
||||
NSArray<ASDisplayNode *> *subnodes = @[subnode1, subnode2];
|
||||
static ASSizeRange kFixedWidth = {{150, 0}, {150, INFINITY}};
|
||||
[self testStackLayoutSpecWithStyle:style sizeRange:kFixedWidth subnodes:subnodes identifier:nil];
|
||||
}
|
||||
@@ -382,14 +386,14 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize, BOOL flex)
|
||||
.alignItems = ASStackLayoutAlignItemsStart
|
||||
};
|
||||
|
||||
NSArray *subnodes = defaultSubnodes();
|
||||
((ASStaticSizeDisplayNode *)subnodes[0]).staticSize = {50, 50};
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {100, 70};
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).staticSize = {150, 90};
|
||||
NSArray<ASDisplayNode *> *subnodes = defaultSubnodes();
|
||||
setCGSizeToNode({50, 50}, subnodes[0]);
|
||||
setCGSizeToNode({100, 70}, subnodes[1]);
|
||||
setCGSizeToNode({150, 90}, subnodes[2]);
|
||||
|
||||
((ASStaticSizeDisplayNode *)subnodes[0]).spacingBefore = 0;
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).spacingBefore = 20;
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).spacingBefore = 30;
|
||||
subnodes[0].spacingBefore = 0;
|
||||
subnodes[1].spacingBefore = 20;
|
||||
subnodes[2].spacingBefore = 30;
|
||||
|
||||
static ASSizeRange kExactSize = {{300, 300}, {300, 300}};
|
||||
[self testStackLayoutSpecWithStyle:style sizeRange:kExactSize subnodes:subnodes identifier:nil];
|
||||
@@ -403,14 +407,14 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize, BOOL flex)
|
||||
.alignItems = ASStackLayoutAlignItemsEnd
|
||||
};
|
||||
|
||||
NSArray *subnodes = defaultSubnodes();
|
||||
((ASStaticSizeDisplayNode *)subnodes[0]).staticSize = {50, 50};
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {100, 70};
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).staticSize = {150, 90};
|
||||
NSArray<ASDisplayNode *> *subnodes = defaultSubnodes();
|
||||
setCGSizeToNode({50, 50}, subnodes[0]);
|
||||
setCGSizeToNode({100, 70}, subnodes[1]);
|
||||
setCGSizeToNode({150, 90}, subnodes[2]);
|
||||
|
||||
((ASStaticSizeDisplayNode *)subnodes[0]).spacingBefore = 0;
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).spacingBefore = 20;
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).spacingBefore = 30;
|
||||
subnodes[0].spacingBefore = 0;
|
||||
subnodes[1].spacingBefore = 20;
|
||||
subnodes[2].spacingBefore = 30;
|
||||
|
||||
static ASSizeRange kExactSize = {{300, 300}, {300, 300}};
|
||||
[self testStackLayoutSpecWithStyle:style sizeRange:kExactSize subnodes:subnodes identifier:nil];
|
||||
@@ -424,14 +428,14 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize, BOOL flex)
|
||||
.alignItems = ASStackLayoutAlignItemsCenter
|
||||
};
|
||||
|
||||
NSArray *subnodes = defaultSubnodes();
|
||||
((ASStaticSizeDisplayNode *)subnodes[0]).staticSize = {50, 50};
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {100, 70};
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).staticSize = {150, 90};
|
||||
NSArray<ASDisplayNode *> *subnodes = defaultSubnodes();
|
||||
setCGSizeToNode({50, 50}, subnodes[0]);
|
||||
setCGSizeToNode({100, 70}, subnodes[1]);
|
||||
setCGSizeToNode({150, 90}, subnodes[2]);
|
||||
|
||||
((ASStaticSizeDisplayNode *)subnodes[0]).spacingBefore = 0;
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).spacingBefore = 20;
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).spacingBefore = 30;
|
||||
subnodes[0].spacingBefore = 0;
|
||||
subnodes[1].spacingBefore = 20;
|
||||
subnodes[2].spacingBefore = 30;
|
||||
|
||||
static ASSizeRange kExactSize = {{300, 300}, {300, 300}};
|
||||
[self testStackLayoutSpecWithStyle:style sizeRange:kExactSize subnodes:subnodes identifier:nil];
|
||||
@@ -445,14 +449,14 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize, BOOL flex)
|
||||
.alignItems = ASStackLayoutAlignItemsStretch
|
||||
};
|
||||
|
||||
NSArray *subnodes = defaultSubnodes();
|
||||
((ASStaticSizeDisplayNode *)subnodes[0]).staticSize = {50, 50};
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {100, 70};
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).staticSize = {150, 90};
|
||||
NSArray<ASDisplayNode *> *subnodes = defaultSubnodes();
|
||||
setCGSizeToNode({50, 50}, subnodes[0]);
|
||||
setCGSizeToNode({100, 70}, subnodes[1]);
|
||||
setCGSizeToNode({150, 90}, subnodes[2]);
|
||||
|
||||
((ASStaticSizeDisplayNode *)subnodes[0]).spacingBefore = 0;
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).spacingBefore = 20;
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).spacingBefore = 30;
|
||||
subnodes[0].spacingBefore = 0;
|
||||
subnodes[1].spacingBefore = 20;
|
||||
subnodes[2].spacingBefore = 30;
|
||||
|
||||
static ASSizeRange kVariableSize = {{200, 200}, {300, 300}};
|
||||
// all children should be 200px wide
|
||||
@@ -467,14 +471,14 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize, BOOL flex)
|
||||
.alignItems = ASStackLayoutAlignItemsStretch
|
||||
};
|
||||
|
||||
NSArray *subnodes = defaultSubnodes();
|
||||
((ASStaticSizeDisplayNode *)subnodes[0]).staticSize = {50, 50};
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {100, 70};
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).staticSize = {150, 90};
|
||||
NSArray<ASDisplayNode *> *subnodes = defaultSubnodes();
|
||||
setCGSizeToNode({50, 50}, subnodes[0]);
|
||||
setCGSizeToNode({100, 70}, subnodes[1]);
|
||||
setCGSizeToNode({150, 90}, subnodes[2]);
|
||||
|
||||
((ASStaticSizeDisplayNode *)subnodes[0]).spacingBefore = 0;
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).spacingBefore = 20;
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).spacingBefore = 30;
|
||||
subnodes[0].spacingBefore = 0;
|
||||
subnodes[1].spacingBefore = 20;
|
||||
subnodes[2].spacingBefore = 30;
|
||||
|
||||
static ASSizeRange kVariableSize = {{50, 50}, {300, 300}};
|
||||
// all children should be 150px wide
|
||||
@@ -491,12 +495,12 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize, BOOL flex)
|
||||
{
|
||||
ASStackLayoutSpecStyle style = {.direction = ASStackLayoutDirectionHorizontal};
|
||||
|
||||
NSArray *subnodes = defaultSubnodesWithSameSize({50, 50}, NO);
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {150, 150};
|
||||
NSArray<ASDisplayNode *> *subnodes = defaultSubnodesWithSameSize({50, 50}, NO);
|
||||
setCGSizeToNode({150, 150}, subnodes[1]);
|
||||
|
||||
for (ASStaticSizeDisplayNode *subnode in subnodes) {
|
||||
for (ASDisplayNode *subnode in subnodes) {
|
||||
subnode.flexGrow = YES;
|
||||
subnode.flexBasis = ASRelativeDimensionMakeWithPoints(10);
|
||||
subnode.flexBasis = ASDimensionMakeWithPoints(10);
|
||||
}
|
||||
|
||||
// width 300px; height 0-150px.
|
||||
@@ -512,15 +516,14 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize, BOOL flex)
|
||||
{
|
||||
ASStackLayoutSpecStyle style = {.direction = ASStackLayoutDirectionHorizontal};
|
||||
|
||||
NSArray *subnodes = defaultSubnodesWithSameSize({50, 50}, NO);
|
||||
|
||||
for (ASStaticSizeDisplayNode *subnode in subnodes) {
|
||||
NSArray<ASDisplayNode *> *subnodes = defaultSubnodesWithSameSize({50, 50}, NO);
|
||||
for (ASDisplayNode *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.
|
||||
((ASStaticSizeDisplayNode *)subnodes[0]).flexBasis = ASRelativeDimensionMakeWithFraction(0.5);
|
||||
subnodes[0].flexBasis = ASDimensionMakeWithFraction(0.5);
|
||||
|
||||
static ASSizeRange kSize = {{200, 0}, {200, INFINITY}};
|
||||
[self testStackLayoutSpecWithStyle:style sizeRange:kSize subnodes:subnodes identifier:nil];
|
||||
@@ -530,13 +533,13 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize, BOOL flex)
|
||||
{
|
||||
ASStackLayoutSpecStyle style = {.direction = ASStackLayoutDirectionHorizontal};
|
||||
|
||||
NSArray *subnodes = defaultSubnodes();
|
||||
((ASStaticSizeDisplayNode *)subnodes[0]).staticSize = {50, 50};
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {150, 150};
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).staticSize = {50, 50};
|
||||
NSArray<ASDisplayNode *> *subnodes = defaultSubnodes();
|
||||
setCGSizeToNode({50, 50}, subnodes[0]);
|
||||
setCGSizeToNode({150, 150}, subnodes[1]);
|
||||
setCGSizeToNode({150, 50}, subnodes[2]);
|
||||
|
||||
for (ASStaticSizeDisplayNode *subnode in subnodes) {
|
||||
subnode.flexBasis = ASRelativeDimensionMakeWithPoints(20);
|
||||
for (ASDisplayNode *subnode in subnodes) {
|
||||
subnode.flexBasis = ASDimensionMakeWithPoints(20);
|
||||
}
|
||||
|
||||
static ASSizeRange kSize = {{300, 0}, {300, 150}};
|
||||
@@ -545,13 +548,11 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize, BOOL flex)
|
||||
|
||||
- (void)testCrossAxisStretchingOccursAfterStackAxisFlexing
|
||||
{
|
||||
NSArray *subnodes = @[
|
||||
ASDisplayNodeWithBackgroundColor([UIColor greenColor]),
|
||||
ASDisplayNodeWithBackgroundColor([UIColor blueColor]),
|
||||
ASDisplayNodeWithBackgroundColor([UIColor redColor])
|
||||
];
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {10, 0};
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).staticSize = {3000, 3000};
|
||||
NSArray<ASDisplayNode *> *subnodes = @[
|
||||
ASDisplayNodeWithBackgroundColor([UIColor greenColor]),
|
||||
ASDisplayNodeWithBackgroundColor([UIColor blueColor], {10, 0}),
|
||||
ASDisplayNodeWithBackgroundColor([UIColor redColor], {3000, 3000})
|
||||
];
|
||||
|
||||
ASRatioLayoutSpec *child2 = [ASRatioLayoutSpec ratioLayoutSpecWithRatio:1.0 child:subnodes[2]];
|
||||
child2.flexGrow = YES;
|
||||
@@ -565,7 +566,12 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize, BOOL flex)
|
||||
[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]];
|
||||
|
||||
@@ -576,17 +582,16 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize, BOOL flex)
|
||||
- (void)testViolationIsDistributedEquallyAmongFlexibleChildren
|
||||
{
|
||||
ASStackLayoutSpecStyle style = {.direction = ASStackLayoutDirectionHorizontal};
|
||||
|
||||
NSArray<ASDisplayNode *> *subnodes = defaultSubnodes();
|
||||
|
||||
NSArray *subnodes = defaultSubnodes();
|
||||
setCGSizeToNode({300, 50}, subnodes[0]);
|
||||
setCGSizeToNode({100, 50}, subnodes[1]);
|
||||
setCGSizeToNode({200, 50}, subnodes[2]);
|
||||
|
||||
((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;
|
||||
subnodes[0].flexShrink = YES;
|
||||
subnodes[1].flexShrink = NO;
|
||||
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