Permalink
Browse files

Pass the parent size to YGNodeCalculateLayout instead of the node size

Reviewed By: astreet

Differential Revision: D4611417

fbshipit-source-id: 2fb0eedffa17f0ec89b601722a1717a72e216b9e
  • Loading branch information...
emilsjolander authored and facebook-github-bot committed Feb 28, 2017
1 parent f52d66c commit 702564fb602cb7d7831a2bf0a359d22863eeec56
Showing with 32 additions and 24 deletions.
  1. +10 −0 React/Views/RCTRootShadowView.m
  2. +3 −0 React/Views/RCTShadowView.m
  3. +19 −24 ReactCommon/yoga/yoga/Yoga.c
@@ -33,6 +33,16 @@ - (instancetype)init
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<RCTShadowView *> *viewsWithNewFrame = [NSMutableSet set];
@@ -242,6 +242,9 @@ - (void)collectUpdatedFrames:(NSMutableSet<RCTShadowView *> *)viewsWithNewFrame
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
@@ -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)) {
widthMeasureMode = YGMeasureModeExactly;
} else if (YGNodeIsStyleDimDefined(node, YGFlexDirectionRow, availableWidth)) {
width = YGValueResolve(node->resolvedDimensions[dim[YGFlexDirectionRow]], availableWidth) +
YGNodeMarginForAxis(node, YGFlexDirectionRow, availableWidth);
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 (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)) {
heightMeasureMode = YGMeasureModeExactly;
} else if (YGNodeIsStyleDimDefined(node, YGFlexDirectionColumn, availableHeight)) {
height = YGValueResolve(node->resolvedDimensions[dim[YGFlexDirectionColumn]], availableHeight) +
YGNodeMarginForAxis(node, YGFlexDirectionColumn, availableWidth);
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 (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);

0 comments on commit 702564f

Please sign in to comment.