From 1331e40bc5c49011982351e4e259bed487197c24 Mon Sep 17 00:00:00 2001 From: Adlai Holler Date: Fri, 29 Jun 2018 18:21:30 -0700 Subject: [PATCH 1/2] Remove yoga layout spec, which has been superseded by tighter yoga-display node integration --- AsyncDisplayKit.xcodeproj/project.pbxproj | 8 - Source/ASDisplayNode+Yoga.mm | 1 - Source/Layout/ASYogaLayoutSpec.h | 24 --- Source/Layout/ASYogaLayoutSpec.mm | 177 ---------------------- 4 files changed, 210 deletions(-) delete mode 100644 Source/Layout/ASYogaLayoutSpec.h delete mode 100644 Source/Layout/ASYogaLayoutSpec.mm diff --git a/AsyncDisplayKit.xcodeproj/project.pbxproj b/AsyncDisplayKit.xcodeproj/project.pbxproj index dc551d2e8..bb8227f27 100644 --- a/AsyncDisplayKit.xcodeproj/project.pbxproj +++ b/AsyncDisplayKit.xcodeproj/project.pbxproj @@ -181,8 +181,6 @@ 8BBBAB8D1CEBAF1E00107FC6 /* ASDefaultPlaybackButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 8B0768B21CE752EC002E1453 /* ASDefaultPlaybackButton.m */; }; 8BDA5FC71CDBDF91007D13B2 /* ASVideoPlayerNode.h in Headers */ = {isa = PBXBuildFile; fileRef = 8BDA5FC31CDBDDE1007D13B2 /* ASVideoPlayerNode.h */; settings = {ATTRIBUTES = (Public, ); }; }; 8BDA5FC81CDBDF95007D13B2 /* ASVideoPlayerNode.mm in Sources */ = {isa = PBXBuildFile; fileRef = 8BDA5FC41CDBDDE1007D13B2 /* ASVideoPlayerNode.mm */; }; - 9019FBBD1ED8061D00C45F72 /* ASYogaLayoutSpec.h in Headers */ = {isa = PBXBuildFile; fileRef = 9019FBB91ED8061D00C45F72 /* ASYogaLayoutSpec.h */; }; - 9019FBBE1ED8061D00C45F72 /* ASYogaLayoutSpec.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9019FBBA1ED8061D00C45F72 /* ASYogaLayoutSpec.mm */; }; 9019FBBF1ED8061D00C45F72 /* ASYogaUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 9019FBBB1ED8061D00C45F72 /* ASYogaUtilities.h */; }; 9019FBC01ED8061D00C45F72 /* ASYogaUtilities.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9019FBBC1ED8061D00C45F72 /* ASYogaUtilities.mm */; }; 909C4C751F09C98B00D6B76F /* ASTextNode2.h in Headers */ = {isa = PBXBuildFile; fileRef = 909C4C731F09C98B00D6B76F /* ASTextNode2.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -739,8 +737,6 @@ 8B0768B21CE752EC002E1453 /* ASDefaultPlaybackButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ASDefaultPlaybackButton.m; sourceTree = ""; }; 8BDA5FC31CDBDDE1007D13B2 /* ASVideoPlayerNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASVideoPlayerNode.h; sourceTree = ""; }; 8BDA5FC41CDBDDE1007D13B2 /* ASVideoPlayerNode.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ASVideoPlayerNode.mm; sourceTree = ""; }; - 9019FBB91ED8061D00C45F72 /* ASYogaLayoutSpec.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASYogaLayoutSpec.h; sourceTree = ""; }; - 9019FBBA1ED8061D00C45F72 /* ASYogaLayoutSpec.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ASYogaLayoutSpec.mm; sourceTree = ""; }; 9019FBBB1ED8061D00C45F72 /* ASYogaUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASYogaUtilities.h; sourceTree = ""; }; 9019FBBC1ED8061D00C45F72 /* ASYogaUtilities.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ASYogaUtilities.mm; sourceTree = ""; }; 909C4C731F09C98B00D6B76F /* ASTextNode2.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASTextNode2.h; sourceTree = ""; }; @@ -1657,8 +1653,6 @@ 9C49C36E1B853957000B0DD5 /* ASStackLayoutElement.h */, ACF6ED161B17843500DA7C62 /* ASStackLayoutSpec.h */, ACF6ED171B17843500DA7C62 /* ASStackLayoutSpec.mm */, - 9019FBB91ED8061D00C45F72 /* ASYogaLayoutSpec.h */, - 9019FBBA1ED8061D00C45F72 /* ASYogaLayoutSpec.mm */, 9019FBBB1ED8061D00C45F72 /* ASYogaUtilities.h */, 9019FBBC1ED8061D00C45F72 /* ASYogaUtilities.mm */, ); @@ -1992,7 +1986,6 @@ CCF18FF41D2575E300DF5895 /* NSIndexSet+ASHelpers.h in Headers */, 83A7D95C1D44548100BF333E /* ASWeakMap.h in Headers */, E5711A2C1C840C81009619D4 /* ASCollectionElement.h in Headers */, - 9019FBBD1ED8061D00C45F72 /* ASYogaLayoutSpec.h in Headers */, 6947B0BE1E36B4E30007C478 /* ASStackUnpositionedLayout.h in Headers */, CC4C2A771D88E3BF0039ACAB /* ASTraceEvent.h in Headers */, 254C6B7B1BF94DF4003EC431 /* ASTextKitRenderer+Positioning.h in Headers */, @@ -2451,7 +2444,6 @@ 6907C25A1DC4ECFE00374C66 /* ASObjectDescriptionHelpers.m in Sources */, B35062051B010EFD0018CF92 /* ASMultiplexImageNode.mm in Sources */, B35062251B010EFD0018CF92 /* ASMutableAttributedStringBuilder.m in Sources */, - 9019FBBE1ED8061D00C45F72 /* ASYogaLayoutSpec.mm in Sources */, B35062071B010EFD0018CF92 /* ASNetworkImageNode.mm in Sources */, 34EFC76D1B701CF100AD841F /* ASOverlayLayoutSpec.mm in Sources */, 044285101BAA64EC00D16268 /* ASTwoDimensionalArrayUtils.m in Sources */, diff --git a/Source/ASDisplayNode+Yoga.mm b/Source/ASDisplayNode+Yoga.mm index ea5af2bb6..ea9739de8 100644 --- a/Source/ASDisplayNode+Yoga.mm +++ b/Source/ASDisplayNode+Yoga.mm @@ -20,7 +20,6 @@ #if YOGA /* YOGA */ #import -#import #import #import #import diff --git a/Source/Layout/ASYogaLayoutSpec.h b/Source/Layout/ASYogaLayoutSpec.h deleted file mode 100644 index 75c9d09be..000000000 --- a/Source/Layout/ASYogaLayoutSpec.h +++ /dev/null @@ -1,24 +0,0 @@ -// -// ASYogaLayoutSpec.h -// Texture -// -// Copyright (c) 2017-present, Pinterest, Inc. All rights reserved. -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// - -#import - -#if YOGA /* YOGA */ - -#import -#import - -@interface ASYogaLayoutSpec : ASLayoutSpec -@property (nonatomic, nonnull) ASDisplayNode *rootNode; -@end - -#endif /* YOGA */ diff --git a/Source/Layout/ASYogaLayoutSpec.mm b/Source/Layout/ASYogaLayoutSpec.mm deleted file mode 100644 index e0cc80e51..000000000 --- a/Source/Layout/ASYogaLayoutSpec.mm +++ /dev/null @@ -1,177 +0,0 @@ -// -// ASYogaLayoutSpec.mm -// Texture -// -// Copyright (c) 2017-present, Pinterest, Inc. All rights reserved. -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// - -#import - -#if YOGA /* YOGA */ - -#import -#import -#import -#import -#import - -#define YOGA_LAYOUT_LOGGING 0 - -@implementation ASYogaLayoutSpec - -- (ASLayout *)layoutForYogaNode:(YGNodeRef)yogaNode -{ - BOOL isRootNode = (YGNodeGetParent(yogaNode) == NULL); - uint32_t childCount = YGNodeGetChildCount(yogaNode); - - NSMutableArray *sublayouts = [NSMutableArray arrayWithCapacity:childCount]; - for (uint32_t i = 0; i < childCount; i++) { - [sublayouts addObject:[self layoutForYogaNode:YGNodeGetChild(yogaNode, i)]]; - } - - id layoutElement = (__bridge id )YGNodeGetContext(yogaNode); - CGSize size = CGSizeMake(YGNodeLayoutGetWidth(yogaNode), YGNodeLayoutGetHeight(yogaNode)); - - if (isRootNode) { - // The layout for root should have position CGPointNull, but include the calculated size. - return [ASLayout layoutWithLayoutElement:layoutElement size:size sublayouts:sublayouts]; - } else { - CGPoint position = CGPointMake(YGNodeLayoutGetLeft(yogaNode), YGNodeLayoutGetTop(yogaNode)); - return [ASLayout layoutWithLayoutElement:layoutElement size:size position:position sublayouts:nil]; - } -} - -- (void)destroyYogaNode:(YGNodeRef)yogaNode -{ - // Release the __bridge_retained Context object. - __unused id element = (__bridge_transfer id)YGNodeGetContext(yogaNode); - YGNodeFree(yogaNode); -} - -- (void)setupYogaNode:(YGNodeRef)yogaNode forElement:(id )element withParentYogaNode:(YGNodeRef)parentYogaNode -{ - ASLayoutElementStyle *style = element.style; - - // Retain the Context object. This must be explicitly released with a __bridge_transfer; YGNodeFree() is not sufficient. - YGNodeSetContext(yogaNode, (__bridge_retained void *)element); - - YGNodeStyleSetDirection (yogaNode, style.direction); - - YGNodeStyleSetFlexWrap (yogaNode, style.flexWrap); - YGNodeStyleSetFlexGrow (yogaNode, style.flexGrow); - YGNodeStyleSetFlexShrink (yogaNode, style.flexShrink); - YGNODE_STYLE_SET_DIMENSION (yogaNode, FlexBasis, style.flexBasis); - - YGNodeStyleSetFlexDirection (yogaNode, yogaFlexDirection(style.flexDirection)); - YGNodeStyleSetJustifyContent(yogaNode, yogaJustifyContent(style.justifyContent)); - YGNodeStyleSetAlignSelf (yogaNode, yogaAlignSelf(style.alignSelf)); - ASStackLayoutAlignItems alignItems = style.alignItems; - if (alignItems != ASStackLayoutAlignItemsNotSet) { - YGNodeStyleSetAlignItems(yogaNode, yogaAlignItems(alignItems)); - } - - YGNodeStyleSetPositionType (yogaNode, style.positionType); - ASEdgeInsets position = style.position; - ASEdgeInsets margin = style.margin; - ASEdgeInsets padding = style.padding; - ASEdgeInsets border = style.border; - - YGEdge edge = YGEdgeLeft; - for (int i = 0; i < YGEdgeAll + 1; ++i) { - YGNODE_STYLE_SET_DIMENSION_WITH_EDGE(yogaNode, Position, dimensionForEdgeWithEdgeInsets(edge, position), edge); - YGNODE_STYLE_SET_DIMENSION_WITH_EDGE(yogaNode, Margin, dimensionForEdgeWithEdgeInsets(edge, margin), edge); - YGNODE_STYLE_SET_DIMENSION_WITH_EDGE(yogaNode, Padding, dimensionForEdgeWithEdgeInsets(edge, padding), edge); - YGNODE_STYLE_SET_FLOAT_WITH_EDGE(yogaNode, Border, dimensionForEdgeWithEdgeInsets(edge, border), edge); - edge = (YGEdge)(edge + 1); - } - - CGFloat aspectRatio = style.aspectRatio; - if (aspectRatio > FLT_EPSILON && aspectRatio < CGFLOAT_MAX / 2.0) { - YGNodeStyleSetAspectRatio(yogaNode, aspectRatio); - } - - // For the root node, we use rootConstrainedSize above. For children, consult the style for their size. - if (parentYogaNode != NULL) { - YGNodeInsertChild(parentYogaNode, yogaNode, YGNodeGetChildCount(parentYogaNode)); - - YGNODE_STYLE_SET_DIMENSION(yogaNode, Width, style.width); - YGNODE_STYLE_SET_DIMENSION(yogaNode, Height, style.height); - - YGNODE_STYLE_SET_DIMENSION(yogaNode, MinWidth, style.minWidth); - YGNODE_STYLE_SET_DIMENSION(yogaNode, MinHeight, style.minHeight); - - YGNODE_STYLE_SET_DIMENSION(yogaNode, MaxWidth, style.maxWidth); - YGNODE_STYLE_SET_DIMENSION(yogaNode, MaxHeight, style.maxHeight); - - YGNodeSetMeasureFunc(yogaNode, &ASLayoutElementYogaMeasureFunc); - } - - // TODO(appleguy): STYLE SETTER METHODS LEFT TO IMPLEMENT: YGNodeStyleSetOverflow, YGNodeStyleSetFlex -} - -- (ASLayout *)calculateLayoutThatFits:(ASSizeRange)constrainedSize - restrictedToSize:(ASLayoutElementSize)layoutElementSize - relativeToParentSize:(CGSize)parentSize -{ - ASSizeRange styleAndParentSize = ASLayoutElementSizeResolve(layoutElementSize, parentSize); - const ASSizeRange rootConstrainedSize = ASSizeRangeIntersect(constrainedSize, styleAndParentSize); - - YGNodeRef rootYogaNode = YGNodeNew(); - - // YGNodeCalculateLayout currently doesn't offer the ability to pass a minimum size (max is passed there). - // Apply the constrainedSize.min directly to the root node so that layout accounts for it. - YGNodeStyleSetMinWidth (rootYogaNode, yogaFloatForCGFloat(rootConstrainedSize.min.width)); - YGNodeStyleSetMinHeight(rootYogaNode, yogaFloatForCGFloat(rootConstrainedSize.min.height)); - - // It's crucial to set these values. YGNodeCalculateLayout has unusual behavior for its width and height parameters: - // 1. If no maximum size set, infer this means YGMeasureModeExactly. Even if a small minWidth & minHeight are set, - // these will never be used because the output size of the root will always exactly match this value. - // 2. If a maximum size is set, infer that this means YGMeasureModeAtMost, and allow down to the min* values in output. - YGNodeStyleSetMaxWidthPercent(rootYogaNode, 100.0); - YGNodeStyleSetMaxHeightPercent(rootYogaNode, 100.0); - - [self setupYogaNode:rootYogaNode forElement:self.rootNode withParentYogaNode:NULL]; - for (id child in self.children) { - YGNodeRef yogaNode = YGNodeNew(); - [self setupYogaNode:yogaNode forElement:child withParentYogaNode:rootYogaNode]; - } - - // It is crucial to use yogaFloat... to convert CGFLOAT_MAX into YGUndefined here. - YGNodeCalculateLayout(rootYogaNode, - yogaFloatForCGFloat(rootConstrainedSize.max.width), - yogaFloatForCGFloat(rootConstrainedSize.max.height), - YGDirectionInherit); - - ASLayout *layout = [self layoutForYogaNode:rootYogaNode]; - -#if YOGA_LAYOUT_LOGGING - // Concurrent layouts will interleave the NSLog messages unless we serialize. - // Use @synchornize rather than trampolining to the main thread so the tree state isn't changed. - @synchronized ([ASDisplayNode class]) { - NSLog(@"****************************************************************************"); - NSLog(@"******************** STARTING YOGA -> ASLAYOUT CREATION ********************"); - NSLog(@"****************************************************************************"); - NSLog(@"node = %@", self.rootNode); - NSLog(@"style = %@", self.rootNode.style); - YGNodePrint(rootYogaNode, (YGPrintOptions)(YGPrintOptionsStyle | YGPrintOptionsLayout)); - } - NSLog(@"rootConstraint = (%@, %@), layout = %@, sublayouts = %@", NSStringFromCGSize(rootConstrainedSize.min), NSStringFromCGSize(rootConstrainedSize.max), layout, layout.sublayouts); -#endif - - while(YGNodeGetChildCount(rootYogaNode) > 0) { - YGNodeRef yogaNode = YGNodeGetChild(rootYogaNode, 0); - [self destroyYogaNode:yogaNode]; - } - [self destroyYogaNode:rootYogaNode]; - - return layout; -} - -@end - -#endif /* YOGA */ From 66d6506bac7be4fa116e629d68c08a5ccf4163b2 Mon Sep 17 00:00:00 2001 From: Adlai Holler Date: Fri, 29 Jun 2018 18:24:21 -0700 Subject: [PATCH 2/2] Changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 573aa36fa..e47a52ecc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ - Add an experiment to reduce work involved in collection teardown. [Adlai Holler](https://github.com/Adlai-Holler) - Optimize layout flattening, particularly reducing retain/release operations. [Adlai Holler](https://github.com/Adlai-Holler) - Create a method to transfer strong C-arrays into immutable NSArrays, reducing retain/release traffic. [Adlai Holler](https://github.com/Adlai-Holler) +- Remove yoga layout spec, which has been superseded by tighter Yoga integration (`ASDisplayNode+Yoga.h`) ## 2.7 - Fix pager node for interface coalescing. [Max Wang](https://github.com/wsdwsd0829) [#877](https://github.com/TextureGroup/Texture/pull/877)