mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2026-01-23 04:28:53 +00:00
Hide ASLayoutOptions from the user
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
#import "ASBackgroundLayoutSpec.h"
|
||||
#import "ASRatioLayoutSpec.h"
|
||||
#import "ASInsetLayoutSpec.h"
|
||||
#import "ASLayoutOptions.h"
|
||||
|
||||
@interface ASStackLayoutSpecSnapshotTests : ASLayoutSpecSnapshotTestCase
|
||||
@end
|
||||
@@ -41,8 +42,8 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize, BOOL flex)
|
||||
];
|
||||
for (ASStaticSizeDisplayNode *subnode in subnodes) {
|
||||
subnode.staticSize = subnodeSize;
|
||||
[ASLayoutSpec layoutOptionsForChild:subnode].flexGrow = flex;
|
||||
[ASLayoutSpec layoutOptionsForChild:subnode].flexShrink = flex;
|
||||
subnode.layoutOptions.flexGrow = flex;
|
||||
subnode.layoutOptions.flexShrink = flex;
|
||||
}
|
||||
return subnodes;
|
||||
}
|
||||
@@ -114,7 +115,7 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize, BOOL flex)
|
||||
ASStackLayoutSpecStyle style = {.direction = ASStackLayoutDirectionHorizontal};
|
||||
|
||||
NSArray *subnodes = defaultSubnodesWithSameSize({50, 50}, NO);
|
||||
[ASLayoutSpec layoutOptionsForChild:((ASDisplayNode *)subnodes[1])].flexShrink = YES;
|
||||
((ASDisplayNode *)subnodes[1]).layoutOptions.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}};
|
||||
@@ -204,25 +205,23 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize, BOOL flex)
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {100, 70};
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).staticSize = {150, 90};
|
||||
|
||||
ASLayoutOptions *layoutOptions1 = [ASLayoutSpec layoutOptionsForChild:subnodes[1]];
|
||||
ASLayoutOptions *layoutOptions2 = [ASLayoutSpec layoutOptionsForChild:subnodes[2]];
|
||||
layoutOptions1.spacingBefore = 10;
|
||||
layoutOptions2.spacingBefore = 20;
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).layoutOptions.spacingBefore = 10;
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).layoutOptions.spacingBefore = 20;
|
||||
[self testStackLayoutSpecWithStyle:style sizeRange:kAnySize subnodes:subnodes identifier:@"spacingBefore"];
|
||||
// Reset above spacing values
|
||||
layoutOptions1.spacingBefore = 0;
|
||||
layoutOptions2.spacingBefore = 0;
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).layoutOptions.spacingBefore = 0;
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).layoutOptions.spacingBefore = 0;
|
||||
|
||||
layoutOptions1.spacingAfter = 10;
|
||||
layoutOptions2.spacingAfter = 20;
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).layoutOptions.spacingAfter = 10;
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).layoutOptions.spacingAfter = 20;
|
||||
[self testStackLayoutSpecWithStyle:style sizeRange:kAnySize subnodes:subnodes identifier:@"spacingAfter"];
|
||||
// Reset above spacing values
|
||||
layoutOptions1.spacingAfter = 0;
|
||||
layoutOptions2.spacingAfter = 0;
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).layoutOptions.spacingAfter = 0;
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).layoutOptions.spacingAfter = 0;
|
||||
|
||||
style.spacing = 10;
|
||||
layoutOptions1.spacingBefore = -10;
|
||||
layoutOptions2.spacingAfter = -10;
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).layoutOptions.spacingBefore = -10;
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).layoutOptions.spacingAfter = -10;
|
||||
[self testStackLayoutSpecWithStyle:style sizeRange:kAnySize subnodes:subnodes identifier:@"spacingBalancedOut"];
|
||||
}
|
||||
|
||||
@@ -238,9 +237,9 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize, BOOL flex)
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {100, 70};
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).staticSize = {150, 90};
|
||||
|
||||
[ASLayoutSpec layoutOptionsForChild:((ASStaticSizeDisplayNode *)subnodes[0])].spacingBefore = 0;
|
||||
[ASLayoutSpec layoutOptionsForChild:((ASStaticSizeDisplayNode *)subnodes[1])].spacingBefore = 20;
|
||||
[ASLayoutSpec layoutOptionsForChild:((ASStaticSizeDisplayNode *)subnodes[2])].spacingBefore = 30;
|
||||
((ASStaticSizeDisplayNode *)subnodes[0]).layoutOptions.spacingBefore = 0;
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).layoutOptions.spacingBefore = 20;
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).layoutOptions.spacingBefore = 30;
|
||||
|
||||
// width 0-300px; height 300px
|
||||
static ASSizeRange kVariableHeight = {{0, 300}, {300, 300}};
|
||||
@@ -256,10 +255,9 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize, BOOL flex)
|
||||
subnode2.staticSize = {50, 50};
|
||||
|
||||
ASRatioLayoutSpec *child1 = [ASRatioLayoutSpec ratioLayoutSpecWithRatio:1.5 child:subnode1];
|
||||
ASLayoutOptions *layoutOptions1 = [ASLayoutSpec layoutOptionsForChild:child1];
|
||||
layoutOptions1.flexBasis = ASRelativeDimensionMakeWithPercent(1);
|
||||
layoutOptions1.flexGrow = YES;
|
||||
layoutOptions1.flexShrink = YES;
|
||||
child1.layoutOptions.flexBasis = ASRelativeDimensionMakeWithPercent(1);
|
||||
child1.layoutOptions.flexGrow = YES;
|
||||
child1.layoutOptions.flexShrink = YES;
|
||||
|
||||
static ASSizeRange kFixedWidth = {{150, 0}, {150, INFINITY}};
|
||||
[self testStackLayoutSpecWithStyle:style children:@[child1, subnode2] sizeRange:kFixedWidth subnodes:@[subnode1, subnode2] identifier:nil];
|
||||
@@ -274,11 +272,11 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize, BOOL flex)
|
||||
|
||||
ASStaticSizeDisplayNode *subnode1 = ASDisplayNodeWithBackgroundColor([UIColor redColor]);
|
||||
subnode1.staticSize = {100, 100};
|
||||
[ASLayoutSpec layoutOptionsForChild:subnode1].flexShrink = YES;
|
||||
subnode1.layoutOptions.flexShrink = YES;
|
||||
|
||||
ASStaticSizeDisplayNode *subnode2 = ASDisplayNodeWithBackgroundColor([UIColor blueColor]);
|
||||
subnode2.staticSize = {50, 50};
|
||||
[ASLayoutSpec layoutOptionsForChild:subnode2].flexShrink = YES;
|
||||
subnode2.layoutOptions.flexShrink = YES;
|
||||
|
||||
NSArray *subnodes = @[subnode1, subnode2];
|
||||
static ASSizeRange kFixedWidth = {{150, 0}, {150, 100}};
|
||||
@@ -294,7 +292,7 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize, BOOL flex)
|
||||
|
||||
ASStaticSizeDisplayNode *subnode2 = ASDisplayNodeWithBackgroundColor([UIColor blueColor]);
|
||||
subnode2.staticSize = {50, 50};
|
||||
[ASLayoutSpec layoutOptionsForChild:subnode2].alignSelf = ASStackLayoutAlignSelfCenter;
|
||||
subnode2.layoutOptions.alignSelf = ASStackLayoutAlignSelfCenter;
|
||||
|
||||
NSArray *subnodes = @[subnode1, subnode2];
|
||||
static ASSizeRange kFixedWidth = {{150, 0}, {150, INFINITY}};
|
||||
@@ -314,9 +312,9 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize, BOOL flex)
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {100, 70};
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).staticSize = {150, 90};
|
||||
|
||||
[ASLayoutSpec layoutOptionsForChild:((ASStaticSizeDisplayNode *)subnodes[0])].spacingBefore = 0;
|
||||
[ASLayoutSpec layoutOptionsForChild:((ASStaticSizeDisplayNode *)subnodes[1])].spacingBefore = 20;
|
||||
[ASLayoutSpec layoutOptionsForChild:((ASStaticSizeDisplayNode *)subnodes[2])].spacingBefore = 30;
|
||||
((ASStaticSizeDisplayNode *)subnodes[0]).layoutOptions.spacingBefore = 0;
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).layoutOptions.spacingBefore = 20;
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).layoutOptions.spacingBefore = 30;
|
||||
|
||||
static ASSizeRange kExactSize = {{300, 300}, {300, 300}};
|
||||
[self testStackLayoutSpecWithStyle:style sizeRange:kExactSize subnodes:subnodes identifier:nil];
|
||||
@@ -335,9 +333,9 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize, BOOL flex)
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {100, 70};
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).staticSize = {150, 90};
|
||||
|
||||
[ASLayoutSpec layoutOptionsForChild:((ASStaticSizeDisplayNode *)subnodes[0])].spacingBefore = 0;
|
||||
[ASLayoutSpec layoutOptionsForChild:((ASStaticSizeDisplayNode *)subnodes[1])].spacingBefore = 20;
|
||||
[ASLayoutSpec layoutOptionsForChild:((ASStaticSizeDisplayNode *)subnodes[2])].spacingBefore = 30;
|
||||
((ASStaticSizeDisplayNode *)subnodes[0]).layoutOptions.spacingBefore = 0;
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).layoutOptions.spacingBefore = 20;
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).layoutOptions.spacingBefore = 30;
|
||||
|
||||
static ASSizeRange kExactSize = {{300, 300}, {300, 300}};
|
||||
[self testStackLayoutSpecWithStyle:style sizeRange:kExactSize subnodes:subnodes identifier:nil];
|
||||
@@ -356,9 +354,9 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize, BOOL flex)
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {100, 70};
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).staticSize = {150, 90};
|
||||
|
||||
[ASLayoutSpec layoutOptionsForChild:((ASStaticSizeDisplayNode *)subnodes[0])].spacingBefore = 0;
|
||||
[ASLayoutSpec layoutOptionsForChild:((ASStaticSizeDisplayNode *)subnodes[1])].spacingBefore = 20;
|
||||
[ASLayoutSpec layoutOptionsForChild:((ASStaticSizeDisplayNode *)subnodes[2])].spacingBefore = 30;
|
||||
((ASStaticSizeDisplayNode *)subnodes[0]).layoutOptions.spacingBefore = 0;
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).layoutOptions.spacingBefore = 20;
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).layoutOptions.spacingBefore = 30;
|
||||
|
||||
static ASSizeRange kExactSize = {{300, 300}, {300, 300}};
|
||||
[self testStackLayoutSpecWithStyle:style sizeRange:kExactSize subnodes:subnodes identifier:nil];
|
||||
@@ -377,9 +375,9 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize, BOOL flex)
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {100, 70};
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).staticSize = {150, 90};
|
||||
|
||||
[ASLayoutSpec layoutOptionsForChild:((ASStaticSizeDisplayNode *)subnodes[0])].spacingBefore = 0;
|
||||
[ASLayoutSpec layoutOptionsForChild:((ASStaticSizeDisplayNode *)subnodes[1])].spacingBefore = 20;
|
||||
[ASLayoutSpec layoutOptionsForChild:((ASStaticSizeDisplayNode *)subnodes[2])].spacingBefore = 30;
|
||||
((ASStaticSizeDisplayNode *)subnodes[0]).layoutOptions.spacingBefore = 0;
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).layoutOptions.spacingBefore = 20;
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).layoutOptions.spacingBefore = 30;
|
||||
|
||||
static ASSizeRange kVariableSize = {{200, 200}, {300, 300}};
|
||||
// all children should be 200px wide
|
||||
@@ -399,9 +397,9 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize, BOOL flex)
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {100, 70};
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).staticSize = {150, 90};
|
||||
|
||||
[ASLayoutSpec layoutOptionsForChild:((ASStaticSizeDisplayNode *)subnodes[0])].spacingBefore = 0;
|
||||
[ASLayoutSpec layoutOptionsForChild:((ASStaticSizeDisplayNode *)subnodes[1])].spacingBefore = 20;
|
||||
[ASLayoutSpec layoutOptionsForChild:((ASStaticSizeDisplayNode *)subnodes[2])].spacingBefore = 30;
|
||||
((ASStaticSizeDisplayNode *)subnodes[0]).layoutOptions.spacingBefore = 0;
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).layoutOptions.spacingBefore = 20;
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).layoutOptions.spacingBefore = 30;
|
||||
|
||||
static ASSizeRange kVariableSize = {{50, 50}, {300, 300}};
|
||||
// all children should be 150px wide
|
||||
@@ -422,9 +420,8 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize, BOOL flex)
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {150, 150};
|
||||
|
||||
for (ASStaticSizeDisplayNode *subnode in subnodes) {
|
||||
ASLayoutOptions *layoutOptions = [ASLayoutSpec layoutOptionsForChild:subnode];
|
||||
layoutOptions.flexGrow = YES;
|
||||
layoutOptions.flexBasis = ASRelativeDimensionMakeWithPoints(10);
|
||||
subnode.layoutOptions.flexGrow = YES;
|
||||
subnode.layoutOptions.flexBasis = ASRelativeDimensionMakeWithPoints(10);
|
||||
}
|
||||
|
||||
// width 300px; height 0-150px.
|
||||
@@ -443,12 +440,12 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize, BOOL flex)
|
||||
NSArray *subnodes = defaultSubnodesWithSameSize({50, 50}, NO);
|
||||
|
||||
for (ASStaticSizeDisplayNode *subnode in subnodes) {
|
||||
[ASLayoutSpec layoutOptionsForChild:subnode].flexGrow = YES;
|
||||
subnode.layoutOptions.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.
|
||||
[ASLayoutSpec layoutOptionsForChild:((ASStaticSizeDisplayNode *)subnodes[0])].flexBasis = ASRelativeDimensionMakeWithPercent(0.5);
|
||||
((ASStaticSizeDisplayNode *)subnodes[0]).layoutOptions.flexBasis = ASRelativeDimensionMakeWithPercent(0.5);
|
||||
|
||||
static ASSizeRange kSize = {{200, 0}, {200, INFINITY}};
|
||||
[self testStackLayoutSpecWithStyle:style sizeRange:kSize subnodes:subnodes identifier:nil];
|
||||
@@ -464,7 +461,7 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize, BOOL flex)
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).staticSize = {50, 50};
|
||||
|
||||
for (ASStaticSizeDisplayNode *subnode in subnodes) {
|
||||
[ASLayoutSpec layoutOptionsForChild:subnode].flexBasis = ASRelativeDimensionMakeWithPoints(20);
|
||||
subnode.layoutOptions.flexBasis = ASRelativeDimensionMakeWithPoints(20);
|
||||
}
|
||||
|
||||
static ASSizeRange kSize = {{300, 0}, {300, 150}};
|
||||
@@ -482,9 +479,8 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize, BOOL flex)
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).staticSize = {3000, 3000};
|
||||
|
||||
ASRatioLayoutSpec *child2 = [ASRatioLayoutSpec ratioLayoutSpecWithRatio:1.0 child:subnodes[2]];
|
||||
ASLayoutOptions *layoutOptions2 = [ASLayoutSpec layoutOptionsForChild:child2];
|
||||
layoutOptions2.flexGrow = YES;
|
||||
layoutOptions2.flexShrink = YES;
|
||||
child2.layoutOptions.flexGrow = YES;
|
||||
child2.layoutOptions.flexShrink = YES;
|
||||
|
||||
// If cross axis stretching occurred *before* flexing, then the blue child would be stretched to 3000 points tall.
|
||||
// Instead it should be stretched to 300 points tall, matching the red child and not overlapping the green inset.
|
||||
@@ -509,13 +505,13 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize, BOOL flex)
|
||||
NSArray *subnodes = defaultSubnodes();
|
||||
|
||||
((ASStaticSizeDisplayNode *)subnodes[0]).staticSize = {300, 50};
|
||||
[ASLayoutSpec layoutOptionsForChild:((ASStaticSizeDisplayNode *)subnodes[0])].flexShrink = YES;
|
||||
((ASStaticSizeDisplayNode *)subnodes[0]).layoutOptions.flexShrink = YES;
|
||||
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {100, 50};
|
||||
[ASLayoutSpec layoutOptionsForChild:((ASStaticSizeDisplayNode *)subnodes[1])].flexShrink = NO;
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).layoutOptions.flexShrink = NO;
|
||||
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).staticSize = {200, 50};
|
||||
[ASLayoutSpec layoutOptionsForChild:((ASStaticSizeDisplayNode *)subnodes[2])].flexShrink = YES;
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).layoutOptions.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