Skip to content

Commit

Permalink
default root node to size of parent contraints
Browse files Browse the repository at this point in the history
Reviewed By: dshahidehpour

Differential Revision: D4634616

fbshipit-source-id: 089eb4313c5bb810a6ff56f158cd19cec71808ec
  • Loading branch information
Emil Sjolander authored and facebook-github-bot committed Mar 1, 2017
1 parent 6b738d1 commit 23f2f5f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
10 changes: 0 additions & 10 deletions React/Views/RCTRootShadowView.m
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -33,16 +33,6 @@ - (instancetype)init
float availableWidth = _availableSize.width == INFINITY ? YGUndefined : _availableSize.width; float availableWidth = _availableSize.width == INFINITY ? YGUndefined : _availableSize.width;
float availableHeight = _availableSize.height == INFINITY ? YGUndefined : _availableSize.height; 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); YGNodeCalculateLayout(self.yogaNode, availableWidth, availableHeight, _baseDirection);


NSMutableSet<RCTShadowView *> *viewsWithNewFrame = [NSMutableSet set]; NSMutableSet<RCTShadowView *> *viewsWithNewFrame = [NSMutableSet set];
Expand Down
12 changes: 9 additions & 3 deletions ReactCommon/yoga/yoga/Yoga.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3251,7 +3251,7 @@ static void YGRoundToPixelGrid(const YGNodeRef node) {
float fractialTop = fmodf(nodeTop, gPointScaleFactor); float fractialTop = fmodf(nodeTop, gPointScaleFactor);
float roundedLeft = nodeLeft - fractialLeft; float roundedLeft = nodeLeft - fractialLeft;
float roundedTop = nodeTop - fractialTop; float roundedTop = nodeTop - fractialTop;

// To do the actual rounding we check if leftover fraction is bigger or equal than half of the grid step // To do the actual rounding we check if leftover fraction is bigger or equal than half of the grid step
if (fractialLeft >= gPointScaleFactor / 2.0) { if (fractialLeft >= gPointScaleFactor / 2.0) {
roundedLeft += gPointScaleFactor; roundedLeft += gPointScaleFactor;
Expand All @@ -3263,13 +3263,13 @@ static void YGRoundToPixelGrid(const YGNodeRef node) {
} }
node->layout.position[YGEdgeLeft] = roundedLeft; node->layout.position[YGEdgeLeft] = roundedLeft;
node->layout.position[YGEdgeTop] = roundedTop; node->layout.position[YGEdgeTop] = roundedTop;

// Now we round width and height in the same way accounting for fractial leftovers from rounding position // Now we round width and height in the same way accounting for fractial leftovers from rounding position
const float adjustedWidth = fractialLeft + node->layout.dimensions[YGDimensionWidth]; const float adjustedWidth = fractialLeft + node->layout.dimensions[YGDimensionWidth];
const float adjustedHeight = fractialTop + node->layout.dimensions[YGDimensionHeight]; const float adjustedHeight = fractialTop + node->layout.dimensions[YGDimensionHeight];
float roundedWidth = adjustedWidth - fmodf(adjustedWidth, gPointScaleFactor); float roundedWidth = adjustedWidth - fmodf(adjustedWidth, gPointScaleFactor);
float roundedHeight = adjustedHeight - fmodf(adjustedHeight, gPointScaleFactor); float roundedHeight = adjustedHeight - fmodf(adjustedHeight, gPointScaleFactor);

if (adjustedWidth - roundedWidth >= gPointScaleFactor / 2.0) { if (adjustedWidth - roundedWidth >= gPointScaleFactor / 2.0) {
roundedWidth += gPointScaleFactor; roundedWidth += gPointScaleFactor;
} }
Expand Down Expand Up @@ -3307,6 +3307,9 @@ void YGNodeCalculateLayout(const YGNodeRef node,
} else if (YGValueResolve(&node->style.maxDimensions[YGDimensionWidth], parentWidth) >= 0.0f) { } else if (YGValueResolve(&node->style.maxDimensions[YGDimensionWidth], parentWidth) >= 0.0f) {
width = YGValueResolve(&node->style.maxDimensions[YGDimensionWidth], parentWidth); width = YGValueResolve(&node->style.maxDimensions[YGDimensionWidth], parentWidth);
widthMeasureMode = YGMeasureModeAtMost; widthMeasureMode = YGMeasureModeAtMost;
} else {
width = parentWidth;
widthMeasureMode = YGFloatIsUndefined(width) ? YGMeasureModeUndefined : YGMeasureModeExactly;
} }


float height = YGUndefined; float height = YGUndefined;
Expand All @@ -3319,6 +3322,9 @@ void YGNodeCalculateLayout(const YGNodeRef node,
0.0f) { 0.0f) {
height = YGValueResolve(&node->style.maxDimensions[YGDimensionHeight], parentHeight); height = YGValueResolve(&node->style.maxDimensions[YGDimensionHeight], parentHeight);
heightMeasureMode = YGMeasureModeAtMost; heightMeasureMode = YGMeasureModeAtMost;
} else {
height = parentHeight;
heightMeasureMode = YGFloatIsUndefined(height) ? YGMeasureModeUndefined : YGMeasureModeExactly;
} }


if (YGLayoutNodeInternal(node, if (YGLayoutNodeInternal(node,
Expand Down

0 comments on commit 23f2f5f

Please sign in to comment.