diff --git a/AsyncDisplayKit/ASDisplayNode.mm b/AsyncDisplayKit/ASDisplayNode.mm index 54a2d94b1e..4dcf41e26e 100644 --- a/AsyncDisplayKit/ASDisplayNode.mm +++ b/AsyncDisplayKit/ASDisplayNode.mm @@ -1849,8 +1849,9 @@ static void _recursivelySetDisplaySuspended(ASDisplayNode *node, CALayer *layer, return !self.layerBacked && [self.view canPerformAction:action withSender:sender]; } -- (id)finalLayoutable { - return self; +- (ASLayoutSpec *)finalLayoutableWithParent:(ASLayoutSpec *)parentSpec +{ + return nil; } @end diff --git a/AsyncDisplayKit/Layout/ASBackgroundLayoutSpec.h b/AsyncDisplayKit/Layout/ASBackgroundLayoutSpec.h index ecc2e48473..cab51ea8b3 100644 --- a/AsyncDisplayKit/Layout/ASBackgroundLayoutSpec.h +++ b/AsyncDisplayKit/Layout/ASBackgroundLayoutSpec.h @@ -15,7 +15,6 @@ */ @interface ASBackgroundLayoutSpec : ASLayoutSpec -@property (nonatomic, strong) id child; @property (nonatomic, strong) id background; /** diff --git a/AsyncDisplayKit/Layout/ASCenterLayoutSpec.h b/AsyncDisplayKit/Layout/ASCenterLayoutSpec.h index dc50b265e7..37ba24e7e7 100644 --- a/AsyncDisplayKit/Layout/ASCenterLayoutSpec.h +++ b/AsyncDisplayKit/Layout/ASCenterLayoutSpec.h @@ -39,7 +39,6 @@ typedef NS_OPTIONS(NSUInteger, ASCenterLayoutSpecSizingOptions) { @property (nonatomic, assign) ASCenterLayoutSpecCenteringOptions centeringOptions; @property (nonatomic, assign) ASCenterLayoutSpecSizingOptions sizingOptions; -@property (nonatomic, strong) id child; /** * Initializer. diff --git a/AsyncDisplayKit/Layout/ASInsetLayoutSpec.h b/AsyncDisplayKit/Layout/ASInsetLayoutSpec.h index 3b140dfcc7..ab0a6f106f 100644 --- a/AsyncDisplayKit/Layout/ASInsetLayoutSpec.h +++ b/AsyncDisplayKit/Layout/ASInsetLayoutSpec.h @@ -29,7 +29,6 @@ */ @interface ASInsetLayoutSpec : ASLayoutSpec -@property (nonatomic, strong) id child; @property (nonatomic, assign) UIEdgeInsets insets; /** diff --git a/AsyncDisplayKit/Layout/ASLayoutOptionsPrivate.mm b/AsyncDisplayKit/Layout/ASLayoutOptionsPrivate.mm index 431565bde1..f04c010936 100644 --- a/AsyncDisplayKit/Layout/ASLayoutOptionsPrivate.mm +++ b/AsyncDisplayKit/Layout/ASLayoutOptionsPrivate.mm @@ -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;\ diff --git a/AsyncDisplayKit/Layout/ASLayoutSpec.mm b/AsyncDisplayKit/Layout/ASLayoutSpec.mm index a1ba8ed80a..904c30cc69 100644 --- a/AsyncDisplayKit/Layout/ASLayoutSpec.mm +++ b/AsyncDisplayKit/Layout/ASLayoutSpec.mm @@ -49,9 +49,9 @@ static NSString * const kDefaultChildrenKey = @"kDefaultChildrenKey"; return [ASLayout layoutWithLayoutableObject:self size:constrainedSize.min]; } -- (id)finalLayoutable +- (ASLayoutSpec *)finalLayoutableWithParent:(ASLayoutSpec *)parentSpec; { - return self; + return nil; } - (void)setChild:(id)child; @@ -61,14 +61,14 @@ static NSString * const kDefaultChildrenKey = @"kDefaultChildrenKey"; - (id)layoutableToAddFromLayoutable:(id)child { - ASLayoutOptions *layoutOptions = [ASLayoutSpec layoutOptionsForChild:child]; - id finalLayoutable = [child finalLayoutable]; + ASLayoutOptions *layoutOptions = [child layoutOptions]; layoutOptions.isMutable = NO; - if (finalLayoutable != child) { + id 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)child -{ - ASLayoutOptions *layoutOptions = [[gLayoutOptionsClass alloc] init];; - [layoutOptions setValuesFromLayoutable:child]; - layoutOptions.isMutable = NO; - return layoutOptions; -} - -+ (void)associateLayoutOptions:(ASLayoutOptions *)layoutOptions withChild:(id)child -{ - objc_setAssociatedObject(child, @selector(setChild:), layoutOptions, OBJC_ASSOCIATION_RETAIN_NONATOMIC); -} - -+ (ASLayoutOptions *)layoutOptionsForChild:(id)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 diff --git a/AsyncDisplayKit/Layout/ASLayoutablePrivate.h b/AsyncDisplayKit/Layout/ASLayoutablePrivate.h index 5091a30954..c7ab3b7ad3 100644 --- a/AsyncDisplayKit/Layout/ASLayoutablePrivate.h +++ b/AsyncDisplayKit/Layout/ASLayoutablePrivate.h @@ -14,6 +14,6 @@ @class ASLayoutOptions; @protocol ASLayoutablePrivate -- (ASLayoutSpec *)finalLayoutable; -@property (nonatomic, strong, readonly) ASLayoutOptions *layoutOptions; +- (ASLayoutSpec *)finalLayoutableWithParent:(ASLayoutSpec *)parentSpec; +@property (nonatomic, strong) ASLayoutOptions *layoutOptions; @end diff --git a/AsyncDisplayKit/Layout/ASOverlayLayoutSpec.h b/AsyncDisplayKit/Layout/ASOverlayLayoutSpec.h index 35a9577dde..05e53d92e8 100644 --- a/AsyncDisplayKit/Layout/ASOverlayLayoutSpec.h +++ b/AsyncDisplayKit/Layout/ASOverlayLayoutSpec.h @@ -15,7 +15,6 @@ */ @interface ASOverlayLayoutSpec : ASLayoutSpec -@property (nonatomic, strong) id child; @property (nonatomic, strong) id overlay; + (instancetype)overlayLayoutSpecWithChild:(id)child overlay:(id)overlay; diff --git a/AsyncDisplayKit/Layout/ASOverlayLayoutSpec.mm b/AsyncDisplayKit/Layout/ASOverlayLayoutSpec.mm index 05c1c0c4ca..b71375f5be 100644 --- a/AsyncDisplayKit/Layout/ASOverlayLayoutSpec.mm +++ b/AsyncDisplayKit/Layout/ASOverlayLayoutSpec.mm @@ -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) { diff --git a/AsyncDisplayKit/Layout/ASRatioLayoutSpec.h b/AsyncDisplayKit/Layout/ASRatioLayoutSpec.h index fd7f6d657b..2affa56a75 100644 --- a/AsyncDisplayKit/Layout/ASRatioLayoutSpec.h +++ b/AsyncDisplayKit/Layout/ASRatioLayoutSpec.h @@ -31,8 +31,6 @@ **/ @interface ASRatioLayoutSpec : ASLayoutSpec - -@property (nonatomic, strong) id child; @property (nonatomic, assign) CGFloat ratio; + (instancetype)ratioLayoutSpecWithRatio:(CGFloat)ratio child:(id)child; diff --git a/AsyncDisplayKit/Private/ASDisplayNodeInternal.h b/AsyncDisplayKit/Private/ASDisplayNodeInternal.h index d727bc5bab..cff5d76461 100644 --- a/AsyncDisplayKit/Private/ASDisplayNodeInternal.h +++ b/AsyncDisplayKit/Private/ASDisplayNodeInternal.h @@ -154,8 +154,6 @@ typedef NS_OPTIONS(NSUInteger, ASDisplayNodeMethodOverrides) { @property (nonatomic, assign) CGFloat contentsScaleForDisplay; -- (id)finalLayoutable; - @end @interface UIView (ASDisplayNodeInternal)