[AsyncDisplayKit 2] Final changes to ease migration of clients to 2.0 APIs. (#2460)

This commit is contained in:
appleguy
2016-10-21 13:12:13 -07:00
committed by GitHub
parent e87ac54138
commit 2c6f8b0506
17 changed files with 470 additions and 72 deletions

View File

@@ -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

View File

@@ -812,9 +812,33 @@ extern NSInteger const ASDefaultDrawingPriority;
*/
- (void)cancelLayoutTransition;
@end
@interface ASDisplayNode (Deprecated) <ASStackLayoutElement, ASAbsoluteLayoutElement>
#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

View File

@@ -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];

View File

@@ -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

View File

@@ -43,4 +43,13 @@ NS_ASSUME_NONNULL_BEGIN
@end
#pragma mark - Deprecated
@interface ASStaticLayoutSpec : ASAbsoluteLayoutSpec
+ (instancetype)staticLayoutSpecWithChildren:(NSArray<id<ASLayoutElement>> *)children AS_WARN_UNUSED_RESULT ASDISPLAYNODE_DEPRECATED;
@end
NS_ASSUME_NONNULL_END

View File

@@ -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
@@ -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<id<ASLayoutElement>> *)children
{
return [self absoluteLayoutSpecWithSizing:ASAbsoluteLayoutSpecSizingSizeToFit children:children];
}
- (instancetype)initWithChildren:(NSArray *)children
{
return [super initWithSizing:ASAbsoluteLayoutSpecSizingSizeToFit children:children];
}
@end

View File

@@ -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

View File

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

View File

@@ -144,6 +144,23 @@ ASDISPLAYNODE_EXTERN_C_END
@end
#pragma mark - Deprecated
@interface ASLayout (Deprecated)
- (id <ASLayoutElement>)layoutableObject ASDISPLAYNODE_DEPRECATED;
+ (instancetype)layoutWithLayoutableObject:(id<ASLayoutElement>)layoutElement
constrainedSizeRange:(ASSizeRange)constrainedSizeRange
size:(CGSize)size ASDISPLAYNODE_DEPRECATED;
+ (instancetype)layoutWithLayoutableObject:(id<ASLayoutElement>)layoutElement
constrainedSizeRange:(ASSizeRange)constrainedSizeRange
size:(CGSize)size
sublayouts:(nullable NSArray<ASLayout *> *)sublayouts AS_WARN_UNUSED_RESULT ASDISPLAYNODE_DEPRECATED;
@end
#pragma mark - Debugging
@interface ASLayout (Debugging)

View File

@@ -243,6 +243,30 @@ static inline NSString * descriptionIndents(NSUInteger indents)
@end
@implementation ASLayout (Deprecation)
- (id <ASLayoutElement>)layoutableObject
{
return self.layoutElement;
}
+ (instancetype)layoutWithLayoutableObject:(id<ASLayoutElement>)layoutElement
constrainedSizeRange:(ASSizeRange)constrainedSizeRange
size:(CGSize)size
{
return [self layoutWithLayoutElement:layoutElement size:size];
}
+ (instancetype)layoutWithLayoutableObject:(id<ASLayoutElement>)layoutElement
constrainedSizeRange:(ASSizeRange)constrainedSizeRange
size:(CGSize)size
sublayouts:(nullable NSArray<ASLayout *> *)sublayouts
{
return [self layoutWithLayoutElement:layoutElement size:size sublayouts:sublayouts];
}
@end
ASLayout *ASCalculateLayout(id<ASLayoutElement> layoutElement, const ASSizeRange sizeRange, const CGSize parentSize)
{
ASDisplayNodeCAssertNotNil(layoutElement, @"Not valid layoutElement passed in.");

View File

@@ -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 <ASEnvironment, ASLayoutElementPrivate, ASLayoutElementExtensibility, ASLayoutElementStylability, NSFastEnumeration>
@protocol ASLayoutElement <ASEnvironment, ASLayoutElementPrivate, ASLayoutElementExtensibility, ASLayoutElementStylability, NSFastEnumeration, ASStackLayoutElement, ASAbsoluteLayoutElement>
#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

View File

@@ -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

View File

@@ -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")\

View File

@@ -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 <ASLayoutElement>
@interface ASLayoutSpec : NSObject <ASLayoutElement, ASStackLayoutElement, ASAbsoluteLayoutElement>
/**
* Creation of a layout spec should only happen by a user in layoutSpecThatFits:. During that method, a

View File

@@ -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

View File

@@ -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
{

View File

@@ -71,7 +71,7 @@
#endif
#ifndef ASDISPLAYNODE_WARN_DEPRECATED
# define ASDISPLAYNODE_WARN_DEPRECATED 1
# define ASDISPLAYNODE_WARN_DEPRECATED 0
#endif
#ifndef ASDISPLAYNODE_DEPRECATED