Skip to content

Commit

Permalink
[Yoga] Important fix for simplified, non-contiguous Yoga integration.
Browse files Browse the repository at this point in the history
  • Loading branch information
appleguy committed May 26, 2017
1 parent 7a9d29e commit 0892c27
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
16 changes: 16 additions & 0 deletions AsyncDisplayKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@
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 */; };
90FC784F1E4BFE1B00383C5A /* ASDisplayNode+Yoga.mm in Sources */ = {isa = PBXBuildFile; fileRef = 90FC784E1E4BFE1B00383C5A /* ASDisplayNode+Yoga.mm */; };
92DD2FE61BF4D05E0074C9DD /* MapKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 92DD2FE51BF4D05E0074C9DD /* MapKit.framework */; settings = {ATTRIBUTES = (Weak, ); }; };
92DD2FE71BF4D0850074C9DD /* ASMapNode.mm in Sources */ = {isa = PBXBuildFile; fileRef = 92DD2FE21BF4B97E0074C9DD /* ASMapNode.mm */; };
Expand Down Expand Up @@ -676,6 +680,10 @@
8B0768B21CE752EC002E1453 /* ASDefaultPlaybackButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ASDefaultPlaybackButton.m; sourceTree = "<group>"; };
8BDA5FC31CDBDDE1007D13B2 /* ASVideoPlayerNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASVideoPlayerNode.h; sourceTree = "<group>"; };
8BDA5FC41CDBDDE1007D13B2 /* ASVideoPlayerNode.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ASVideoPlayerNode.mm; sourceTree = "<group>"; };
9019FBB91ED8061D00C45F72 /* ASYogaLayoutSpec.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASYogaLayoutSpec.h; sourceTree = "<group>"; };
9019FBBA1ED8061D00C45F72 /* ASYogaLayoutSpec.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ASYogaLayoutSpec.mm; sourceTree = "<group>"; };
9019FBBB1ED8061D00C45F72 /* ASYogaUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASYogaUtilities.h; sourceTree = "<group>"; };
9019FBBC1ED8061D00C45F72 /* ASYogaUtilities.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ASYogaUtilities.mm; sourceTree = "<group>"; };
90FC784E1E4BFE1B00383C5A /* ASDisplayNode+Yoga.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "ASDisplayNode+Yoga.mm"; sourceTree = "<group>"; };
92DD2FE11BF4B97E0074C9DD /* ASMapNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASMapNode.h; sourceTree = "<group>"; };
92DD2FE21BF4B97E0074C9DD /* ASMapNode.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ASMapNode.mm; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1481,6 +1489,10 @@
9C49C36E1B853957000B0DD5 /* ASStackLayoutElement.h */,
ACF6ED161B17843500DA7C62 /* ASStackLayoutSpec.h */,
ACF6ED171B17843500DA7C62 /* ASStackLayoutSpec.mm */,
9019FBB91ED8061D00C45F72 /* ASYogaLayoutSpec.h */,
9019FBBA1ED8061D00C45F72 /* ASYogaLayoutSpec.mm */,
9019FBBB1ED8061D00C45F72 /* ASYogaUtilities.h */,
9019FBBC1ED8061D00C45F72 /* ASYogaUtilities.mm */,
);
path = Layout;
sourceTree = "<group>";
Expand Down Expand Up @@ -1643,6 +1655,7 @@
B35062571B010F070018CF92 /* ASAssert.h in Headers */,
CCBBBF5D1EB161760069AA91 /* ASRangeManagingNode.h in Headers */,
B35062581B010F070018CF92 /* ASAvailability.h in Headers */,
9019FBBF1ED8061D00C45F72 /* ASYogaUtilities.h in Headers */,
DE84918D1C8FFF2B003D89E9 /* ASRunLoopQueue.h in Headers */,
CC0F88621E4281E200576FED /* ASSectionController.h in Headers */,
A2763D7A1CBDD57D00A9ADBD /* ASPINRemoteImageDownloader.h in Headers */,
Expand Down Expand Up @@ -1751,6 +1764,7 @@
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 */,
Expand Down Expand Up @@ -2086,6 +2100,7 @@
AC026B721BD57DBF00BBC17E /* _ASHierarchyChangeSet.mm in Sources */,
B35062421B010EFD0018CF92 /* _ASAsyncTransactionGroup.m in Sources */,
CCA282BD1E9EABDD0037E8B7 /* ASTipProvider.m in Sources */,
9019FBC01ED8061D00C45F72 /* ASYogaUtilities.mm in Sources */,
B350624A1B010EFD0018CF92 /* _ASCoreAnimationExtras.mm in Sources */,
68EE0DC01C1B4ED300BA1B99 /* ASMainSerialQueue.mm in Sources */,
B35062101B010EFD0018CF92 /* _ASDisplayLayer.mm in Sources */,
Expand Down Expand Up @@ -2167,6 +2182,7 @@
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 */,
Expand Down
2 changes: 1 addition & 1 deletion Source/ASDisplayNode+Yoga.mm
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ - (void)addYogaChild:(ASDisplayNode *)child
self.layoutSpecBlock = ^ASLayoutSpec * _Nonnull(__kindof ASDisplayNode * _Nonnull node, ASSizeRange constrainedSize) {
ASYogaLayoutSpec *spec = [[ASYogaLayoutSpec alloc] init];
spec.rootNode = weakSelf;
spec.yogaChildren = weakSelf.yogaChildren;
spec.children = weakSelf.yogaChildren;
return spec;
};
#endif
Expand Down
2 changes: 1 addition & 1 deletion Source/Base/ASAvailability.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
#endif

#ifndef YOGA_TREE_CONTIGUOUS
#define YOGA_TREE_CONTIGUOUS 0 // YOGA // Enabled by default when Yoga is used.
#define YOGA_TREE_CONTIGUOUS 0
#endif

#define AS_PIN_REMOTE_IMAGE __has_include(<PINRemoteImage/PINRemoteImage.h>)
Expand Down
9 changes: 9 additions & 0 deletions Source/Layout/ASYogaLayoutSpec.mm
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#import <AsyncDisplayKit/ASAvailability.h>

#if YOGA /* YOGA */
#if !YOGA_TREE_CONTIGUOUS /* !YOGA_TREE_CONTIGUOUS */

#import <AsyncDisplayKit/ASYogaLayoutSpec.h>
Expand Down Expand Up @@ -117,6 +118,13 @@ - (ASLayout *)calculateLayoutThatFits:(ASSizeRange)constrainedSize
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 <ASLayoutElement> child in self.children) {
YGNodeRef yogaNode = YGNodeNew();
Expand Down Expand Up @@ -151,3 +159,4 @@ - (ASLayout *)calculateLayoutThatFits:(ASSizeRange)constrainedSize
@end

#endif /* !YOGA_TREE_CONTIGUOUS */
#endif /* YOGA */

0 comments on commit 0892c27

Please sign in to comment.