Skip to content

Commit

Permalink
Address PR comments
Browse files Browse the repository at this point in the history
- Delegate to layout spec engine if the node is a layout spec node but yoga engine was asked for calculate the layout
- Change ASLayoutType to ASLayoutEngineType
- Improve layout engine fall through code
  • Loading branch information
maicki committed Jan 11, 2019
1 parent 9d1234a commit 9afd7d1
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 17 deletions.
6 changes: 3 additions & 3 deletions Source/ASDisplayNode+Layout.mm
Original file line number Diff line number Diff line change
Expand Up @@ -144,19 +144,19 @@ - (NSString *)asciiArtName

@implementation ASDisplayNode (ASLayout)

- (ASLayoutType)layoutType
- (ASLayoutEngineType)layoutEngineType
{
#if YOGA
ASDN::MutexLocker l(__instanceLock__);
YGNodeRef yogaNode = _style.yogaNode;
BOOL hasYogaParent = (_yogaParent != nil);
BOOL hasYogaChildren = (_yogaChildren.count > 0);
if (yogaNode != NULL && (hasYogaParent || hasYogaChildren)) {
return ASLayoutTypeYoga;
return ASLayoutEngineTypeYoga;
}
#endif

return ASLayoutTypeLayoutSpec;
return ASLayoutEngineTypeLayoutSpec;
}

- (ASLayout *)calculatedLayout
Expand Down
8 changes: 4 additions & 4 deletions Source/ASDisplayNode+Yoga.mm
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#import <AsyncDisplayKit/ASLayout.h>
#import <AsyncDisplayKit/ASLayoutElementStylePrivate.h>

#import <AsyncDisplayKit/ASDisplayNode+LayoutSpec.h>

#define YOGA_LAYOUT_LOGGING 0

#pragma mark - ASDisplayNode+Yoga
Expand Down Expand Up @@ -321,10 +323,8 @@ - (ASLayout *)calculateLayoutYoga:(ASSizeRange)constrainedSize
}
}

// Manual size calculation via calculateSizeThatFits:
CGSize size = [self calculateSizeThatFits:constrainedSize.max];
ASDisplayNodeLogEvent(self, @"calculatedSize: %@", NSStringFromCGSize(size));
return [ASLayout layoutWithLayoutElement:self size:ASSizeRangeClamp(constrainedSize, size) sublayouts:nil];
// Delegate to layout spec layout for nodes that do not support Yoga
return [self calculateLayoutLayoutSpec:constrainedSize];
}

- (void)calculateLayoutFromYogaRoot:(ASSizeRange)rootConstrainedSize
Expand Down
8 changes: 4 additions & 4 deletions Source/ASDisplayNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -817,17 +817,17 @@ AS_EXTERN NSInteger const ASDefaultDrawingPriority;

@end

typedef NS_ENUM(NSInteger, ASLayoutType) {
ASLayoutTypeLayoutSpec,
ASLayoutTypeYoga
typedef NS_ENUM(NSInteger, ASLayoutEngineType) {
ASLayoutEngineTypeLayoutSpec,
ASLayoutEngineTypeYoga
};

@interface ASDisplayNode (ASLayout)

/**
* @abstract Returns the current layout type the node uses for layout the subtree.
*/
@property (readonly) ASLayoutType layoutType;
@property (readonly) ASLayoutEngineType layoutEngineType;

/**
* @abstract Return the calculated size.
Expand Down
14 changes: 9 additions & 5 deletions Source/ASDisplayNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1110,18 +1110,22 @@ - (ASLayout *)calculateLayoutThatFits:(ASSizeRange)constrainedSize
{
__ASDisplayNodeCheckForLayoutMethodOverrides;

switch (self.layoutType) {
case ASLayoutTypeLayoutSpec:
switch (self.layoutEngineType) {
case ASLayoutEngineTypeLayoutSpec:
return [self calculateLayoutLayoutSpec:constrainedSize];
case ASLayoutTypeYoga:
#if YOGA
case ASLayoutEngineTypeYoga:
return [self calculateLayoutYoga:constrainedSize];
#endif
// If not YOGA we fallthrough here
// If YOGA is not defined but for some reason the layout type engine is Yoga
// we explicitly fallthrough here
default:
ASDisplayNodeAssert(NO, @"No layout type determined");
break;
}

// If this case is reached a layout type engine was defined for a node that is currently
// not supported.
ASDisplayNodeAssert(NO, @"No layout type determined");
return nil;
}

Expand Down
1 change: 0 additions & 1 deletion Source/Private/ASDisplayNodeInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ AS_EXTERN NSString * const ASRenderingEngineDidDisplayNodesScheduledBeforeTimest
NSInteger _layoutComputationNumberOfPasses;



// View Loading
ASDisplayNodeViewBlock _viewBlock;
ASDisplayNodeLayerBlock _layerBlock;
Expand Down

0 comments on commit 9afd7d1

Please sign in to comment.