Introduce type property to replace layout id check

This commit is contained in:
Levi McCallum
2016-06-08 18:28:21 -07:00
parent a3e8f556a3
commit 7e8d519a9a
5 changed files with 36 additions and 6 deletions

View File

@@ -62,7 +62,9 @@ NSString * const ASRenderingEngineDidDisplayNodesScheduledBeforeTimestamp = @"AS
@implementation ASDisplayNode @implementation ASDisplayNode
// these dynamic properties all defined in ASLayoutOptionsPrivate.m // these dynamic properties all defined in ASLayoutOptionsPrivate.m
@dynamic spacingAfter, spacingBefore, flexGrow, flexShrink, flexBasis, alignSelf, ascender, descender, sizeRange, layoutPosition; @dynamic spacingAfter, spacingBefore, flexGrow, flexShrink, flexBasis,
alignSelf, ascender, descender, sizeRange, layoutPosition, layoutableType;
@synthesize name = _name; @synthesize name = _name;
@synthesize preferredFrameSize = _preferredFrameSize; @synthesize preferredFrameSize = _preferredFrameSize;
@synthesize isFinalLayoutable = _isFinalLayoutable; @synthesize isFinalLayoutable = _isFinalLayoutable;
@@ -659,6 +661,11 @@ static ASDisplayNodeMethodOverrides GetASDisplayNodeMethodOverrides(Class c)
return _layout == nil || _layout.isDirty; return _layout == nil || _layout.isDirty;
} }
- (ASLayoutableType)layoutableType
{
return ASLayoutableTypeDisplayNode;
}
#pragma mark - Layout Transition #pragma mark - Layout Transition
- (void)transitionLayoutWithAnimation:(BOOL)animated - (void)transitionLayoutWithAnimation:(BOOL)animated

View File

@@ -31,6 +31,11 @@ extern BOOL CGPointIsNull(CGPoint point);
*/ */
@property (nonatomic, weak, readonly) id<ASLayoutable> layoutableObject; @property (nonatomic, weak, readonly) id<ASLayoutable> layoutableObject;
/**
* The type of ASLayoutable that created this layout
*/
@property (nonatomic, readonly) ASLayoutableType type;
/** /**
* Size of the current layout * Size of the current layout
*/ */

View File

@@ -12,7 +12,6 @@
#import "ASAssert.h" #import "ASAssert.h"
#import "ASDimension.h" #import "ASDimension.h"
#import "ASDisplayNode.h"
#import "ASInternalHelpers.h" #import "ASInternalHelpers.h"
#import "ASLayoutSpecUtilities.h" #import "ASLayoutSpecUtilities.h"
@@ -36,7 +35,7 @@ extern BOOL CGPointIsNull(CGPoint point)
@implementation ASLayout @implementation ASLayout
@dynamic frame; @dynamic frame, type;
- (instancetype)initWithLayoutableObject:(id<ASLayoutable>)layoutableObject - (instancetype)initWithLayoutableObject:(id<ASLayoutable>)layoutableObject
constrainedSizeRange:(ASSizeRange)sizeRange constrainedSizeRange:(ASSizeRange)sizeRange
@@ -159,7 +158,7 @@ extern BOOL CGPointIsNull(CGPoint point)
Context context = queue.front(); Context context = queue.front();
queue.pop(); queue.pop();
if (self != context.layout && [context.layout.layoutableObject isKindOfClass:[ASDisplayNode class]]) { if (self != context.layout && context.layout.type == ASLayoutableTypeDisplayNode) {
ASLayout *layout = [ASLayout layoutWithLayout:context.layout position:context.absolutePosition]; ASLayout *layout = [ASLayout layoutWithLayout:context.layout position:context.absolutePosition];
layout.flattened = YES; layout.flattened = YES;
[flattenedSublayouts addObject:layout]; [flattenedSublayouts addObject:layout];
@@ -178,6 +177,13 @@ extern BOOL CGPointIsNull(CGPoint point)
sublayouts:flattenedSublayouts]; sublayouts:flattenedSublayouts];
} }
#pragma mark - Accessors
- (ASLayoutableType)type
{
return _layoutableObject.layoutableType;
}
- (CGRect)frame - (CGRect)frame
{ {
CGRect subnodeFrame = CGRectZero; CGRect subnodeFrame = CGRectZero;

View File

@@ -34,7 +34,8 @@
@implementation ASLayoutSpec @implementation ASLayoutSpec
// these dynamic properties all defined in ASLayoutOptionsPrivate.m // these dynamic properties all defined in ASLayoutOptionsPrivate.m
@dynamic spacingAfter, spacingBefore, flexGrow, flexShrink, flexBasis, alignSelf, ascender, descender, sizeRange, layoutPosition; @dynamic spacingAfter, spacingBefore, flexGrow, flexShrink, flexBasis,
alignSelf, ascender, descender, sizeRange, layoutPosition, layoutableType;
@synthesize isFinalLayoutable = _isFinalLayoutable; @synthesize isFinalLayoutable = _isFinalLayoutable;
- (instancetype)init - (instancetype)init
@@ -48,6 +49,11 @@
return self; return self;
} }
- (ASLayoutableType)layoutableType
{
return ASLayoutableTypeLayoutSpec;
}
#pragma mark - Layout #pragma mark - Layout
- (ASLayout *)measureWithSizeRange:(ASSizeRange)constrainedSize - (ASLayout *)measureWithSizeRange:(ASSizeRange)constrainedSize

View File

@@ -21,6 +21,11 @@
@class ASLayout; @class ASLayout;
@class ASLayoutSpec; @class ASLayoutSpec;
typedef NS_ENUM(NSUInteger, ASLayoutableType) {
ASLayoutableTypeLayoutSpec,
ASLayoutableTypeDisplayNode
};
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
/** /**
@@ -41,6 +46,8 @@ NS_ASSUME_NONNULL_BEGIN
*/ */
@protocol ASLayoutable <ASEnvironment, ASStackLayoutable, ASStaticLayoutable, ASLayoutablePrivate, ASLayoutableExtensibility> @protocol ASLayoutable <ASEnvironment, ASStackLayoutable, ASStaticLayoutable, ASLayoutablePrivate, ASLayoutableExtensibility>
@property (nonatomic, readonly) ASLayoutableType layoutableType;
/** /**
* @abstract Calculate a layout based on given size range. * @abstract Calculate a layout based on given size range.
* *
@@ -50,7 +57,6 @@ NS_ASSUME_NONNULL_BEGIN
*/ */
- (ASLayout *)measureWithSizeRange:(ASSizeRange)constrainedSize; - (ASLayout *)measureWithSizeRange:(ASSizeRange)constrainedSize;
#pragma mark - Layout options from the Layoutable Protocols #pragma mark - Layout options from the Layoutable Protocols
#pragma mark - ASStackLayoutable #pragma mark - ASStackLayoutable