addressed comments and fixed tests

This commit is contained in:
rcancro 2015-08-21 21:03:40 -07:00
parent c06a6be188
commit 680305704a
17 changed files with 82 additions and 113 deletions

View File

@ -25,12 +25,13 @@
- (instancetype)initWithChild:(id<ASLayoutable>)child background:(id<ASLayoutable>)background
{
self = [super init];
if (self) {
ASDisplayNodeAssertNotNil(child, @"Child cannot be nil");
_child = child;
_background = background;
if (!(self = [super init])) {
return nil;
}
ASDisplayNodeAssertNotNil(child, @"Child cannot be nil");
_child = child;
_background = background;
return self;
}

View File

@ -24,13 +24,13 @@
sizingOptions:(ASCenterLayoutSpecSizingOptions)sizingOptions
child:(id<ASLayoutable>)child;
{
self = [super init];
if (self) {
ASDisplayNodeAssertNotNil(child, @"Child cannot be nil");
_centeringOptions = centeringOptions;
_sizingOptions = sizingOptions;
_child = child;
if (!(self = [super init])) {
return nil;
}
ASDisplayNodeAssertNotNil(child, @"Child cannot be nil");
_centeringOptions = centeringOptions;
_sizingOptions = sizingOptions;
_child = child;
return self;
}

View File

@ -45,12 +45,12 @@ static CGFloat centerInset(CGFloat outer, CGFloat inner)
- (instancetype)initWithInsets:(UIEdgeInsets)insets child:(id<ASLayoutable>)child;
{
self = [super init];
if (self) {
ASDisplayNodeAssertNotNil(child, @"Child cannot be nil");
_insets = insets;
_child = child;
if (!(self = [super init])) {
return nil;
}
ASDisplayNodeAssertNotNil(child, @"Child cannot be nil");
_insets = insets;
_child = child;
return self;
}

View File

@ -27,11 +27,11 @@
- (instancetype)init
{
self = [super init];
if (self) {
_flexBasis = ASRelativeDimensionUnconstrained;
_isMutable = YES;
if (!(self = [super init])) {
return nil;
}
_flexBasis = ASRelativeDimensionUnconstrained;
_isMutable = YES;
return self;
}

View File

@ -18,6 +18,6 @@
@property (nonatomic, strong) id<ASLayoutable> child;
@property (nonatomic, strong) id<ASLayoutable> overlay;
+ (instancetype)overlayLayoutWithChild:(id<ASLayoutable>)child overlay:(id<ASLayoutable>)overlay;
+ (instancetype)overlayLayoutSpecWithChild:(id<ASLayoutable>)child overlay:(id<ASLayoutable>)overlay;
@end

View File

@ -22,16 +22,16 @@
- (instancetype)initWithChild:(id<ASLayoutable>)child overlay:(id<ASLayoutable>)overlay
{
self = [super init];
if (self) {
ASDisplayNodeAssertNotNil(child, @"Child that will be overlayed on shouldn't be nil");
_overlay = overlay;
_child = child;
if (!(self = [super init])) {
return nil;
}
ASDisplayNodeAssertNotNil(child, @"Child that will be overlayed on shouldn't be nil");
_overlay = overlay;
_child = child;
return self;
}
+ (instancetype)overlayLayoutWithChild:(id<ASLayoutable>)child overlay:(id<ASLayoutable>)overlay
+ (instancetype)overlayLayoutSpecWithChild:(id<ASLayoutable>)child overlay:(id<ASLayoutable>)overlay
{
return [[self alloc] initWithChild:child overlay:overlay];
}

View File

@ -32,13 +32,13 @@
- (instancetype)initWithRatio:(CGFloat)ratio child:(id<ASLayoutable>)child;
{
self = [super init];
if (self) {
ASDisplayNodeAssertNotNil(child, @"Child cannot be nil");
ASDisplayNodeAssert(ratio > 0, @"Ratio should be strictly positive, but received %f", ratio);
_ratio = ratio;
_child = child;
if (!(self = [super init])) {
return nil;
}
ASDisplayNodeAssertNotNil(child, @"Child cannot be nil");
ASDisplayNodeAssert(ratio > 0, @"Ratio should be strictly positive, but received %f", ratio);
_ratio = ratio;
_child = child;
return self;
}

View File

@ -85,15 +85,13 @@ typedef NS_ENUM(NSUInteger, ASStackLayoutAlignItems) {
- (instancetype)init;
/**
@param style Specifies how children are laid out.
@param direction The direction of the stack view (horizontal or vertical)
@param spacing The spacing between the children
@param justifyContent If no children are flexible, this describes how to fill any extra space
@param alignItems Orientation of the children along the cross axis
@param children ASLayoutable children to be positioned.
*/
+ (instancetype)satckLayoutSpecWithDirection:(ASStackLayoutDirection)direction
spacing:(CGFloat)spacing
contentJustification:(ASStackLayoutJustifyContent)justifyContent
itemAlignment:(ASStackLayoutAlignItems)alignItems
children:(NSArray *)children;
+ (instancetype)stackLayoutSpecWithDirection:(ASStackLayoutDirection)direction spacing:(CGFloat)spacing justifyContent:(ASStackLayoutJustifyContent)justifyContent alignItems:(ASStackLayoutAlignItems)alignItems children:(NSArray *)children;
- (void)addChild:(id<ASLayoutable>)child;
- (void)addChildren:(NSArray *)children;

View File

@ -28,43 +28,27 @@
- (instancetype)init
{
return [self initWithDirection:ASStackLayoutDirectionHorizontal
spacing:0.0
contentJustification:ASStackLayoutJustifyContentStart
itemAlignment:ASStackLayoutAlignItemsStart
children:nil];
return [self initWithDirection:ASStackLayoutDirectionHorizontal spacing:0.0 justifyContent:ASStackLayoutJustifyContentStart alignItems:ASStackLayoutAlignItemsStart children:nil];
}
+ (instancetype)satckLayoutSpecWithDirection:(ASStackLayoutDirection)direction
spacing:(CGFloat)spacing
contentJustification:(ASStackLayoutJustifyContent)justifyContent
itemAlignment:(ASStackLayoutAlignItems)alignItems
children:(NSArray *)children
+ (instancetype)stackLayoutSpecWithDirection:(ASStackLayoutDirection)direction spacing:(CGFloat)spacing justifyContent:(ASStackLayoutJustifyContent)justifyContent alignItems:(ASStackLayoutAlignItems)alignItems children:(NSArray *)children
{
return [[self alloc] initWithDirection:direction
spacing:spacing
contentJustification:justifyContent
itemAlignment:alignItems
children:children];
return [[self alloc] initWithDirection:direction spacing:spacing justifyContent:justifyContent alignItems:alignItems children:children];
}
- (instancetype)initWithDirection:(ASStackLayoutDirection)direction
spacing:(CGFloat)spacing
contentJustification:(ASStackLayoutJustifyContent)justifyContent
itemAlignment:(ASStackLayoutAlignItems)alignItems
children:(NSArray *)children;
- (instancetype)initWithDirection:(ASStackLayoutDirection)direction spacing:(CGFloat)spacing justifyContent:(ASStackLayoutJustifyContent)justifyContent alignItems:(ASStackLayoutAlignItems)alignItems children:(NSArray *)children
{
self = [super init];
if (self) {
_direction = direction;
_alignItems = alignItems;
_spacing = spacing;
_justifyContent = justifyContent;
_children = std::vector<id<ASLayoutable>>();
for (id<ASLayoutable> child in children) {
_children.push_back(child);
}
if (!(self = [super init])) {
return nil;
}
_direction = direction;
_alignItems = alignItems;
_spacing = spacing;
_justifyContent = justifyContent;
_children = std::vector<id<ASLayoutable>>();
for (id<ASLayoutable> child in children) {
_children.push_back(child);
}
return self;
}
@ -82,7 +66,6 @@
}
}
- (void)setDirection:(ASStackLayoutDirection)direction
{
ASDisplayNodeAssert(self.isMutable, @"Cannot set properties when layout spec is not mutable");
@ -109,11 +92,7 @@
- (ASLayout *)measureWithSizeRange:(ASSizeRange)constrainedSize
{
ASStackLayoutSpecStyle style = {.direction = _direction,
.spacing = _spacing,
.justifyContent = _justifyContent,
.alignItems = _alignItems
};
ASStackLayoutSpecStyle style = {.direction = _direction, .spacing = _spacing, .justifyContent = _justifyContent, .alignItems = _alignItems};
const auto unpositionedLayout = ASStackUnpositionedLayout::compute(_children, style, constrainedSize);
const auto positionedLayout = ASStackPositionedLayout::compute(unpositionedLayout, style, constrainedSize);
const CGSize finalSize = directionSize(style.direction, unpositionedLayout.stackDimensionSum, positionedLayout.crossSize);

View File

@ -46,10 +46,10 @@
- (instancetype)initWithChildren:(NSArray *)children
{
self = [super init];
if (self) {
_children = children;
if (!(self = [super init])) {
return nil;
}
_children = children;
return self;
}

View File

@ -52,9 +52,9 @@ static const ASSizeRange kSize = {{100, 120}, {320, 160}};
ASLayoutSpec *layoutSpec =
[ASBackgroundLayoutSpec
newWithChild:
backgroundLayoutSpecWithChild:
[ASCenterLayoutSpec
newWithCenteringOptions:options
centerLayoutSpecWithCenteringOptions:options
sizingOptions:sizingOptions
child:foregroundNode]
background:backgroundNode];
@ -98,11 +98,11 @@ static NSString *suffixForCenteringOptions(ASCenterLayoutSpecCenteringOptions ce
ASCenterLayoutSpec *layoutSpec =
[ASCenterLayoutSpec
newWithCenteringOptions:ASCenterLayoutSpecCenteringNone
centerLayoutSpecWithCenteringOptions:ASCenterLayoutSpecCenteringNone
sizingOptions:{}
child:
[ASBackgroundLayoutSpec
newWithChild:[ASStackLayoutSpec newWithStyle:{} children:@[foregroundNode]]
backgroundLayoutSpecWithChild:[ASStackLayoutSpec stackLayoutSpecWithDirection:ASStackLayoutDirectionVertical spacing:0 justifyContent:ASStackLayoutJustifyContentStart alignItems:ASStackLayoutAlignItemsStart children:@[foregroundNode]]
background:backgroundNode]];
[self testLayoutSpec:layoutSpec sizeRange:kSize subnodes:@[backgroundNode, foregroundNode] identifier:nil];

View File

@ -61,7 +61,7 @@ static NSString *nameForInsets(UIEdgeInsets insets)
ASLayoutSpec *layoutSpec =
[ASBackgroundLayoutSpec
newWithChild:[ASInsetLayoutSpec newWithInsets:insets child:foregroundNode]
backgroundLayoutSpecWithChild:[ASInsetLayoutSpec insetLayoutSpecWithInsets:insets child:foregroundNode]
background:backgroundNode];
static ASSizeRange kVariableSize = {{0, 0}, {300, 300}};
@ -82,7 +82,7 @@ static NSString *nameForInsets(UIEdgeInsets insets)
ASLayoutSpec *layoutSpec =
[ASBackgroundLayoutSpec
newWithChild:[ASInsetLayoutSpec newWithInsets:insets child:foregroundNode]
backgroundLayoutSpecWithChild:[ASInsetLayoutSpec insetLayoutSpecWithInsets:insets child:foregroundNode]
background:backgroundNode];
static ASSizeRange kFixedSize = {{300, 300}, {300, 300}};
@ -104,7 +104,7 @@ static NSString *nameForInsets(UIEdgeInsets insets)
ASLayoutSpec *layoutSpec =
[ASBackgroundLayoutSpec
newWithChild:[ASInsetLayoutSpec newWithInsets:insets child:foregroundNode]
backgroundLayoutSpecWithChild:[ASInsetLayoutSpec insetLayoutSpecWithInsets:insets child:foregroundNode]
background:backgroundNode];
static ASSizeRange kFixedSize = {{300, 300}, {300, 300}};

View File

@ -55,7 +55,7 @@
{
ASLayout *layout = [layoutSpecUnderTest measureWithSizeRange:sizeRange];
layout.position = CGPointZero;
layout = [ASLayout newWithLayoutableObject:self size:layout.size sublayouts:@[layout]];
layout = [ASLayout layoutWithLayoutableObject:self size:layout.size sublayouts:@[layout]];
_layoutUnderTest = [layout flattenedLayoutUsingPredicateBlock:^BOOL(ASLayout *evaluatedLayout) {
return [self.subnodes containsObject:evaluatedLayout.layoutableObject];
}];

View File

@ -34,10 +34,10 @@ static const ASSizeRange kSize = {{320, 320}, {320, 320}};
ASLayoutSpec *layoutSpec =
[ASOverlayLayoutSpec
newWithChild:backgroundNode
overlayLayoutSpecWithChild:backgroundNode
overlay:
[ASCenterLayoutSpec
newWithCenteringOptions:ASCenterLayoutSpecCenteringXY
centerLayoutSpecWithCenteringOptions:ASCenterLayoutSpecCenteringXY
sizingOptions:{}
child:foregroundNode]];

View File

@ -30,7 +30,7 @@ static const ASSizeRange kFixedSize = {{0, 0}, {100, 100}};
ASStaticSizeDisplayNode *subnode = ASDisplayNodeWithBackgroundColor([UIColor greenColor]);
subnode.staticSize = childSize;
ASLayoutSpec *layoutSpec = [ASRatioLayoutSpec newWithRatio:ratio child:subnode];
ASLayoutSpec *layoutSpec = [ASRatioLayoutSpec ratioLayoutSpecWithRatio:ratio child:subnode];
[self testLayoutSpec:layoutSpec sizeRange:kFixedSize subnodes:@[subnode] identifier:identifier];
}

View File

@ -11,6 +11,7 @@
#import "ASLayoutSpecSnapshotTestsHelper.h"
#import "ASStackLayoutSpec.h"
#import "ASStackLayoutSpecUtilities.h"
#import "ASBackgroundLayoutSpec.h"
#import "ASRatioLayoutSpec.h"
#import "ASInsetLayoutSpec.h"
@ -79,7 +80,7 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize, BOOL flex)
ASLayoutSpec *layoutSpec =
[ASBackgroundLayoutSpec
newWithChild:[ASStackLayoutSpec newWithStyle:style children:children]
backgroundLayoutSpecWithChild:[ASStackLayoutSpec stackLayoutSpecWithDirection:style.direction spacing:style.spacing justifyContent:style.justifyContent alignItems:style.alignItems children:children]
background:backgroundNode];
NSMutableArray *newSubnodes = [NSMutableArray arrayWithObject:backgroundNode];
@ -179,17 +180,12 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize, BOOL flex)
ASLayoutSpec *layoutSpec =
[ASInsetLayoutSpec
newWithInsets:{10, 10, 10 ,10}
insetLayoutSpecWithInsets:{10, 10, 10 ,10}
child:
[ASBackgroundLayoutSpec
newWithChild:
backgroundLayoutSpecWithChild:
[ASStackLayoutSpec
newWithStyle:{
.direction = ASStackLayoutDirectionVertical,
.spacing = 10,
.alignItems = ASStackLayoutAlignItemsStretch
}
children:@[]]
stackLayoutSpecWithDirection:ASStackLayoutDirectionVertical spacing:10 justifyContent:ASStackLayoutJustifyContentStart alignItems:ASStackLayoutAlignItemsStretch children:@[]]
background:backgroundNode]];
// width 300px; height 0-300px
@ -257,7 +253,7 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize, BOOL flex)
ASStaticSizeDisplayNode * subnode2 = ASDisplayNodeWithBackgroundColor([UIColor redColor]);
subnode2.staticSize = {50, 50};
ASRatioLayoutSpec *child1 = [ASRatioLayoutSpec newWithRatio:1.5 child:subnode1];
ASRatioLayoutSpec *child1 = [ASRatioLayoutSpec ratioLayoutSpecWithRatio:1.5 child:subnode1];
child1.flexBasis = ASRelativeDimensionMakeWithPercent(1);
child1.flexGrow = YES;
child1.flexShrink = YES;
@ -481,7 +477,7 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize, BOOL flex)
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {10, 0};
((ASStaticSizeDisplayNode *)subnodes[2]).staticSize = {3000, 3000};
ASRatioLayoutSpec *child2 = [ASRatioLayoutSpec newWithRatio:1.0 child:subnodes[2]];
ASRatioLayoutSpec *child2 = [ASRatioLayoutSpec ratioLayoutSpecWithRatio:1.0 child:subnodes[2]];
child2.flexGrow = YES;
child2.flexShrink = YES;
@ -489,16 +485,12 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize, BOOL flex)
// Instead it should be stretched to 300 points tall, matching the red child and not overlapping the green inset.
ASLayoutSpec *layoutSpec =
[ASBackgroundLayoutSpec
newWithChild:
backgroundLayoutSpecWithChild:
[ASInsetLayoutSpec
newWithInsets:UIEdgeInsetsMake(10, 10, 10, 10)
insetLayoutSpecWithInsets:UIEdgeInsetsMake(10, 10, 10, 10)
child:
[ASStackLayoutSpec
newWithStyle:{
.direction = ASStackLayoutDirectionHorizontal,
.alignItems = ASStackLayoutAlignItemsStretch,
}
children:@[subnodes[1], child2,]]]
[ASStackLayoutSpec stackLayoutSpecWithDirection:ASStackLayoutDirectionHorizontal spacing:0 justifyContent:ASStackLayoutJustifyContentStart alignItems:ASStackLayoutAlignItemsStretch children:@[subnodes[1], child2,]]
]
background:subnodes[0]];
static ASSizeRange kSize = {{300, 0}, {300, INFINITY}};

View File

@ -81,9 +81,8 @@ static NSString *kLinkAttributeName = @"PlaceKittenNodeLinkAttributeName";
centerSpec.sizingOptions = ASCenterLayoutSpecSizingOptionMinimumY;
centerSpec.child = _textNode;
return [ASInsetLayoutSpec insetLayoutSpecWithInsets:UIEdgeInsetsMake(kTextPadding, kTextPadding, kTextPadding, kTextPadding)
child:centerSpec];
UIEdgeInsets padding =UIEdgeInsetsMake(kTextPadding, kTextPadding, kTextPadding, kTextPadding);
return [ASInsetLayoutSpec insetLayoutSpecWithInsets:padding child:centerSpec];
}
#else
- (CGSize)calculateSizeThatFits:(CGSize)constrainedSize