From 2c6f8b0506f7a144955eeb4cc1f36fa747b59ac4 Mon Sep 17 00:00:00 2001 From: appleguy Date: Fri, 21 Oct 2016 13:12:13 -0700 Subject: [PATCH] [AsyncDisplayKit 2] Final changes to ease migration of clients to 2.0 APIs. (#2460) --- AsyncDisplayKit.podspec | 3 +- AsyncDisplayKit/ASDisplayNode.h | 24 ++++ AsyncDisplayKit/ASDisplayNode.mm | 92 +++++++------- .../Layout/ASAbsoluteLayoutElement.h | 5 + AsyncDisplayKit/Layout/ASAbsoluteLayoutSpec.h | 9 ++ .../Layout/ASAbsoluteLayoutSpec.mm | 29 ++++- AsyncDisplayKit/Layout/ASDimension.h | 71 +++++++++++ AsyncDisplayKit/Layout/ASDimension.mm | 79 ++++++++++++ AsyncDisplayKit/Layout/ASLayout.h | 17 +++ AsyncDisplayKit/Layout/ASLayout.mm | 24 ++++ AsyncDisplayKit/Layout/ASLayoutElement.h | 4 +- AsyncDisplayKit/Layout/ASLayoutElement.mm | 18 +++ .../Layout/ASLayoutElementPrivate.h | 119 ++++++++++++++++++ AsyncDisplayKit/Layout/ASLayoutSpec.h | 2 +- AsyncDisplayKit/Layout/ASLayoutSpec.mm | 15 ++- .../ASDisplayNodeImplicitHierarchyTests.m | 29 ++--- Base/ASBaseDefines.h | 2 +- 17 files changed, 470 insertions(+), 72 deletions(-) diff --git a/AsyncDisplayKit.podspec b/AsyncDisplayKit.podspec index f5dba4322d..9e146ed38d 100644 --- a/AsyncDisplayKit.podspec +++ b/AsyncDisplayKit.podspec @@ -59,7 +59,8 @@ Pod::Spec.new do |spec| spec.subspec 'PINRemoteImage' do |pin| pin.xcconfig = { 'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) PIN_REMOTE_IMAGE=1' } - pin.dependency 'PINRemoteImage/iOS', '= 3.0.0-beta.5' + pin.dependency 'PINRemoteImage/iOS', '>= 3.0.0-beta.4' + pin.dependency 'PINRemoteImage/PINCache' pin.dependency 'AsyncDisplayKit/Core' end diff --git a/AsyncDisplayKit/ASDisplayNode.h b/AsyncDisplayKit/ASDisplayNode.h index 89a4942e04..73639dca9e 100644 --- a/AsyncDisplayKit/ASDisplayNode.h +++ b/AsyncDisplayKit/ASDisplayNode.h @@ -812,9 +812,33 @@ extern NSInteger const ASDefaultDrawingPriority; */ - (void)cancelLayoutTransition; +@end + +@interface ASDisplayNode (Deprecated) #pragma mark - Deprecated +/** + * @abstract Asks the node to measure and return the size that best fits its subnodes. + * + * @param constrainedSize The maximum size the receiver should fit in. + * + * @return A new size that fits the receiver's subviews. + * + * @discussion Though this method does not set the bounds of the view, it does have side effects--caching both the + * constraint and the result. + * + * @warning Subclasses must not override this; it calls -measureWithSizeRange: with zero min size. + * -measureWithSizeRange: caches results from -calculateLayoutThatFits:. Calling this method may + * be expensive if result is not cached. + * + * @see measureWithSizeRange: + * @see [ASDisplayNode(Subclassing) calculateLayoutThatFits:] + * + * @deprecated Deprecated in version 2.0: Use layoutThatFits: with a constrained size of (CGSizeZero, constrainedSize) and call size on the returned ASLayout + */ +- (CGSize)measure:(CGSize)constrainedSize ASDISPLAYNODE_DEPRECATED; + /** * @abstract Provides a default intrinsic content size for calculateSizeThatFits:. This is useful when laying out * a node that either has no intrinsic content size or should be laid out at a different size than its intrinsic content diff --git a/AsyncDisplayKit/ASDisplayNode.mm b/AsyncDisplayKit/ASDisplayNode.mm index 9b132030fc..e6ca7b9269 100644 --- a/AsyncDisplayKit/ASDisplayNode.mm +++ b/AsyncDisplayKit/ASDisplayNode.mm @@ -1654,7 +1654,8 @@ static bool disableNotificationsForMovingBetweenParents(ASDisplayNode *from, ASD - (void)addSubnode:(ASDisplayNode *)subnode { - ASDisplayNodeAssert(self.automaticallyManagesSubnodes == NO, @"Attempt to manually add subnode to node with automaticallyManagesSubnodes=YES. Node: %@", subnode); + // TODO: 2.0 Conversion: Reenable and fix within product code + //ASDisplayNodeAssert(self.automaticallyManagesSubnodes == NO, @"Attempt to manually add subnode to node with automaticallyManagesSubnodes=YES. Node: %@", subnode); [self _addSubnode:subnode]; } @@ -1770,7 +1771,8 @@ static bool disableNotificationsForMovingBetweenParents(ASDisplayNode *from, ASD - (void)replaceSubnode:(ASDisplayNode *)oldSubnode withSubnode:(ASDisplayNode *)replacementSubnode { - ASDisplayNodeAssert(self.automaticallyManagesSubnodes == NO, @"Attempt to manually replace old node with replacement node to node with automaticallyManagesSubnodes=YES. Old Node: %@, replacement node: %@", oldSubnode, replacementSubnode); + // TODO: 2.0 Conversion: Reenable and fix within product code + //ASDisplayNodeAssert(self.automaticallyManagesSubnodes == NO, @"Attempt to manually replace old node with replacement node to node with automaticallyManagesSubnodes=YES. Old Node: %@, replacement node: %@", oldSubnode, replacementSubnode); [self _replaceSubnode:oldSubnode withSubnode:replacementSubnode]; } @@ -1806,7 +1808,8 @@ static NSInteger incrementIfFound(NSInteger i) { - (void)insertSubnode:(ASDisplayNode *)subnode belowSubnode:(ASDisplayNode *)below { - ASDisplayNodeAssert(self.automaticallyManagesSubnodes == NO, @"Attempt to manually insert subnode to node with automaticallyManagesSubnodes=YES. Node: %@", subnode); + // TODO: 2.0 Conversion: Reenable and fix within product code + //ASDisplayNodeAssert(self.automaticallyManagesSubnodes == NO, @"Attempt to manually insert subnode to node with automaticallyManagesSubnodes=YES. Node: %@", subnode); [self _insertSubnode:subnode belowSubnode:below]; } @@ -1857,7 +1860,8 @@ static NSInteger incrementIfFound(NSInteger i) { - (void)insertSubnode:(ASDisplayNode *)subnode aboveSubnode:(ASDisplayNode *)above { - ASDisplayNodeAssert(self.automaticallyManagesSubnodes == NO, @"Attempt to manually insert subnode to node with automaticallyManagesSubnodes=YES. Node: %@", subnode); + // TODO: 2.0 Conversion: Reenable and fix within product code + //ASDisplayNodeAssert(self.automaticallyManagesSubnodes == NO, @"Attempt to manually insert subnode to node with automaticallyManagesSubnodes=YES. Node: %@", subnode); [self _insertSubnode:subnode aboveSubnode:above]; } @@ -1911,7 +1915,8 @@ static NSInteger incrementIfFound(NSInteger i) { - (void)insertSubnode:(ASDisplayNode *)subnode atIndex:(NSInteger)idx { - ASDisplayNodeAssert(self.automaticallyManagesSubnodes == NO, @"Attempt to manually insert subnode to node with automaticallyManagesSubnodes=YES. Node: %@", subnode); + // TODO: 2.0 Conversion: Reenable and fix within product code + //ASDisplayNodeAssert(self.automaticallyManagesSubnodes == NO, @"Attempt to manually insert subnode to node with automaticallyManagesSubnodes=YES. Node: %@", subnode); [self _insertSubnode:subnode atIndex:idx]; } @@ -1989,7 +1994,7 @@ static NSInteger incrementIfFound(NSInteger i) { - (void)removeFromSupernode { - ASDisplayNodeAssert(self.supernode.automaticallyManagesSubnodes == NO, @"Attempt to manually remove subnode from node with automaticallyManagesSubnodes=YES. Node: %@", self); + //ASDisplayNodeAssert(self.supernode.automaticallyManagesSubnodes == NO, @"Attempt to manually remove subnode from node with automaticallyManagesSubnodes=YES. Node: %@", self); [self _removeFromSupernode]; } @@ -3451,6 +3456,15 @@ static const char *ASDisplayNodeDrawingPriorityKey = "ASDrawingPriority"; // Subclass override } +#pragma mark - Deprecated + +ASLayoutElementStyleForwarding + +- (ASLayout *)measureWithSizeRange:(ASSizeRange)constrainedSize +{ + return [self layoutThatFits:constrainedSize parentSize:constrainedSize.max]; +} + ASEnvironmentLayoutExtensibilityForwarding #if TARGET_OS_TV @@ -3486,42 +3500,6 @@ ASEnvironmentLayoutExtensibilityForwarding } #endif -#pragma mark - Deprecated - -- (NSString *)name -{ - return self.debugName; -} - -- (void)setName:(NSString *)name -{ - self.debugName = name; -} - -- (CGSize)measure:(CGSize)constrainedSize -{ - return [self layoutThatFits:ASSizeRangeMake(CGSizeZero, constrainedSize)].size; -} - -- (ASLayout *)measureWithSizeRange:(ASSizeRange)constrainedSize -{ - return [self layoutThatFits:constrainedSize parentSize:constrainedSize.max]; -} - -- (void)setPreferredFrameSize:(CGSize)preferredFrameSize -{ - // Deprecated preferredFrameSize just calls through to set width and height - self.style.preferredSize = preferredFrameSize; - [self invalidateCalculatedLayout]; -} - -- (CGSize)preferredFrameSize -{ - ASLayoutSize size = self.style.preferredLayoutSize; - BOOL isPoints = (size.width.unit == ASDimensionUnitPoints && size.height.unit == ASDimensionUnitPoints); - return isPoints ? CGSizeMake(size.width.value, size.height.value) : CGSizeZero; -} - @end @implementation ASDisplayNode (Debugging) @@ -3637,9 +3615,39 @@ static const char *ASDisplayNodeAssociatedNodeKey = "ASAssociatedNode"; @end +#pragma mark - Deprecated @implementation ASDisplayNode (Deprecated) +- (NSString *)name +{ + return self.debugName; +} + +- (void)setName:(NSString *)name +{ + self.debugName = name; +} + +- (CGSize)measure:(CGSize)constrainedSize +{ + return [self layoutThatFits:ASSizeRangeMake(CGSizeZero, constrainedSize)].size; +} + +- (void)setPreferredFrameSize:(CGSize)preferredFrameSize +{ + // Deprecated preferredFrameSize just calls through to set width and height + self.style.preferredSize = preferredFrameSize; + [self invalidateCalculatedLayout]; +} + +- (CGSize)preferredFrameSize +{ + ASLayoutSize size = self.style.preferredLayoutSize; + BOOL isPoints = (size.width.unit == ASDimensionUnitPoints && size.height.unit == ASDimensionUnitPoints); + return isPoints ? CGSizeMake(size.width.value, size.height.value) : CGSizeZero; +} + - (void)cancelLayoutTransitionsInProgress { [self cancelLayoutTransition]; diff --git a/AsyncDisplayKit/Layout/ASAbsoluteLayoutElement.h b/AsyncDisplayKit/Layout/ASAbsoluteLayoutElement.h index 58c5973ed6..7b6d269259 100644 --- a/AsyncDisplayKit/Layout/ASAbsoluteLayoutElement.h +++ b/AsyncDisplayKit/Layout/ASAbsoluteLayoutElement.h @@ -20,6 +20,11 @@ NS_ASSUME_NONNULL_BEGIN */ @property (nonatomic, assign) CGPoint layoutPosition; + +#pragma mark Deprecated + +@property (nonatomic, assign) ASRelativeSizeRange sizeRange ASDISPLAYNODE_DEPRECATED; + @end NS_ASSUME_NONNULL_END diff --git a/AsyncDisplayKit/Layout/ASAbsoluteLayoutSpec.h b/AsyncDisplayKit/Layout/ASAbsoluteLayoutSpec.h index 5ed9467f47..0f3cc89522 100644 --- a/AsyncDisplayKit/Layout/ASAbsoluteLayoutSpec.h +++ b/AsyncDisplayKit/Layout/ASAbsoluteLayoutSpec.h @@ -43,4 +43,13 @@ NS_ASSUME_NONNULL_BEGIN @end + +#pragma mark - Deprecated + +@interface ASStaticLayoutSpec : ASAbsoluteLayoutSpec + ++ (instancetype)staticLayoutSpecWithChildren:(NSArray> *)children AS_WARN_UNUSED_RESULT ASDISPLAYNODE_DEPRECATED; + +@end + NS_ASSUME_NONNULL_END diff --git a/AsyncDisplayKit/Layout/ASAbsoluteLayoutSpec.mm b/AsyncDisplayKit/Layout/ASAbsoluteLayoutSpec.mm index 5e6377d66f..6b6ff05832 100644 --- a/AsyncDisplayKit/Layout/ASAbsoluteLayoutSpec.mm +++ b/AsyncDisplayKit/Layout/ASAbsoluteLayoutSpec.mm @@ -10,11 +10,11 @@ #import "ASAbsoluteLayoutSpec.h" -#import "ASLayoutSpecUtilities.h" +#import "ASLayout.h" #import "ASLayoutPrivate.h" +#import "ASLayoutSpecUtilities.h" #import "ASLayoutElementStylePrivate.h" - #pragma mark - ASAbsoluteLayoutSpec @implementation ASAbsoluteLayoutSpec @@ -48,7 +48,7 @@ if (!(self = [super init])) { return nil; } - + _sizing = sizing; self.children = children; @@ -100,6 +100,8 @@ @end +#pragma mark - ASEnvironment + @implementation ASAbsoluteLayoutSpec (ASEnvironment) - (BOOL)supportsUpwardPropagation @@ -109,9 +111,9 @@ @end -@implementation ASAbsoluteLayoutSpec (Debugging) +#pragma mark - Debugging -#pragma mark - ASLayoutElementAsciiArtProtocol +@implementation ASAbsoluteLayoutSpec (Debugging) - (NSString *)debugBoxString { @@ -119,3 +121,20 @@ } @end + + +#pragma mark - ASStaticLayoutSpec + +@implementation ASStaticLayoutSpec : ASAbsoluteLayoutSpec + ++ (instancetype)staticLayoutSpecWithChildren:(NSArray> *)children +{ + return [self absoluteLayoutSpecWithSizing:ASAbsoluteLayoutSpecSizingSizeToFit children:children]; +} + +- (instancetype)initWithChildren:(NSArray *)children +{ + return [super initWithSizing:ASAbsoluteLayoutSpecSizingSizeToFit children:children]; +} + +@end diff --git a/AsyncDisplayKit/Layout/ASDimension.h b/AsyncDisplayKit/Layout/ASDimension.h index 37b8880e2e..5fd9a375f6 100644 --- a/AsyncDisplayKit/Layout/ASDimension.h +++ b/AsyncDisplayKit/Layout/ASDimension.h @@ -333,10 +333,81 @@ ASDISPLAYNODE_INLINE AS_WARN_UNUSED_RESULT ASSizeRange ASLayoutElementSizeResolv #pragma mark - Deprecated +/** + * A dimension relative to constraints to be provided in the future. + * A ASDimension can be one of three types: + * + * "Auto" - This indicated "I have no opinion" and may be resolved in whatever way makes most sense given the circumstances. + * + * "Points" - Just a number. It will always resolve to exactly this amount. + * + * "Percent" - Multiplied to a provided parent amount to resolve a final amount. + */ +typedef NS_ENUM(NSInteger, ASRelativeDimensionType) { + /** This indicates "I have no opinion" and may be resolved in whatever way makes most sense given the circumstances. */ + ASRelativeDimensionTypeAuto, + /** Just a number. It will always resolve to exactly this amount. This is the default type. */ + ASRelativeDimensionTypePoints, + /** Multiplied to a provided parent amount to resolve a final amount. */ + ASRelativeDimensionTypeFraction, +}; + +#define ASRelativeDimension ASDimension +#define ASRelativeSize ASLayoutSize +#define ASRelativeDimensionMakeWithPoints ASDimensionMakeWithPoints +#define ASRelativeDimensionMakeWithFraction ASDimensionMakeWithFraction + /** * Function is deprecated. Use ASSizeRangeMakeWithExactCGSize instead. */ extern AS_WARN_UNUSED_RESULT ASSizeRange ASSizeRangeMakeExactSize(CGSize size) ASDISPLAYNODE_DEPRECATED_MSG("Use ASSizeRangeMakeWithExactCGSize instead."); +/** + Expresses an inclusive range of relative sizes. Used to provide additional constraint to layout. + Used by ASStaticLayoutSpec. + */ +typedef struct { + ASLayoutSize min; + ASLayoutSize max; +} ASRelativeSizeRange; + +extern ASRelativeSizeRange const ASRelativeSizeRangeUnconstrained; + +#pragma mark - ASRelativeDimension + +extern ASDimension ASRelativeDimensionMake(ASRelativeDimensionType type, CGFloat value) ASDISPLAYNODE_DEPRECATED; + +#pragma mark - ASRelativeSize + +extern ASLayoutSize ASRelativeSizeMake(ASRelativeDimension width, ASRelativeDimension height) ASDISPLAYNODE_DEPRECATED; + +/** Convenience constructor to provide size in points. */ +extern ASLayoutSize ASRelativeSizeMakeWithCGSize(CGSize size) ASDISPLAYNODE_DEPRECATED; + +/** Convenience constructor to provide size as a fraction. */ +extern ASLayoutSize ASRelativeSizeMakeWithFraction(CGFloat fraction) ASDISPLAYNODE_DEPRECATED; + +extern BOOL ASRelativeSizeEqualToRelativeSize(ASLayoutSize lhs, ASLayoutSize rhs) ASDISPLAYNODE_DEPRECATED; + +extern NSString *NSStringFromASRelativeSize(ASLayoutSize size) ASDISPLAYNODE_DEPRECATED; + +#pragma mark - ASRelativeSizeRange + +extern ASRelativeSizeRange ASRelativeSizeRangeMake(ASLayoutSize min, ASLayoutSize max) ASDISPLAYNODE_DEPRECATED; + +#pragma mark Convenience constructors to provide an exact size (min == max). +extern ASRelativeSizeRange ASRelativeSizeRangeMakeWithExactRelativeSize(ASLayoutSize exact) ASDISPLAYNODE_DEPRECATED; + +extern ASRelativeSizeRange ASRelativeSizeRangeMakeWithExactCGSize(CGSize exact) ASDISPLAYNODE_DEPRECATED; + +extern ASRelativeSizeRange ASRelativeSizeRangeMakeWithExactFraction(CGFloat fraction) ASDISPLAYNODE_DEPRECATED; + +extern ASRelativeSizeRange ASRelativeSizeRangeMakeWithExactRelativeDimensions(ASRelativeDimension exactWidth, ASRelativeDimension exactHeight) ASDISPLAYNODE_DEPRECATED; + +extern BOOL ASRelativeSizeRangeEqualToRelativeSizeRange(ASRelativeSizeRange lhs, ASRelativeSizeRange rhs) ASDISPLAYNODE_DEPRECATED; + +/** Provided a parent size, compute final dimensions for this RelativeSizeRange to arrive at a SizeRange. */ +extern ASSizeRange ASRelativeSizeRangeResolve(ASRelativeSizeRange relativeSizeRange, CGSize parentSize) ASDISPLAYNODE_DEPRECATED; + NS_ASSUME_NONNULL_END ASDISPLAYNODE_EXTERN_C_END diff --git a/AsyncDisplayKit/Layout/ASDimension.mm b/AsyncDisplayKit/Layout/ASDimension.mm index 260b232e51..ff49a3de0b 100644 --- a/AsyncDisplayKit/Layout/ASDimension.mm +++ b/AsyncDisplayKit/Layout/ASDimension.mm @@ -188,7 +188,86 @@ NSString *NSStringFromASSizeRange(ASSizeRange sizeRange) #pragma mark - Deprecated +ASDimension ASRelativeDimensionMake(ASRelativeDimensionType type, CGFloat value) +{ + if (type == ASRelativeDimensionTypePoints) { + return ASDimensionMakeWithPoints(value); + } else if (type == ASRelativeDimensionTypeFraction) { + return ASDimensionMakeWithFraction(value); + } + + ASDisplayNodeCAssert(NO, @"ASRelativeDimensionMake does not support the given ASRelativeDimensionType"); + return ASDimensionMakeWithPoints(0); +} + ASSizeRange ASSizeRangeMakeExactSize(CGSize size) { return ASSizeRangeMake(size); } + +ASRelativeSizeRange const ASRelativeSizeRangeUnconstrained = {}; + +#pragma mark - ASRelativeSize + +ASLayoutSize ASRelativeSizeMake(ASRelativeDimension width, ASRelativeDimension height) +{ + return ASLayoutSizeMake(width, height); +} + +ASLayoutSize ASRelativeSizeMakeWithCGSize(CGSize size) +{ + return ASRelativeSizeMake(ASRelativeDimensionMakeWithPoints(size.width), + ASRelativeDimensionMakeWithPoints(size.height)); +} + +ASLayoutSize ASRelativeSizeMakeWithFraction(CGFloat fraction) +{ + return ASRelativeSizeMake(ASRelativeDimensionMakeWithFraction(fraction), + ASRelativeDimensionMakeWithFraction(fraction)); +} + +BOOL ASRelativeSizeEqualToRelativeSize(ASLayoutSize lhs, ASLayoutSize rhs) +{ + return ASDimensionEqualToDimension(lhs.width, rhs.width) + && ASDimensionEqualToDimension(lhs.height, rhs.height); +} + + +#pragma mark - ASRelativeSizeRange + +ASRelativeSizeRange ASRelativeSizeRangeMake(ASLayoutSize min, ASLayoutSize max) +{ + ASRelativeSizeRange sizeRange; sizeRange.min = min; sizeRange.max = max; return sizeRange; +} + +ASRelativeSizeRange ASRelativeSizeRangeMakeWithExactRelativeSize(ASLayoutSize exact) +{ + return ASRelativeSizeRangeMake(exact, exact); +} + +ASRelativeSizeRange ASRelativeSizeRangeMakeWithExactCGSize(CGSize exact) +{ + return ASRelativeSizeRangeMakeWithExactRelativeSize(ASRelativeSizeMakeWithCGSize(exact)); +} + +ASRelativeSizeRange ASRelativeSizeRangeMakeWithExactFraction(CGFloat fraction) +{ + return ASRelativeSizeRangeMakeWithExactRelativeSize(ASRelativeSizeMakeWithFraction(fraction)); +} + +ASRelativeSizeRange ASRelativeSizeRangeMakeWithExactRelativeDimensions(ASRelativeDimension exactWidth, ASRelativeDimension exactHeight) +{ + return ASRelativeSizeRangeMakeWithExactRelativeSize(ASRelativeSizeMake(exactWidth, exactHeight)); +} + +BOOL ASRelativeSizeRangeEqualToRelativeSizeRange(ASRelativeSizeRange lhs, ASRelativeSizeRange rhs) +{ + return ASRelativeSizeEqualToRelativeSize(lhs.min, rhs.min) && ASRelativeSizeEqualToRelativeSize(lhs.max, rhs.max); +} + +ASSizeRange ASRelativeSizeRangeResolve(ASRelativeSizeRange relativeSizeRange, + CGSize parentSize) +{ + return ASSizeRangeMake(ASLayoutSizeResolveSize(relativeSizeRange.min, parentSize, parentSize), + ASLayoutSizeResolveSize(relativeSizeRange.max, parentSize, parentSize)); +} diff --git a/AsyncDisplayKit/Layout/ASLayout.h b/AsyncDisplayKit/Layout/ASLayout.h index 0e145c1399..76389398f7 100644 --- a/AsyncDisplayKit/Layout/ASLayout.h +++ b/AsyncDisplayKit/Layout/ASLayout.h @@ -144,6 +144,23 @@ ASDISPLAYNODE_EXTERN_C_END @end +#pragma mark - Deprecated + +@interface ASLayout (Deprecated) + +- (id )layoutableObject ASDISPLAYNODE_DEPRECATED; + ++ (instancetype)layoutWithLayoutableObject:(id)layoutElement + constrainedSizeRange:(ASSizeRange)constrainedSizeRange + size:(CGSize)size ASDISPLAYNODE_DEPRECATED; + ++ (instancetype)layoutWithLayoutableObject:(id)layoutElement + constrainedSizeRange:(ASSizeRange)constrainedSizeRange + size:(CGSize)size + sublayouts:(nullable NSArray *)sublayouts AS_WARN_UNUSED_RESULT ASDISPLAYNODE_DEPRECATED; + +@end + #pragma mark - Debugging @interface ASLayout (Debugging) diff --git a/AsyncDisplayKit/Layout/ASLayout.mm b/AsyncDisplayKit/Layout/ASLayout.mm index 3a7c8d52fa..3b3c4a76b7 100644 --- a/AsyncDisplayKit/Layout/ASLayout.mm +++ b/AsyncDisplayKit/Layout/ASLayout.mm @@ -243,6 +243,30 @@ static inline NSString * descriptionIndents(NSUInteger indents) @end +@implementation ASLayout (Deprecation) + +- (id )layoutableObject +{ + return self.layoutElement; +} + ++ (instancetype)layoutWithLayoutableObject:(id)layoutElement + constrainedSizeRange:(ASSizeRange)constrainedSizeRange + size:(CGSize)size +{ + return [self layoutWithLayoutElement:layoutElement size:size]; +} + ++ (instancetype)layoutWithLayoutableObject:(id)layoutElement + constrainedSizeRange:(ASSizeRange)constrainedSizeRange + size:(CGSize)size + sublayouts:(nullable NSArray *)sublayouts +{ + return [self layoutWithLayoutElement:layoutElement size:size sublayouts:sublayouts]; +} + +@end + ASLayout *ASCalculateLayout(id layoutElement, const ASSizeRange sizeRange, const CGSize parentSize) { ASDisplayNodeCAssertNotNil(layoutElement, @"Not valid layoutElement passed in."); diff --git a/AsyncDisplayKit/Layout/ASLayoutElement.h b/AsyncDisplayKit/Layout/ASLayoutElement.h index fcfd99a10f..1e7b4c3967 100644 --- a/AsyncDisplayKit/Layout/ASLayoutElement.h +++ b/AsyncDisplayKit/Layout/ASLayoutElement.h @@ -50,7 +50,7 @@ NS_ASSUME_NONNULL_BEGIN * access to the options via convenience properties. If you are creating custom layout spec, then you can * extend the backing layout options class to accommodate any new layout options. */ -@protocol ASLayoutElement +@protocol ASLayoutElement #pragma mark - Getter @@ -74,7 +74,6 @@ NS_ASSUME_NONNULL_BEGIN */ @property (nullable, nonatomic, copy) NSString *debugName; - #pragma mark - Calculate layout /** @@ -320,3 +319,4 @@ extern NSString * const ASLayoutElementStyleLayoutPositionProperty; @end NS_ASSUME_NONNULL_END +#define ASLayoutable ASLayoutElement diff --git a/AsyncDisplayKit/Layout/ASLayoutElement.mm b/AsyncDisplayKit/Layout/ASLayoutElement.mm index 2f563124da..affa57314b 100644 --- a/AsyncDisplayKit/Layout/ASLayoutElement.mm +++ b/AsyncDisplayKit/Layout/ASLayoutElement.mm @@ -437,5 +437,23 @@ do {\ return _layoutPosition.load(); } +#pragma mark Deprecated + +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + +- (ASRelativeSizeRange)sizeRange +{ + return ASRelativeSizeRangeMake(self.minLayoutSize, self.maxLayoutSize); +} + +- (void)setSizeRange:(ASRelativeSizeRange)sizeRange +{ + self.minLayoutSize = sizeRange.min; + self.maxLayoutSize = sizeRange.max; +} + +#pragma clang diagnostic pop + @end diff --git a/AsyncDisplayKit/Layout/ASLayoutElementPrivate.h b/AsyncDisplayKit/Layout/ASLayoutElementPrivate.h index 8dded8c36f..70f3aa917f 100644 --- a/AsyncDisplayKit/Layout/ASLayoutElementPrivate.h +++ b/AsyncDisplayKit/Layout/ASLayoutElementPrivate.h @@ -93,3 +93,122 @@ extern void ASLayoutElementClearCurrentContext(); {\ return _ASEnvironmentLayoutOptionsExtensionGetEdgeInsetsAtIndex(self, idx);\ }\ + + + +#pragma mark - ASLayoutElementStyleForwarding (Deprecated) + +// For the time beeing we are forwading all style related properties on ASDisplayNode and ASLayoutSpec. This define +// help us to not have duplicate code while moving from 1.x to 2.0s +#define ASLayoutElementStyleForwarding \ +\ +@dynamic spacingBefore, spacingAfter, flexGrow, flexShrink, flexBasis, alignSelf, ascender, descender, sizeRange, layoutPosition;\ +\ +_Pragma("mark - ASStackLayoutElement")\ +\ +- (void)setSpacingBefore:(CGFloat)spacingBefore\ +{\ + self.style.spacingBefore = spacingBefore;\ +}\ +\ +- (CGFloat)spacingBefore\ +{\ + return self.style.spacingBefore;\ +}\ +\ +- (void)setSpacingAfter:(CGFloat)spacingAfter\ +{\ + self.style.spacingAfter = spacingAfter;\ +}\ +\ +- (CGFloat)spacingAfter\ +{\ + return self.style.spacingAfter;\ +}\ +\ +- (void)setFlexGrow:(CGFloat)flexGrow\ +{\ + self.style.flexGrow = flexGrow;\ +}\ +\ +- (CGFloat)flexGrow\ +{\ + return self.style.flexGrow;\ +}\ +\ +- (void)setFlexShrink:(CGFloat)flexShrink\ +{\ + self.style.flexShrink = flexShrink;\ +}\ +\ +- (CGFloat)flexShrink\ +{\ + return self.style.flexShrink;\ +}\ +\ +- (void)setFlexBasis:(ASDimension)flexBasis\ +{\ + self.style.flexBasis = flexBasis;\ +}\ +\ +- (ASDimension)flexBasis\ +{\ + return self.style.flexBasis;\ +}\ +\ +- (void)setAlignSelf:(ASStackLayoutAlignSelf)alignSelf\ +{\ + self.style.alignSelf = alignSelf;\ +}\ +\ +- (ASStackLayoutAlignSelf)alignSelf\ +{\ + return self.style.alignSelf;\ +}\ +\ +- (void)setAscender:(CGFloat)ascender\ +{\ + self.style.ascender = ascender;\ +}\ +\ +- (CGFloat)ascender\ +{\ + return self.style.ascender;\ +}\ +\ +- (void)setDescender:(CGFloat)descender\ +{\ + self.style.descender = descender;\ +}\ +\ +- (CGFloat)descender\ +{\ + return self.style.descender;\ +}\ +\ +_Pragma("mark - ASAbsoluteLayoutElement")\ +\ +- (void)setLayoutPosition:(CGPoint)layoutPosition\ +{\ + self.style.layoutPosition = layoutPosition;\ +}\ +\ +- (CGPoint)layoutPosition\ +{\ + return self.style.layoutPosition;\ +}\ +\ +_Pragma("clang diagnostic push")\ +_Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"")\ +\ +- (void)setSizeRange:(ASRelativeSizeRange)sizeRange\ +{\ + self.style.sizeRange = sizeRange;\ +}\ +\ +- (ASRelativeSizeRange)sizeRange\ +{\ + return self.style.sizeRange;\ +}\ +\ +_Pragma("clang diagnostic pop")\ diff --git a/AsyncDisplayKit/Layout/ASLayoutSpec.h b/AsyncDisplayKit/Layout/ASLayoutSpec.h index cce02aaee4..4b583cb9fa 100644 --- a/AsyncDisplayKit/Layout/ASLayoutSpec.h +++ b/AsyncDisplayKit/Layout/ASLayoutSpec.h @@ -16,7 +16,7 @@ NS_ASSUME_NONNULL_BEGIN /** * A layout spec is an immutable object that describes a layout, loosely inspired by React. */ -@interface ASLayoutSpec : NSObject +@interface ASLayoutSpec : NSObject /** * Creation of a layout spec should only happen by a user in layoutSpecThatFits:. During that method, a diff --git a/AsyncDisplayKit/Layout/ASLayoutSpec.mm b/AsyncDisplayKit/Layout/ASLayoutSpec.mm index d1dc4126bc..fec8c53be7 100644 --- a/AsyncDisplayKit/Layout/ASLayoutSpec.mm +++ b/AsyncDisplayKit/Layout/ASLayoutSpec.mm @@ -83,12 +83,6 @@ #pragma mark - Layout -// Deprecated -- (ASLayout *)measureWithSizeRange:(ASSizeRange)constrainedSize -{ - return [self layoutThatFits:constrainedSize]; -} - - (ASLayout *)layoutThatFits:(ASSizeRange)constrainedSize { return [self layoutThatFits:constrainedSize parentSize:constrainedSize.max]; @@ -293,6 +287,15 @@ ASEnvironmentLayoutExtensibilityForwarding } } +#pragma mark - Deprecated + +- (ASLayout *)measureWithSizeRange:(ASSizeRange)constrainedSize +{ + return [self layoutThatFits:constrainedSize]; +} + +ASLayoutElementStyleForwarding + @end #pragma mark - ASWrapperLayoutSpec diff --git a/AsyncDisplayKitTests/ASDisplayNodeImplicitHierarchyTests.m b/AsyncDisplayKitTests/ASDisplayNodeImplicitHierarchyTests.m index 6944e676e5..51f8c26ee6 100644 --- a/AsyncDisplayKitTests/ASDisplayNodeImplicitHierarchyTests.m +++ b/AsyncDisplayKitTests/ASDisplayNodeImplicitHierarchyTests.m @@ -118,20 +118,21 @@ XCTAssertEqual(node.subnodes[2], node2); } -- (void)testLayoutTransitionWillThrowForManualSubnodeManagement -{ - ASDisplayNode *node1 = [[ASDisplayNode alloc] init]; - node1.debugName = @"node1"; - - ASSpecTestDisplayNode *node = [[ASSpecTestDisplayNode alloc] init]; - node.automaticallyManagesSubnodes = YES; - node.layoutSpecBlock = ^ASLayoutSpec *(ASDisplayNode *weakNode, ASSizeRange constrainedSize){ - return [ASAbsoluteLayoutSpec absoluteLayoutSpecWithChildren:@[node1]]; - }; - - XCTAssertNoThrow([node layoutThatFits:ASSizeRangeMake(CGSizeZero)]); - XCTAssertThrows([node1 removeFromSupernode]); -} +// Disable test for now as we disabled the assertion +//- (void)testLayoutTransitionWillThrowForManualSubnodeManagement +//{ +// ASDisplayNode *node1 = [[ASDisplayNode alloc] init]; +// node1.name = @"node1"; +// +// ASSpecTestDisplayNode *node = [[ASSpecTestDisplayNode alloc] init]; +// node.automaticallyManagesSubnodes = YES; +// node.layoutSpecBlock = ^ASLayoutSpec *(ASDisplayNode *weakNode, ASSizeRange constrainedSize){ +// return [ASAbsoluteLayoutSpec absoluteLayoutSpecWithChildren:@[node1]]; +// }; +// +// XCTAssertNoThrow([node layoutThatFits:ASSizeRangeMake(CGSizeZero)]); +// XCTAssertThrows([node1 removeFromSupernode]); +//} - (void)testLayoutTransitionMeasurementCompletionBlockIsCalledOnMainThread { diff --git a/Base/ASBaseDefines.h b/Base/ASBaseDefines.h index bfa3de4aec..8db12be97e 100755 --- a/Base/ASBaseDefines.h +++ b/Base/ASBaseDefines.h @@ -71,7 +71,7 @@ #endif #ifndef ASDISPLAYNODE_WARN_DEPRECATED -# define ASDISPLAYNODE_WARN_DEPRECATED 1 +# define ASDISPLAYNODE_WARN_DEPRECATED 0 #endif #ifndef ASDISPLAYNODE_DEPRECATED