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;
}