Fixed infinite recursion in finalLayoutable, removed child properties from ASLayoutSpecs

This commit is contained in:
rcancro 2015-08-28 20:11:19 -07:00
parent 84cd80c41d
commit 5786bc1b5b
11 changed files with 19 additions and 49 deletions

View File

@ -1849,8 +1849,9 @@ static void _recursivelySetDisplaySuspended(ASDisplayNode *node, CALayer *layer,
return !self.layerBacked && [self.view canPerformAction:action withSender:sender];
}
- (id<ASLayoutable>)finalLayoutable {
return self;
- (ASLayoutSpec *)finalLayoutableWithParent:(ASLayoutSpec *)parentSpec
{
return nil;
}
@end

View File

@ -15,7 +15,6 @@
*/
@interface ASBackgroundLayoutSpec : ASLayoutSpec
@property (nonatomic, strong) id<ASLayoutable> child;
@property (nonatomic, strong) id<ASLayoutable> background;
/**

View File

@ -39,7 +39,6 @@ typedef NS_OPTIONS(NSUInteger, ASCenterLayoutSpecSizingOptions) {
@property (nonatomic, assign) ASCenterLayoutSpecCenteringOptions centeringOptions;
@property (nonatomic, assign) ASCenterLayoutSpecSizingOptions sizingOptions;
@property (nonatomic, strong) id<ASLayoutable> child;
/**
* Initializer.

View File

@ -29,7 +29,6 @@
*/
@interface ASInsetLayoutSpec : ASLayoutSpec
@property (nonatomic, strong) id<ASLayoutable> child;
@property (nonatomic, assign) UIEdgeInsets insets;
/**

View File

@ -16,11 +16,18 @@
- (ASLayoutOptions *)layoutOptions\
{\
dispatch_once(&_layoutOptionsInitializeToken, ^{\
if (_layoutOptions == nil) {\
_layoutOptions = [[[ASLayoutOptions defaultLayoutOptionsClass] alloc] init];\
}\
});\
return _layoutOptions;\
}\
\
- (void)setLayoutOptions:(ASLayoutOptions *)layoutOptions\
{\
_layoutOptions = layoutOptions;\
}\
\
- (CGFloat)spacingBefore\
{\
return self.layoutOptions.spacingBefore;\

View File

@ -49,9 +49,9 @@ static NSString * const kDefaultChildrenKey = @"kDefaultChildrenKey";
return [ASLayout layoutWithLayoutableObject:self size:constrainedSize.min];
}
- (id<ASLayoutable>)finalLayoutable
- (ASLayoutSpec *)finalLayoutableWithParent:(ASLayoutSpec *)parentSpec;
{
return self;
return nil;
}
- (void)setChild:(id<ASLayoutable>)child;
@ -61,14 +61,14 @@ static NSString * const kDefaultChildrenKey = @"kDefaultChildrenKey";
- (id<ASLayoutable>)layoutableToAddFromLayoutable:(id<ASLayoutable>)child
{
ASLayoutOptions *layoutOptions = [ASLayoutSpec layoutOptionsForChild:child];
id<ASLayoutable> finalLayoutable = [child finalLayoutable];
ASLayoutOptions *layoutOptions = [child layoutOptions];
layoutOptions.isMutable = NO;
if (finalLayoutable != child) {
id<ASLayoutable> finalLayoutable = [child finalLayoutableWithParent:self];
if (finalLayoutable) {
ASLayoutOptions *finalLayoutOptions = [layoutOptions copy];
finalLayoutOptions.isMutable = NO;
[ASLayoutSpec associateLayoutOptions:finalLayoutOptions withChild:finalLayoutable];
finalLayoutable.layoutOptions = finalLayoutOptions;
return finalLayoutable;
}
return child;
@ -107,35 +107,5 @@ static NSString * const kDefaultChildrenKey = @"kDefaultChildrenKey";
return self.layoutChildren[kDefaultChildrenKey];
}
static Class gLayoutOptionsClass = [ASLayoutOptions class];
+ (void)setLayoutOptionsClass:(Class)layoutOptionsClass
{
gLayoutOptionsClass = layoutOptionsClass;
}
+ (ASLayoutOptions *)optionsForChild:(id<ASLayoutable>)child
{
ASLayoutOptions *layoutOptions = [[gLayoutOptionsClass alloc] init];;
[layoutOptions setValuesFromLayoutable:child];
layoutOptions.isMutable = NO;
return layoutOptions;
}
+ (void)associateLayoutOptions:(ASLayoutOptions *)layoutOptions withChild:(id<ASLayoutable>)child
{
objc_setAssociatedObject(child, @selector(setChild:), layoutOptions, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
+ (ASLayoutOptions *)layoutOptionsForChild:(id<ASLayoutable>)child
{
ASLayoutOptions *layoutOptions = objc_getAssociatedObject(child, @selector(setChild:));
if (layoutOptions == nil) {
layoutOptions = [self optionsForChild:child];
[self associateLayoutOptions:layoutOptions withChild:child];
}
return objc_getAssociatedObject(child, @selector(setChild:));
}
@end

View File

@ -14,6 +14,6 @@
@class ASLayoutOptions;
@protocol ASLayoutablePrivate <NSObject>
- (ASLayoutSpec *)finalLayoutable;
@property (nonatomic, strong, readonly) ASLayoutOptions *layoutOptions;
- (ASLayoutSpec *)finalLayoutableWithParent:(ASLayoutSpec *)parentSpec;
@property (nonatomic, strong) ASLayoutOptions *layoutOptions;
@end

View File

@ -15,7 +15,6 @@
*/
@interface ASOverlayLayoutSpec : ASLayoutSpec
@property (nonatomic, strong) id<ASLayoutable> child;
@property (nonatomic, strong) id<ASLayoutable> overlay;
+ (instancetype)overlayLayoutSpecWithChild:(id<ASLayoutable>)child overlay:(id<ASLayoutable>)overlay;

View File

@ -49,7 +49,7 @@ static NSString * const kOverlayChildKey = @"kOverlayChildKey";
*/
- (ASLayout *)measureWithSizeRange:(ASSizeRange)constrainedSize
{
ASLayout *contentsLayout = [_child measureWithSizeRange:constrainedSize];
ASLayout *contentsLayout = [self.child measureWithSizeRange:constrainedSize];
contentsLayout.position = CGPointZero;
NSMutableArray *sublayouts = [NSMutableArray arrayWithObject:contentsLayout];
if (self.overlay) {

View File

@ -31,8 +31,6 @@
**/
@interface ASRatioLayoutSpec : ASLayoutSpec
@property (nonatomic, strong) id<ASLayoutable> child;
@property (nonatomic, assign) CGFloat ratio;
+ (instancetype)ratioLayoutSpecWithRatio:(CGFloat)ratio child:(id<ASLayoutable>)child;

View File

@ -154,8 +154,6 @@ typedef NS_OPTIONS(NSUInteger, ASDisplayNodeMethodOverrides) {
@property (nonatomic, assign) CGFloat contentsScaleForDisplay;
- (id<ASLayoutable>)finalLayoutable;
@end
@interface UIView (ASDisplayNodeInternal)