Remove ASLayoutChild. ASLayout now has a position property defaults to (NAN, NAN).

This commit is contained in:
Huy Nguyen
2015-06-30 17:10:17 +07:00
parent e74823bbee
commit 4799a9d206
11 changed files with 79 additions and 54 deletions

View File

@@ -9,39 +9,53 @@
*/
#import "ASLayout.h"
#import "ASAssert.h"
CGPoint const CGPointNull = {NAN, NAN};
extern BOOL CGPointIsNull(CGPoint point)
{
return isnan(point.x) && isnan(point.y);
}
@implementation ASLayout
+ (instancetype)newWithLayoutableObject:(id<ASLayoutable>)layoutableObject
size:(CGSize)size
position:(CGPoint)position
children:(NSArray *)children
{
for (ASLayout *child in children) {
ASDisplayNodeAssert(!CGPointIsNull(child.position), @"Invalid position is not allowed in children.");
}
ASLayout *l = [super new];
if (l) {
l->_layoutableObject = layoutableObject;
l->_size = size;
l->_position = position;
l->_children = [children copy];
}
return l;
}
+ (instancetype)newWithLayoutableObject:(id<ASLayoutable>)layoutableObject
size:(CGSize)size
children:(NSArray *)children
{
return [self newWithLayoutableObject:layoutableObject size:size position:CGPointNull children:children];
}
+ (instancetype)newWithLayoutableObject:(id<ASLayoutable>)layoutableObject size:(CGSize)size
{
return [self newWithLayoutableObject:layoutableObject size:size children:nil];
}
@end
@implementation ASLayoutChild
+ (instancetype)newWithPosition:(CGPoint)position layout:(ASLayout *)layout
- (void)setPosition:(CGPoint)position
{
ASLayoutChild *c = [super new];
if (c) {
c->_position = position;
c->_layout = layout;
}
return c;
ASDisplayNodeAssert(CGPointIsNull(_position), @"Position can be set once and only once.");
ASDisplayNodeAssert(!CGPointIsNull(position), @"Position must not be set to null.");
_position = position;
}
@end