mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-03 13:13:55 +00:00
Update tests.
This commit is contained in:
parent
64e2323a4e
commit
4ad64b2841
@ -330,7 +330,6 @@
|
||||
ACF6ED5C1B178DC700DA7C62 /* ASCenterLayoutNodeSnapshotTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = ACF6ED531B178DC700DA7C62 /* ASCenterLayoutNodeSnapshotTests.mm */; };
|
||||
ACF6ED5D1B178DC700DA7C62 /* ASDimensionTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = ACF6ED541B178DC700DA7C62 /* ASDimensionTests.mm */; };
|
||||
ACF6ED5E1B178DC700DA7C62 /* ASInsetLayoutNodeSnapshotTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = ACF6ED551B178DC700DA7C62 /* ASInsetLayoutNodeSnapshotTests.mm */; };
|
||||
ACF6ED5F1B178DC700DA7C62 /* ASLayoutNodeSizeTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = ACF6ED561B178DC700DA7C62 /* ASLayoutNodeSizeTests.mm */; };
|
||||
ACF6ED601B178DC700DA7C62 /* ASLayoutNodeSnapshotTestsHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = ACF6ED581B178DC700DA7C62 /* ASLayoutNodeSnapshotTestsHelper.m */; };
|
||||
ACF6ED611B178DC700DA7C62 /* ASOverlayLayoutNodeSnapshotTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = ACF6ED591B178DC700DA7C62 /* ASOverlayLayoutNodeSnapshotTests.mm */; };
|
||||
ACF6ED621B178DC700DA7C62 /* ASRatioLayoutNodeSnapshotTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = ACF6ED5A1B178DC700DA7C62 /* ASRatioLayoutNodeSnapshotTests.mm */; };
|
||||
@ -558,7 +557,6 @@
|
||||
ACF6ED531B178DC700DA7C62 /* ASCenterLayoutNodeSnapshotTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ASCenterLayoutNodeSnapshotTests.mm; sourceTree = "<group>"; };
|
||||
ACF6ED541B178DC700DA7C62 /* ASDimensionTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ASDimensionTests.mm; sourceTree = "<group>"; };
|
||||
ACF6ED551B178DC700DA7C62 /* ASInsetLayoutNodeSnapshotTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ASInsetLayoutNodeSnapshotTests.mm; sourceTree = "<group>"; };
|
||||
ACF6ED561B178DC700DA7C62 /* ASLayoutNodeSizeTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ASLayoutNodeSizeTests.mm; sourceTree = "<group>"; };
|
||||
ACF6ED571B178DC700DA7C62 /* ASLayoutNodeSnapshotTestsHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASLayoutNodeSnapshotTestsHelper.h; sourceTree = "<group>"; };
|
||||
ACF6ED581B178DC700DA7C62 /* ASLayoutNodeSnapshotTestsHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = ASLayoutNodeSnapshotTestsHelper.m; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objc; };
|
||||
ACF6ED591B178DC700DA7C62 /* ASOverlayLayoutNodeSnapshotTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ASOverlayLayoutNodeSnapshotTests.mm; sourceTree = "<group>"; };
|
||||
@ -746,7 +744,6 @@
|
||||
058D0A2F195D057000B7D73C /* ASDisplayNodeTests.m */,
|
||||
058D0A30195D057000B7D73C /* ASDisplayNodeTestsHelper.h */,
|
||||
058D0A31195D057000B7D73C /* ASDisplayNodeTestsHelper.m */,
|
||||
ACF6ED561B178DC700DA7C62 /* ASLayoutNodeSizeTests.mm */,
|
||||
052EE0651A159FEF002C6279 /* ASMultiplexImageNodeTests.m */,
|
||||
058D0A32195D057000B7D73C /* ASMutableAttributedStringBuilderTests.m */,
|
||||
3C9C128419E616EF00E942A0 /* ASTableViewTests.m */,
|
||||
@ -1420,7 +1417,6 @@
|
||||
058D0A3F195D057000B7D73C /* ASTextNodeShadowerTests.m in Sources */,
|
||||
ACF6ED631B178DC700DA7C62 /* ASStackLayoutNodeSnapshotTests.mm in Sources */,
|
||||
29CDC2E21AAE70D000833CA4 /* ASBasicImageDownloaderContextTests.m in Sources */,
|
||||
ACF6ED5F1B178DC700DA7C62 /* ASLayoutNodeSizeTests.mm in Sources */,
|
||||
056D21551ABCEF50001107EF /* ASImageNodeSnapshotTests.m in Sources */,
|
||||
05EA6FE71AC0966E00E35788 /* ASSnapshotTestCase.mm in Sources */,
|
||||
ACF6ED5E1B178DC700DA7C62 /* ASInsetLayoutNodeSnapshotTests.mm in Sources */,
|
||||
|
||||
@ -47,7 +47,9 @@ static const ASSizeRange kSize = {{100, 120}, {320, 160}};
|
||||
sizingOptions:(ASCenterLayoutNodeSizingOptions)sizingOptions
|
||||
{
|
||||
ASDisplayNode *backgroundNode = ASDisplayNodeWithBackgroundColor([UIColor redColor]);
|
||||
ASDisplayNode *foregroundNode = ASDisplayNodeWithBackgroundColor([UIColor greenColor]);
|
||||
ASStaticSizeDisplayNode *foregroundNode = ASDisplayNodeWithBackgroundColor([UIColor greenColor]);
|
||||
foregroundNode.staticSize = {70, 100};
|
||||
|
||||
|
||||
ASLayoutNode *layoutNode =
|
||||
[ASBackgroundLayoutNode
|
||||
@ -55,8 +57,7 @@ static const ASSizeRange kSize = {{100, 120}, {320, 160}};
|
||||
[ASCenterLayoutNode
|
||||
newWithCenteringOptions:options
|
||||
sizingOptions:sizingOptions
|
||||
child:[ASCompositeNode newWithSize:ASLayoutNodeSizeMake(70.0, 100.0) displayNode:foregroundNode]
|
||||
size:{}]
|
||||
child:[ASCompositeNode newWithDisplayNode:foregroundNode]]
|
||||
background:[ASCompositeNode newWithDisplayNode:backgroundNode]];
|
||||
|
||||
[self testLayoutNode:layoutNode
|
||||
@ -92,7 +93,8 @@ static NSString *suffixForCenteringOptions(ASCenterLayoutNodeCenteringOptions ce
|
||||
- (void)testMinimumSizeRangeIsGivenToChildWhenNotCentering
|
||||
{
|
||||
ASDisplayNode *backgroundNode = ASDisplayNodeWithBackgroundColor([UIColor redColor]);
|
||||
ASDisplayNode *foregroundNode = ASDisplayNodeWithBackgroundColor([UIColor redColor]);
|
||||
ASStaticSizeDisplayNode *foregroundNode = ASDisplayNodeWithBackgroundColor([UIColor redColor]);
|
||||
foregroundNode.staticSize = {10, 10};
|
||||
|
||||
ASCenterLayoutNode *layoutNode =
|
||||
[ASCenterLayoutNode
|
||||
@ -102,14 +104,12 @@ static NSString *suffixForCenteringOptions(ASCenterLayoutNodeCenteringOptions ce
|
||||
[ASBackgroundLayoutNode
|
||||
newWithNode:
|
||||
[ASStackLayoutNode
|
||||
newWithSize:{}
|
||||
style:{}
|
||||
newWithStyle:{}
|
||||
children:@[[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
|
||||
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(10, 10) displayNode:foregroundNode];
|
||||
mutableChild.node = [ASCompositeNode newWithDisplayNode:foregroundNode];
|
||||
mutableChild.flexGrow = YES;
|
||||
}]]]
|
||||
background: [ASCompositeNode newWithDisplayNode:backgroundNode]]
|
||||
size:{}];
|
||||
background: [ASCompositeNode newWithDisplayNode:backgroundNode]]];
|
||||
|
||||
[self testLayoutNode:layoutNode sizeRange:kSize subnodes:@[backgroundNode, foregroundNode] identifier:nil];
|
||||
}
|
||||
|
||||
@ -58,14 +58,15 @@ static NSString *nameForInsets(UIEdgeInsets insets)
|
||||
for (NSUInteger combination = 0; combination < 16; combination++) {
|
||||
UIEdgeInsets insets = insetsForCombination(combination, 10);
|
||||
ASDisplayNode *backgroundNode = ASDisplayNodeWithBackgroundColor([UIColor grayColor]);
|
||||
ASDisplayNode *foregroundNode = ASDisplayNodeWithBackgroundColor([UIColor greenColor]);
|
||||
ASStaticSizeDisplayNode *foregroundNode = ASDisplayNodeWithBackgroundColor([UIColor greenColor]);
|
||||
foregroundNode.staticSize = {10, 10};
|
||||
|
||||
ASLayoutNode *layoutNode =
|
||||
[ASBackgroundLayoutNode
|
||||
newWithNode:
|
||||
[ASInsetLayoutNode
|
||||
newWithInsets:insets
|
||||
node:[ASCompositeNode newWithSize:ASLayoutNodeSizeMake(10, 10) displayNode:foregroundNode]]
|
||||
node:[ASCompositeNode newWithDisplayNode:foregroundNode]]
|
||||
background:[ASCompositeNode newWithDisplayNode:backgroundNode]];
|
||||
|
||||
static ASSizeRange kVariableSize = {{0, 0}, {300, 300}};
|
||||
@ -81,14 +82,15 @@ static NSString *nameForInsets(UIEdgeInsets insets)
|
||||
for (NSUInteger combination = 0; combination < 16; combination++) {
|
||||
UIEdgeInsets insets = insetsForCombination(combination, 10);
|
||||
ASDisplayNode *backgroundNode = ASDisplayNodeWithBackgroundColor([UIColor grayColor]);
|
||||
ASDisplayNode *foregroundNode = ASDisplayNodeWithBackgroundColor([UIColor greenColor]);
|
||||
ASStaticSizeDisplayNode *foregroundNode = ASDisplayNodeWithBackgroundColor([UIColor greenColor]);
|
||||
foregroundNode.staticSize = {10, 10};
|
||||
|
||||
ASLayoutNode *layoutNode =
|
||||
[ASBackgroundLayoutNode
|
||||
newWithNode:
|
||||
[ASInsetLayoutNode
|
||||
newWithInsets:insets
|
||||
node:[ASCompositeNode newWithSize:ASLayoutNodeSizeMake(10, 10) displayNode:foregroundNode]]
|
||||
node:[ASCompositeNode newWithDisplayNode:foregroundNode]]
|
||||
background:[ASCompositeNode newWithDisplayNode:backgroundNode]];
|
||||
|
||||
static ASSizeRange kFixedSize = {{300, 300}, {300, 300}};
|
||||
@ -105,14 +107,15 @@ static NSString *nameForInsets(UIEdgeInsets insets)
|
||||
for (NSUInteger combination = 0; combination < 16; combination++) {
|
||||
UIEdgeInsets insets = insetsForCombination(combination, 0);
|
||||
ASDisplayNode *backgroundNode = ASDisplayNodeWithBackgroundColor([UIColor grayColor]);
|
||||
ASDisplayNode *foregroundNode = ASDisplayNodeWithBackgroundColor([UIColor greenColor]);
|
||||
ASStaticSizeDisplayNode *foregroundNode = ASDisplayNodeWithBackgroundColor([UIColor greenColor]);
|
||||
foregroundNode.staticSize = {10, 10};
|
||||
|
||||
ASLayoutNode *layoutNode =
|
||||
[ASBackgroundLayoutNode
|
||||
newWithNode:
|
||||
[ASInsetLayoutNode
|
||||
newWithInsets:insets
|
||||
node:[ASCompositeNode newWithSize:ASLayoutNodeSizeMake(10, 10) displayNode:foregroundNode]]
|
||||
node:[ASCompositeNode newWithDisplayNode:foregroundNode]]
|
||||
background:[ASCompositeNode newWithDisplayNode:backgroundNode]];
|
||||
|
||||
static ASSizeRange kFixedSize = {{300, 300}, {300, 300}};
|
||||
|
||||
@ -1,88 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
*/
|
||||
|
||||
#import <XCTest/XCTest.h>
|
||||
|
||||
#import "ASLayoutNode.h"
|
||||
|
||||
|
||||
@interface ASLayoutNodeSizeTests : XCTestCase
|
||||
@end
|
||||
|
||||
@implementation ASLayoutNodeSizeTests
|
||||
|
||||
- (void)testResolvingSizeWithAutoInAllFieldsReturnsUnconstrainedRange
|
||||
{
|
||||
ASLayoutNodeSize s;
|
||||
ASSizeRange r = ASLayoutNodeSizeResolve(s, {500, 300});
|
||||
XCTAssertEqual(r.min.width, 0.f, @"Expected no min width");
|
||||
XCTAssertEqual(r.max.width, INFINITY, @"Expected no max width");
|
||||
XCTAssertEqual(r.min.height, 0.f, @"Expected no min height");
|
||||
XCTAssertEqual(r.max.height, INFINITY, @"Expected no max height");
|
||||
}
|
||||
|
||||
- (void)testPercentageWidthIsResolvedAgainstParentDimension
|
||||
{
|
||||
ASLayoutNodeSize s = {.width = ASRelativeDimensionMakeWithPercent(1.0)};
|
||||
ASSizeRange r = ASLayoutNodeSizeResolve(s, {500, 300});
|
||||
XCTAssertEqual(r.min.width, 500.0f, @"Expected min of resolved range to match");
|
||||
XCTAssertEqual(r.max.width, 500.0f, @"Expected max of resolved range to match");
|
||||
}
|
||||
|
||||
- (void)testMaxSizeClampsLayoutNodeSize
|
||||
{
|
||||
ASLayoutNodeSize s = {.width = ASRelativeDimensionMakeWithPercent(1.0), .maxWidth = ASRelativeDimensionMakeWithPoints(300)};
|
||||
ASSizeRange r = ASLayoutNodeSizeResolve(s, {500, 300});
|
||||
XCTAssertEqual(r.min.width, 300.0f, @"Expected max-size to clamp the width to exactly 300 pts");
|
||||
XCTAssertEqual(r.max.width, 300.0f, @"Expected max-size to clamp the width to exactly 300 pts");
|
||||
}
|
||||
|
||||
- (void)testMinSizeOverridesMaxSizeWhenTheyConflict
|
||||
{
|
||||
// Min-size overriding max-size matches CSS.
|
||||
ASLayoutNodeSize s = {.minWidth = ASRelativeDimensionMakeWithPercent(0.5), .maxWidth = ASRelativeDimensionMakeWithPoints(300)};
|
||||
ASSizeRange r = ASLayoutNodeSizeResolve(s, {800, 300});
|
||||
XCTAssertEqual(r.min.width, 400.0f, @"Expected min-size to override max-size");
|
||||
XCTAssertEqual(r.max.width, 400.0f, @"Expected min-size to override max-size");
|
||||
}
|
||||
|
||||
- (void)testMinSizeAloneResultsInRangeUnconstrainedToInfinity
|
||||
{
|
||||
ASLayoutNodeSize s = {.minWidth = ASRelativeDimensionMakeWithPoints(100)};
|
||||
ASSizeRange r = ASLayoutNodeSizeResolve(s, {800, 300});
|
||||
XCTAssertEqual(r.min.width, 100.0f, @"Expected min width to be passed through");
|
||||
XCTAssertEqual(r.max.width, INFINITY, @"Expected max width to be infinity since no maxWidth was specified");
|
||||
}
|
||||
|
||||
- (void)testMaxSizeAloneResultsInRangeUnconstrainedFromZero
|
||||
{
|
||||
ASLayoutNodeSize s = {.maxWidth = ASRelativeDimensionMakeWithPoints(100)};
|
||||
ASSizeRange r = ASLayoutNodeSizeResolve(s, {800, 300});
|
||||
XCTAssertEqual(r.min.width, 0.0f, @"Expected min width to be zero");
|
||||
XCTAssertEqual(r.max.width, 100.0f, @"Expected max width to be passed through");
|
||||
}
|
||||
|
||||
- (void)testMinSizeAndMaxSizeResolveToARangeWhenTheyAreNotInConflict
|
||||
{
|
||||
ASLayoutNodeSize s = {.minWidth = ASRelativeDimensionMakeWithPoints(100), .maxWidth = ASRelativeDimensionMakeWithPoints(300)};
|
||||
ASSizeRange r = ASLayoutNodeSizeResolve(s, {800, 300});
|
||||
XCTAssertEqual(r.min.width, 100.0f, @"Expected min-size to be passed to size range");
|
||||
XCTAssertEqual(r.max.width, 300.0f, @"Expected max-size to be passed to size range");
|
||||
}
|
||||
|
||||
- (void)testWhenWidthFallsBetweenMinAndMaxWidthsItReturnsARangeWithExactlyThatWidth
|
||||
{
|
||||
ASLayoutNodeSize s = {.minWidth = ASRelativeDimensionMakeWithPoints(100), .width = ASRelativeDimensionMakeWithPoints(200), .maxWidth = ASRelativeDimensionMakeWithPoints(300)};
|
||||
ASSizeRange r = ASLayoutNodeSizeResolve(s, {800, 300});
|
||||
XCTAssertEqual(r.min.width, 200.0f, @"Expected min-size to be width");
|
||||
XCTAssertEqual(r.max.width, 200.0f, @"Expected max-size to be width");
|
||||
}
|
||||
|
||||
@end
|
||||
@ -27,10 +27,17 @@
|
||||
identifier:(NSString *)identifier;
|
||||
@end
|
||||
|
||||
static inline ASDisplayNode *ASDisplayNodeWithBackgroundColor(UIColor *backgroundColor)
|
||||
@interface ASStaticSizeDisplayNode : ASDisplayNode
|
||||
|
||||
@property (nonatomic) CGSize staticSize;
|
||||
|
||||
@end
|
||||
|
||||
static inline ASStaticSizeDisplayNode *ASDisplayNodeWithBackgroundColor(UIColor *backgroundColor)
|
||||
{
|
||||
ASDisplayNode *node = [[ASDisplayNode alloc] init];
|
||||
ASStaticSizeDisplayNode *node = [[ASStaticSizeDisplayNode alloc] init];
|
||||
node.layerBacked = YES;
|
||||
node.backgroundColor = backgroundColor;
|
||||
node.staticSize = CGSizeZero;
|
||||
return node;
|
||||
}
|
||||
|
||||
@ -50,7 +50,7 @@
|
||||
|
||||
- (void)setLayoutNodeUnderTest:(ASLayoutNode *)layoutNodeUnderTest sizeRange:(ASSizeRange)sizeRange
|
||||
{
|
||||
_layoutUnderTest = [layoutNodeUnderTest calculateLayoutThatFits:sizeRange];
|
||||
_layoutUnderTest = [layoutNodeUnderTest computeLayoutThatFits:sizeRange];
|
||||
self.frame = CGRectMake(0, 0, _layoutUnderTest.size.width, _layoutUnderTest.size.height);
|
||||
[self measure:_layoutUnderTest.size];
|
||||
}
|
||||
@ -61,3 +61,14 @@
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation ASStaticSizeDisplayNode
|
||||
|
||||
- (ASLayout *)calculateLayoutThatFits:(CGSize)constrainedSize
|
||||
{
|
||||
return CGSizeEqualToSize(_staticSize, CGSizeZero)
|
||||
? [super calculateLayoutThatFits:constrainedSize]
|
||||
: [ASLayout newWithNode:[ASLayoutNode new] size:_staticSize];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@ -29,7 +29,8 @@ static const ASSizeRange kSize = {{320, 320}, {320, 320}};
|
||||
- (void)testOverlay
|
||||
{
|
||||
ASDisplayNode *backgroundNode = ASDisplayNodeWithBackgroundColor([UIColor blueColor]);
|
||||
ASDisplayNode *foregroundNode = ASDisplayNodeWithBackgroundColor([UIColor blackColor]);
|
||||
ASStaticSizeDisplayNode *foregroundNode = ASDisplayNodeWithBackgroundColor([UIColor blackColor]);
|
||||
foregroundNode.staticSize = {20, 20};
|
||||
|
||||
ASLayoutNode *layoutNode =
|
||||
[ASOverlayLayoutNode
|
||||
@ -38,8 +39,7 @@ static const ASSizeRange kSize = {{320, 320}, {320, 320}};
|
||||
[ASCenterLayoutNode
|
||||
newWithCenteringOptions:ASCenterLayoutNodeCenteringXY
|
||||
sizingOptions:{}
|
||||
child:[ASCompositeNode newWithSize:ASLayoutNodeSizeMake(20, 20) displayNode:foregroundNode]
|
||||
size:{}]];
|
||||
child:[ASCompositeNode newWithDisplayNode:foregroundNode]]];
|
||||
|
||||
[self testLayoutNode:layoutNode sizeRange:kSize subnodes:@[backgroundNode, foregroundNode] identifier: nil];
|
||||
}
|
||||
|
||||
@ -27,12 +27,12 @@ static const ASSizeRange kFixedSize = {{0, 0}, {100, 100}};
|
||||
|
||||
- (void)testRatioLayoutNodeWithRatio:(CGFloat)ratio childNodeSize:(CGSize)childNodeSize identifier:(NSString *)identifier
|
||||
{
|
||||
ASDisplayNode *subnode = ASDisplayNodeWithBackgroundColor([UIColor greenColor]);
|
||||
ASStaticSizeDisplayNode *subnode = ASDisplayNodeWithBackgroundColor([UIColor greenColor]);
|
||||
subnode.staticSize = childNodeSize;
|
||||
|
||||
ASLayoutNode *layoutNode = [ASRatioLayoutNode
|
||||
newWithRatio:ratio
|
||||
size:{}
|
||||
node:[ASCompositeNode newWithSize:ASLayoutNodeSizeMakeWithCGSize(childNodeSize) displayNode:subnode]];
|
||||
node:[ASCompositeNode newWithDisplayNode:subnode]];
|
||||
|
||||
[self testLayoutNode:layoutNode sizeRange:kFixedSize subnodes:@[subnode] identifier:identifier];
|
||||
}
|
||||
|
||||
@ -37,11 +37,20 @@ static ASStackLayoutNodeChild *flexChild(ASLayoutNode *n, BOOL flex)
|
||||
|
||||
static NSArray *defaultSubnodes()
|
||||
{
|
||||
return @[
|
||||
ASDisplayNodeWithBackgroundColor([UIColor redColor]),
|
||||
ASDisplayNodeWithBackgroundColor([UIColor blueColor]),
|
||||
ASDisplayNodeWithBackgroundColor([UIColor greenColor])
|
||||
];
|
||||
return defaultSubnodesWithSameSize(CGSizeZero);
|
||||
}
|
||||
|
||||
static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize)
|
||||
{
|
||||
NSArray *subnodes = @[
|
||||
ASDisplayNodeWithBackgroundColor([UIColor redColor]),
|
||||
ASDisplayNodeWithBackgroundColor([UIColor blueColor]),
|
||||
ASDisplayNodeWithBackgroundColor([UIColor greenColor])
|
||||
];
|
||||
for (ASStaticSizeDisplayNode *subnode in subnodes) {
|
||||
subnode.staticSize = subnodeSize;
|
||||
}
|
||||
return subnodes;
|
||||
}
|
||||
|
||||
- (void)testStackLayoutNodeWithJustify:(ASStackLayoutJustifyContent)justify
|
||||
@ -53,12 +62,11 @@ static NSArray *defaultSubnodes()
|
||||
.direction = ASStackLayoutDirectionHorizontal,
|
||||
.justifyContent = justify
|
||||
};
|
||||
ASLayoutNodeSize subnodeSize = ASLayoutNodeSizeMake(50, 50);
|
||||
NSArray *subnodes = defaultSubnodes();
|
||||
NSArray *subnodes = defaultSubnodesWithSameSize({50, 50});
|
||||
NSArray *children = @[
|
||||
flexChild([ASCompositeNode newWithSize:subnodeSize displayNode:subnodes[0]], flex),
|
||||
flexChild([ASCompositeNode newWithSize:subnodeSize displayNode:subnodes[1]], flex),
|
||||
flexChild([ASCompositeNode newWithSize:subnodeSize displayNode:subnodes[2]], flex)
|
||||
flexChild([ASCompositeNode newWithDisplayNode:subnodes[0]], flex),
|
||||
flexChild([ASCompositeNode newWithDisplayNode:subnodes[1]], flex),
|
||||
flexChild([ASCompositeNode newWithDisplayNode:subnodes[2]], flex)
|
||||
];
|
||||
|
||||
[self testStackLayoutNodeWithStyle:style children:children sizeRange:sizeRange subnodes:subnodes identifier:identifier];
|
||||
@ -74,7 +82,7 @@ static NSArray *defaultSubnodes()
|
||||
|
||||
ASLayoutNode *layoutNode =
|
||||
[ASBackgroundLayoutNode
|
||||
newWithNode:[ASStackLayoutNode newWithSize:{} style:style children:children]
|
||||
newWithNode:[ASStackLayoutNode newWithStyle:style children:children]
|
||||
background:[ASCompositeNode newWithDisplayNode:backgroundNode]];
|
||||
|
||||
NSMutableArray *newSubnodes = [NSMutableArray arrayWithObject:backgroundNode];
|
||||
@ -106,20 +114,19 @@ static NSArray *defaultSubnodes()
|
||||
- (void)testOverflowBehaviorsWhenAllFlexShrinkNodesHaveBeenClampedToZeroButViolationStillExists
|
||||
{
|
||||
ASStackLayoutNodeStyle style = {.direction = ASStackLayoutDirectionHorizontal};
|
||||
ASLayoutNodeSize subnodeSize = ASLayoutNodeSizeMake(50, 50);
|
||||
NSArray *subnodes = defaultSubnodes();
|
||||
NSArray *subnodes = defaultSubnodesWithSameSize({50, 50});
|
||||
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 newWithSize:subnodeSize displayNode:subnodes[0]];
|
||||
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[0]];
|
||||
mutableChild.flexShrink = NO;
|
||||
}],
|
||||
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
|
||||
mutableChild.node = [ASCompositeNode newWithSize:subnodeSize displayNode:subnodes[1]];
|
||||
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[1]];
|
||||
mutableChild.flexShrink = YES;
|
||||
}],
|
||||
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
|
||||
mutableChild.node = [ASCompositeNode newWithSize:subnodeSize displayNode:subnodes[2]];
|
||||
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[2]];
|
||||
mutableChild.flexShrink = NO;
|
||||
}]
|
||||
];
|
||||
@ -131,11 +138,16 @@ static NSArray *defaultSubnodes()
|
||||
- (void)testFlexWithUnequalIntrinsicSizes
|
||||
{
|
||||
ASStackLayoutNodeStyle 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 *children = @[
|
||||
flexChild([ASCompositeNode newWithSize:ASLayoutNodeSizeMake(50, 50) displayNode:subnodes[0]], YES),
|
||||
flexChild([ASCompositeNode newWithSize:ASLayoutNodeSizeMake(150, 150) displayNode:subnodes[1]], YES),
|
||||
flexChild([ASCompositeNode newWithSize:ASLayoutNodeSizeMake(50, 50) displayNode:subnodes[2]], YES)
|
||||
flexChild([ASCompositeNode newWithDisplayNode:subnodes[0]], YES),
|
||||
flexChild([ASCompositeNode newWithDisplayNode:subnodes[1]], YES),
|
||||
flexChild([ASCompositeNode newWithDisplayNode:subnodes[2]], YES)
|
||||
];
|
||||
|
||||
// width 300px; height 0-150px.
|
||||
@ -150,16 +162,21 @@ static NSArray *defaultSubnodes()
|
||||
- (void)testCrossAxisSizeBehaviors
|
||||
{
|
||||
ASStackLayoutNodeStyle 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 *children = @[
|
||||
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
|
||||
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(50, 50) displayNode:subnodes[0]];
|
||||
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[0]];
|
||||
}],
|
||||
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
|
||||
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(100, 50) displayNode:subnodes[1]];
|
||||
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[1]];
|
||||
}],
|
||||
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
|
||||
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(150, 50) displayNode:subnodes[2]];
|
||||
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[2]];
|
||||
}]
|
||||
];
|
||||
|
||||
@ -178,16 +195,21 @@ static NSArray *defaultSubnodes()
|
||||
.direction = ASStackLayoutDirectionVertical,
|
||||
.spacing = 10
|
||||
};
|
||||
|
||||
NSArray *subnodes = defaultSubnodes();
|
||||
((ASStaticSizeDisplayNode *)subnodes[0]).staticSize = {50, 50};
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {100, 50};
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).staticSize = {150, 50};
|
||||
|
||||
NSArray *children = @[
|
||||
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
|
||||
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(50, 50) displayNode:subnodes[0]];
|
||||
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[0]];
|
||||
}],
|
||||
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
|
||||
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(100, 50) displayNode:subnodes[1]];
|
||||
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[1]];
|
||||
}],
|
||||
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
|
||||
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(150, 50) displayNode:subnodes[2]];
|
||||
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[2]];
|
||||
}]
|
||||
];
|
||||
// width 0-300px; height 300px
|
||||
@ -208,8 +230,7 @@ static NSArray *defaultSubnodes()
|
||||
[ASBackgroundLayoutNode
|
||||
newWithNode:
|
||||
[ASStackLayoutNode
|
||||
newWithSize:{}
|
||||
style:{
|
||||
newWithStyle:{
|
||||
.direction = ASStackLayoutDirectionVertical,
|
||||
.spacing = 10,
|
||||
.alignItems = ASStackLayoutAlignItemsStretch
|
||||
@ -229,19 +250,23 @@ static NSArray *defaultSubnodes()
|
||||
{
|
||||
// width 0-INF; height 0-INF
|
||||
static ASSizeRange kAnySize = {{0, 0}, {INFINITY, INFINITY}};
|
||||
NSArray *subnodes = defaultSubnodes();
|
||||
ASStackLayoutNodeStyle 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 *children = @[
|
||||
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
|
||||
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(50, 50) displayNode:subnodes[0]];
|
||||
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[0]];
|
||||
}],
|
||||
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
|
||||
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(100, 70) displayNode:subnodes[1]];
|
||||
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[1]];
|
||||
mutableChild.spacingBefore = 10;
|
||||
}],
|
||||
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
|
||||
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(150, 90) displayNode:subnodes[2]];
|
||||
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[2]];
|
||||
mutableChild.spacingBefore = 20;
|
||||
}]
|
||||
];
|
||||
@ -249,14 +274,14 @@ static NSArray *defaultSubnodes()
|
||||
|
||||
children = @[
|
||||
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
|
||||
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(50, 50) displayNode:subnodes[0]];
|
||||
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[0]];
|
||||
}],
|
||||
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
|
||||
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(100, 70) displayNode:subnodes[1]];
|
||||
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[1]];
|
||||
mutableChild.spacingAfter = 10;
|
||||
}],
|
||||
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
|
||||
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(150, 90) displayNode:subnodes[2]];
|
||||
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[2]];
|
||||
mutableChild.spacingAfter = 20;
|
||||
}]
|
||||
];
|
||||
@ -265,15 +290,15 @@ static NSArray *defaultSubnodes()
|
||||
style.spacing = 10;
|
||||
children = @[
|
||||
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
|
||||
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(50, 50) displayNode:subnodes[0]];
|
||||
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[0]];
|
||||
}],
|
||||
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
|
||||
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(100, 70) displayNode:subnodes[1]];
|
||||
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[1]];
|
||||
mutableChild.spacingBefore = -10;
|
||||
mutableChild.spacingAfter = -10;
|
||||
}],
|
||||
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
|
||||
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(150, 90) displayNode:subnodes[2]];
|
||||
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[2]];
|
||||
}]
|
||||
];
|
||||
[self testStackLayoutNodeWithStyle:style children:children sizeRange:kAnySize subnodes:subnodes identifier:@"spacingBalancedOut"];
|
||||
@ -285,18 +310,23 @@ static NSArray *defaultSubnodes()
|
||||
.direction = ASStackLayoutDirectionVertical,
|
||||
.justifyContent = ASStackLayoutJustifyContentCenter
|
||||
};
|
||||
|
||||
NSArray *subnodes = defaultSubnodes();
|
||||
((ASStaticSizeDisplayNode *)subnodes[0]).staticSize = {50, 50};
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {100, 70};
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).staticSize = {150, 90};
|
||||
|
||||
NSArray *children = @[
|
||||
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
|
||||
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(50, 50) displayNode:subnodes[0]];
|
||||
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[0]];
|
||||
mutableChild.spacingBefore = 0;
|
||||
}],
|
||||
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
|
||||
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(100, 70) displayNode:subnodes[1]];
|
||||
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[1]];
|
||||
mutableChild.spacingBefore = 20;
|
||||
}],
|
||||
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
|
||||
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(150, 90) displayNode:subnodes[2]];
|
||||
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[2]];
|
||||
mutableChild.spacingBefore = 30;
|
||||
}]
|
||||
];
|
||||
@ -309,22 +339,24 @@ static NSArray *defaultSubnodes()
|
||||
- (void)testNodeThatChangesCrossSizeWhenMainSizeIsFlexed
|
||||
{
|
||||
ASStackLayoutNodeStyle style = {.direction = ASStackLayoutDirectionHorizontal};
|
||||
|
||||
NSArray *subnodes = @[
|
||||
ASDisplayNodeWithBackgroundColor([UIColor blueColor]),
|
||||
ASDisplayNodeWithBackgroundColor([UIColor redColor])
|
||||
];
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {50, 50};
|
||||
|
||||
NSArray *children = @[
|
||||
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
|
||||
mutableChild.node = [ASRatioLayoutNode
|
||||
newWithRatio:1.5
|
||||
size:{}
|
||||
node:[ASCompositeNode newWithSize:ASLayoutNodeSizeMake(00, 150) displayNode:subnodes[0]]];;
|
||||
node:[ASCompositeNode newWithDisplayNode:subnodes[0]]];
|
||||
mutableChild.flexBasis = ASRelativeDimensionMakeWithPercent(1);
|
||||
mutableChild.flexGrow = YES;
|
||||
mutableChild.flexShrink = YES;
|
||||
}],
|
||||
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
|
||||
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(50, 50) displayNode:subnodes[1]];
|
||||
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[1]];
|
||||
}]
|
||||
];
|
||||
static ASSizeRange kFixedWidth = {{150, 0}, {150, INFINITY}};
|
||||
@ -337,17 +369,21 @@ static NSArray *defaultSubnodes()
|
||||
.direction = ASStackLayoutDirectionVertical,
|
||||
.alignItems = ASStackLayoutAlignItemsCenter
|
||||
};
|
||||
|
||||
NSArray *subnodes = @[
|
||||
ASDisplayNodeWithBackgroundColor([UIColor redColor]),
|
||||
ASDisplayNodeWithBackgroundColor([UIColor blueColor])
|
||||
];
|
||||
((ASStaticSizeDisplayNode *)subnodes[0]).staticSize = {100, 100};
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {50, 50};
|
||||
|
||||
NSArray *children = @[
|
||||
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
|
||||
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(100, 100) displayNode:subnodes[0]];
|
||||
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[0]];
|
||||
mutableChild.flexShrink = YES;
|
||||
}],
|
||||
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
|
||||
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(50, 50) displayNode:subnodes[1]];
|
||||
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[1]];
|
||||
mutableChild.flexShrink = YES;
|
||||
}],
|
||||
];
|
||||
@ -358,16 +394,20 @@ static NSArray *defaultSubnodes()
|
||||
- (void)testAlignCenterWithIndefiniteCrossDimension
|
||||
{
|
||||
ASStackLayoutNodeStyle style = {.direction = ASStackLayoutDirectionHorizontal};
|
||||
|
||||
NSArray *subnodes = @[
|
||||
ASDisplayNodeWithBackgroundColor([UIColor redColor]),
|
||||
ASDisplayNodeWithBackgroundColor([UIColor blueColor])
|
||||
];
|
||||
((ASStaticSizeDisplayNode *)subnodes[0]).staticSize = {100, 100};
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {50, 50};
|
||||
|
||||
NSArray *children = @[
|
||||
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
|
||||
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(100, 100) displayNode:subnodes[0]];
|
||||
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[0]];
|
||||
}],
|
||||
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
|
||||
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(50, 50) displayNode:subnodes[1]];
|
||||
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[1]];
|
||||
mutableChild.alignSelf = ASStackLayoutAlignSelfCenter;
|
||||
}],
|
||||
];
|
||||
@ -382,18 +422,23 @@ static NSArray *defaultSubnodes()
|
||||
.justifyContent = ASStackLayoutJustifyContentCenter,
|
||||
.alignItems = ASStackLayoutAlignItemsStart
|
||||
};
|
||||
|
||||
NSArray *subnodes = defaultSubnodes();
|
||||
((ASStaticSizeDisplayNode *)subnodes[0]).staticSize = {50, 50};
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {100, 70};
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).staticSize = {150, 90};
|
||||
|
||||
NSArray *children = @[
|
||||
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
|
||||
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(50, 50) displayNode:subnodes[0]];
|
||||
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[0]];
|
||||
mutableChild.spacingBefore = 0;
|
||||
}],
|
||||
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
|
||||
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(100, 70) displayNode:subnodes[1]];
|
||||
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[1]];
|
||||
mutableChild.spacingBefore = 20;
|
||||
}],
|
||||
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
|
||||
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(150, 90) displayNode:subnodes[2]];
|
||||
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[2]];
|
||||
mutableChild.spacingBefore = 30;
|
||||
}]
|
||||
];
|
||||
@ -408,18 +453,23 @@ static NSArray *defaultSubnodes()
|
||||
.justifyContent = ASStackLayoutJustifyContentCenter,
|
||||
.alignItems = ASStackLayoutAlignItemsEnd
|
||||
};
|
||||
|
||||
NSArray *subnodes = defaultSubnodes();
|
||||
((ASStaticSizeDisplayNode *)subnodes[0]).staticSize = {50, 50};
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {100, 70};
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).staticSize = {150, 90};
|
||||
|
||||
NSArray *children = @[
|
||||
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
|
||||
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(50, 50) displayNode:subnodes[0]];
|
||||
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[0]];
|
||||
mutableChild.spacingBefore = 0;
|
||||
}],
|
||||
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
|
||||
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(100, 70) displayNode:subnodes[1]];
|
||||
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[1]];
|
||||
mutableChild.spacingBefore = 20;
|
||||
}],
|
||||
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
|
||||
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(150, 90) displayNode:subnodes[2]];
|
||||
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[2]];
|
||||
mutableChild.spacingBefore = 30;
|
||||
}]
|
||||
];
|
||||
@ -434,18 +484,23 @@ static NSArray *defaultSubnodes()
|
||||
.justifyContent = ASStackLayoutJustifyContentCenter,
|
||||
.alignItems = ASStackLayoutAlignItemsCenter
|
||||
};
|
||||
|
||||
NSArray *subnodes = defaultSubnodes();
|
||||
((ASStaticSizeDisplayNode *)subnodes[0]).staticSize = {50, 50};
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {100, 70};
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).staticSize = {150, 90};
|
||||
|
||||
NSArray *children = @[
|
||||
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
|
||||
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(50, 50) displayNode:subnodes[0]];
|
||||
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[0]];
|
||||
mutableChild.spacingBefore = 0;
|
||||
}],
|
||||
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
|
||||
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(100, 70) displayNode:subnodes[1]];
|
||||
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[1]];
|
||||
mutableChild.spacingBefore = 20;
|
||||
}],
|
||||
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
|
||||
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(150, 90) displayNode:subnodes[2]];
|
||||
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[2]];
|
||||
mutableChild.spacingBefore = 30;
|
||||
}]
|
||||
];
|
||||
@ -460,18 +515,23 @@ static NSArray *defaultSubnodes()
|
||||
.justifyContent = ASStackLayoutJustifyContentCenter,
|
||||
.alignItems = ASStackLayoutAlignItemsStretch
|
||||
};
|
||||
|
||||
NSArray *subnodes = defaultSubnodes();
|
||||
((ASStaticSizeDisplayNode *)subnodes[0]).staticSize = {50, 50};
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {100, 70};
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).staticSize = {150, 90};
|
||||
|
||||
NSArray *children = @[
|
||||
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
|
||||
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(50, 50) displayNode:subnodes[0]];
|
||||
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[0]];
|
||||
mutableChild.spacingBefore = 0;
|
||||
}],
|
||||
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
|
||||
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(100, 70) displayNode:subnodes[1]];
|
||||
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[1]];
|
||||
mutableChild.spacingBefore = 20;
|
||||
}],
|
||||
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
|
||||
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(150, 90) displayNode:subnodes[2]];
|
||||
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[2]];
|
||||
mutableChild.spacingBefore = 30;
|
||||
}]
|
||||
];
|
||||
@ -487,18 +547,23 @@ static NSArray *defaultSubnodes()
|
||||
.justifyContent = ASStackLayoutJustifyContentCenter,
|
||||
.alignItems = ASStackLayoutAlignItemsStretch
|
||||
};
|
||||
|
||||
NSArray *subnodes = defaultSubnodes();
|
||||
((ASStaticSizeDisplayNode *)subnodes[0]).staticSize = {50, 50};
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {100, 70};
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).staticSize = {150, 90};
|
||||
|
||||
NSArray *children = @[
|
||||
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
|
||||
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(50, 50) displayNode:subnodes[0]];
|
||||
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[0]];
|
||||
mutableChild.spacingBefore = 0;
|
||||
}],
|
||||
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
|
||||
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(100, 70) displayNode:subnodes[1]];
|
||||
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[1]];
|
||||
mutableChild.spacingBefore = 20;
|
||||
}],
|
||||
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
|
||||
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(150, 90) displayNode:subnodes[2]];
|
||||
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[2]];
|
||||
mutableChild.spacingBefore = 30;
|
||||
}]
|
||||
];
|
||||
@ -516,20 +581,25 @@ static NSArray *defaultSubnodes()
|
||||
- (void)testFixedFlexBasisAppliedWhenFlexingItems
|
||||
{
|
||||
ASStackLayoutNodeStyle 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 *children = @[
|
||||
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
|
||||
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(50, 50) displayNode:subnodes[0]];
|
||||
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[0]];
|
||||
mutableChild.flexGrow = YES;
|
||||
mutableChild.flexBasis = ASRelativeDimensionMakeWithPoints(10);
|
||||
}],
|
||||
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
|
||||
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(150, 150) displayNode:subnodes[1]];
|
||||
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[1]];
|
||||
mutableChild.flexGrow = YES;
|
||||
mutableChild.flexBasis = ASRelativeDimensionMakeWithPoints(10);
|
||||
}],
|
||||
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
|
||||
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(50, 50) displayNode:subnodes[2]];
|
||||
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[2]];
|
||||
mutableChild.flexGrow = YES;
|
||||
mutableChild.flexBasis = ASRelativeDimensionMakeWithPoints(10);
|
||||
}]
|
||||
@ -546,21 +616,21 @@ static NSArray *defaultSubnodes()
|
||||
- (void)testPercentageFlexBasisResolvesAgainstParentSize
|
||||
{
|
||||
ASStackLayoutNodeStyle style = {.direction = ASStackLayoutDirectionHorizontal};
|
||||
NSArray *subnodes = defaultSubnodes();
|
||||
NSArray *subnodes = defaultSubnodesWithSameSize({50, 50});
|
||||
NSArray *children = @[
|
||||
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
|
||||
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(50, 50) displayNode:subnodes[0]];
|
||||
mutableChild.node = [ASCompositeNode newWithDisplayNode: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 newWithSize:ASLayoutNodeSizeMake(50, 50) displayNode:subnodes[1]];
|
||||
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[1]];
|
||||
mutableChild.flexGrow = YES;
|
||||
}],
|
||||
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
|
||||
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(50, 50) displayNode:subnodes[2]];
|
||||
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[2]];
|
||||
mutableChild.flexGrow = YES;
|
||||
}]
|
||||
];
|
||||
@ -571,18 +641,23 @@ static NSArray *defaultSubnodes()
|
||||
- (void)testFixedFlexBasisOverridesIntrinsicSizeForNonFlexingChildren
|
||||
{
|
||||
ASStackLayoutNodeStyle 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 *children = @[
|
||||
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
|
||||
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(50, 50) displayNode:subnodes[0]];
|
||||
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[0]];
|
||||
mutableChild.flexBasis = ASRelativeDimensionMakeWithPoints(20);
|
||||
}],
|
||||
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
|
||||
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(150, 150) displayNode:subnodes[1]];
|
||||
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[1]];
|
||||
mutableChild.flexBasis = ASRelativeDimensionMakeWithPoints(20);
|
||||
}],
|
||||
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
|
||||
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(50, 50) displayNode:subnodes[2]];
|
||||
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[2]];
|
||||
mutableChild.flexBasis = ASRelativeDimensionMakeWithPoints(20);
|
||||
}]
|
||||
];
|
||||
@ -597,6 +672,8 @@ static NSArray *defaultSubnodes()
|
||||
ASDisplayNodeWithBackgroundColor([UIColor blueColor]),
|
||||
ASDisplayNodeWithBackgroundColor([UIColor redColor])
|
||||
];
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {10, 0};
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).staticSize = {3000, 3000};
|
||||
|
||||
// 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.
|
||||
@ -607,20 +684,18 @@ static NSArray *defaultSubnodes()
|
||||
newWithInsets:UIEdgeInsetsMake(10, 10, 10, 10)
|
||||
node:
|
||||
[ASStackLayoutNode
|
||||
newWithSize:{}
|
||||
style:{
|
||||
newWithStyle:{
|
||||
.direction = ASStackLayoutDirectionHorizontal,
|
||||
.alignItems = ASStackLayoutAlignItemsStretch,
|
||||
}
|
||||
children:
|
||||
@[
|
||||
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
|
||||
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(10, 00) displayNode:subnodes[1]];
|
||||
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[1]];
|
||||
}],
|
||||
flexChild([ASRatioLayoutNode
|
||||
newWithRatio:1.0
|
||||
size:{}
|
||||
node:[ASCompositeNode newWithSize:ASLayoutNodeSizeMake(3000, 3000) displayNode:subnodes[2]]],
|
||||
node:[ASCompositeNode newWithDisplayNode:subnodes[2]]],
|
||||
YES),
|
||||
]]]
|
||||
background:[ASCompositeNode newWithDisplayNode:subnodes[0]]];
|
||||
@ -632,18 +707,23 @@ static NSArray *defaultSubnodes()
|
||||
- (void)testViolationIsDistributedEquallyAmongFlexibleChildNodes
|
||||
{
|
||||
ASStackLayoutNodeStyle style = {.direction = ASStackLayoutDirectionHorizontal};
|
||||
|
||||
NSArray *subnodes = defaultSubnodes();
|
||||
((ASStaticSizeDisplayNode *)subnodes[0]).staticSize = {300, 50};
|
||||
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {100, 50};
|
||||
((ASStaticSizeDisplayNode *)subnodes[2]).staticSize = {200, 50};
|
||||
|
||||
NSArray *children = @[
|
||||
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
|
||||
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(300, 50) displayNode:subnodes[0]];
|
||||
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[0]];
|
||||
mutableChild.flexShrink = YES;
|
||||
}],
|
||||
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
|
||||
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(100, 50) displayNode:subnodes[1]];
|
||||
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[1]];
|
||||
mutableChild.flexShrink = NO;
|
||||
}],
|
||||
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
|
||||
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(200, 50) displayNode:subnodes[2]];
|
||||
mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[2]];
|
||||
mutableChild.flexShrink = YES;
|
||||
}]
|
||||
];
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user