From 702564fb602cb7d7831a2bf0a359d22863eeec56 Mon Sep 17 00:00:00 2001 From: Emil Sjolander Date: Tue, 28 Feb 2017 08:10:34 -0800 Subject: [PATCH] Pass the parent size to YGNodeCalculateLayout instead of the node size Reviewed By: astreet Differential Revision: D4611417 fbshipit-source-id: 2fb0eedffa17f0ec89b601722a1717a72e216b9e --- React/Views/RCTRootShadowView.m | 10 ++++++++ React/Views/RCTShadowView.m | 3 +++ ReactCommon/yoga/yoga/Yoga.c | 43 +++++++++++++++------------------ 3 files changed, 32 insertions(+), 24 deletions(-) diff --git a/React/Views/RCTRootShadowView.m b/React/Views/RCTRootShadowView.m index 2a134a7fe..1d925a4fc 100644 --- a/React/Views/RCTRootShadowView.m +++ b/React/Views/RCTRootShadowView.m @@ -33,6 +33,16 @@ float availableWidth = _availableSize.width == INFINITY ? YGUndefined : _availableSize.width; float availableHeight = _availableSize.height == INFINITY ? YGUndefined : _availableSize.height; + YGUnit widthUnit = YGNodeStyleGetWidth(self.yogaNode).unit; + if (widthUnit == YGUnitUndefined || widthUnit == YGUnitAuto) { + YGNodeStyleSetWidthPercent(self.yogaNode, 100); + } + + YGUnit heightUnit = YGNodeStyleGetHeight(self.yogaNode).unit; + if (heightUnit == YGUnitUndefined || heightUnit == YGUnitAuto) { + YGNodeStyleSetHeightPercent(self.yogaNode, 100); + } + YGNodeCalculateLayout(self.yogaNode, availableWidth, availableHeight, _baseDirection); NSMutableSet *viewsWithNewFrame = [NSMutableSet set]; diff --git a/React/Views/RCTShadowView.m b/React/Views/RCTShadowView.m index 972459cf6..8a82794ed 100644 --- a/React/Views/RCTShadowView.m +++ b/React/Views/RCTShadowView.m @@ -242,6 +242,9 @@ static void RCTProcessMetaPropsBorder(const YGValue metaProps[META_PROP_COUNT], hidden:(BOOL)hidden absolutePosition:(CGPoint)absolutePosition { + // This is not the core layout method. It is only used by RCTShadowText to layout + // nested views. + if (_hidden != hidden) { // The hidden state has changed. Even if the frame hasn't changed, add // this ShadowView to viewsWithNewFrame so the UIManager will process diff --git a/ReactCommon/yoga/yoga/Yoga.c b/ReactCommon/yoga/yoga/Yoga.c index a67b33d07..9546f338d 100644 --- a/ReactCommon/yoga/yoga/Yoga.c +++ b/ReactCommon/yoga/yoga/Yoga.c @@ -3280,8 +3280,8 @@ static void YGRoundToPixelGrid(const YGNodeRef node) { } void YGNodeCalculateLayout(const YGNodeRef node, - const float availableWidth, - const float availableHeight, + const float parentWidth, + const float parentHeight, const YGDirection parentDirection) { // Increment the generation count. This will force the recursive routine to // visit @@ -3290,33 +3290,28 @@ void YGNodeCalculateLayout(const YGNodeRef node, // parameters don't change. gCurrentGenerationCount++; - float width = availableWidth; - float height = availableHeight; - YGMeasureMode widthMeasureMode = YGMeasureModeUndefined; - YGMeasureMode heightMeasureMode = YGMeasureModeUndefined; - YGResolveDimensions(node); - if (!YGFloatIsUndefined(width)) { + float width = YGUndefined; + YGMeasureMode widthMeasureMode = YGMeasureModeUndefined; + if (YGNodeIsStyleDimDefined(node, YGFlexDirectionRow, parentWidth)) { + width = YGValueResolve(node->resolvedDimensions[dim[YGFlexDirectionRow]], parentWidth) + + YGNodeMarginForAxis(node, YGFlexDirectionRow, parentWidth); widthMeasureMode = YGMeasureModeExactly; - } else if (YGNodeIsStyleDimDefined(node, YGFlexDirectionRow, availableWidth)) { - width = YGValueResolve(node->resolvedDimensions[dim[YGFlexDirectionRow]], availableWidth) + - YGNodeMarginForAxis(node, YGFlexDirectionRow, availableWidth); - widthMeasureMode = YGMeasureModeExactly; - } else if (YGValueResolve(&node->style.maxDimensions[YGDimensionWidth], availableWidth) >= 0.0f) { - width = YGValueResolve(&node->style.maxDimensions[YGDimensionWidth], availableWidth); + } else if (YGValueResolve(&node->style.maxDimensions[YGDimensionWidth], parentWidth) >= 0.0f) { + width = YGValueResolve(&node->style.maxDimensions[YGDimensionWidth], parentWidth); widthMeasureMode = YGMeasureModeAtMost; } - if (!YGFloatIsUndefined(height)) { + float height = YGUndefined; + YGMeasureMode heightMeasureMode = YGMeasureModeUndefined; + if (YGNodeIsStyleDimDefined(node, YGFlexDirectionColumn, parentHeight)) { + height = YGValueResolve(node->resolvedDimensions[dim[YGFlexDirectionColumn]], parentHeight) + + YGNodeMarginForAxis(node, YGFlexDirectionColumn, parentWidth); heightMeasureMode = YGMeasureModeExactly; - } else if (YGNodeIsStyleDimDefined(node, YGFlexDirectionColumn, availableHeight)) { - height = YGValueResolve(node->resolvedDimensions[dim[YGFlexDirectionColumn]], availableHeight) + - YGNodeMarginForAxis(node, YGFlexDirectionColumn, availableWidth); - heightMeasureMode = YGMeasureModeExactly; - } else if (YGValueResolve(&node->style.maxDimensions[YGDimensionHeight], availableHeight) >= + } else if (YGValueResolve(&node->style.maxDimensions[YGDimensionHeight], parentHeight) >= 0.0f) { - height = YGValueResolve(&node->style.maxDimensions[YGDimensionHeight], availableHeight); + height = YGValueResolve(&node->style.maxDimensions[YGDimensionHeight], parentHeight); heightMeasureMode = YGMeasureModeAtMost; } @@ -3326,12 +3321,12 @@ void YGNodeCalculateLayout(const YGNodeRef node, parentDirection, widthMeasureMode, heightMeasureMode, - availableWidth, - availableHeight, + parentWidth, + parentHeight, true, "initia" "l")) { - YGNodeSetPosition(node, node->layout.direction, availableWidth, availableHeight, availableWidth); + YGNodeSetPosition(node, node->layout.direction, node->layout.dimensions[YGDimensionWidth], node->layout.dimensions[YGDimensionHeight], parentWidth); if (YGIsExperimentalFeatureEnabled(YGExperimentalFeatureRounding)) { YGRoundToPixelGrid(node);