Solve width bug when the size is less than min

Summary:
Removed the faulty calculation of `remainingFreeSpace` from the code. `remainingFreeSpace` already had the correct value that special condition was not required.

Also added a test case for this issue

Reviewed By: IanChilds

Differential Revision: D9286928

fbshipit-source-id: 915269602cda2cc4515e6eab8184b2ea98d3e6d4
This commit is contained in:
Pritesh Nandgaonkar
2018-08-15 14:21:55 -07:00
committed by Facebook Github Bot
parent 8368338c93
commit b872751d68
4 changed files with 190 additions and 23 deletions

View File

@@ -86,3 +86,18 @@
<div style="height: 10px;"></div>
</div>
<div id="justify_content_min_width_with_padding_child_width_greater_than_parent" style="width: 1000px; height: 1584px;">
<div style="flex-direction: row; align-content: stretch;">
<div style="flex-direction: row; justify-content: center; align-content: stretch; min-width: 400px; padding-left: 100px; padding-right: 100px;">
<div style="height: 100px; width: 300px; align-content: stretch; flex-direction: row;"></div>
</div>
</div>
</div>
<div id="justify_content_min_width_with_padding_child_width_greater_than_parent" style="width: 1080px; height: 1584px;">
<div style="flex-direction: row; align-content: stretch;">
<div style="flex-direction: row; justify-content: center; align-content: stretch; min-width: 400px; padding-left: 100px; padding-right: 100px;">
<div style="height: 100px; width: 199px; align-content: stretch; flex-direction: row;"></div>
</div>
</div>
</div>

View File

@@ -1,11 +1,12 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
/*
* Copyright (c) 2014-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
// @Generated by gentest/gentest.rb from gentest/fixtures/YGJustifyContentTest.html
// @Generated by gentest/gentest.rb from
// gentest/fixtures/YGJustifyContentTest.html
#include <gtest/gtest.h>
#include <yoga/Yoga.h>
@@ -735,6 +736,164 @@ TEST(YogaTest, justify_content_row_min_width_and_margin) {
YGConfigFree(config);
}
TEST(
YogaTest,
justify_content_min_width_with_padding_child_width_greater_than_parent) {
const YGConfigRef config = YGConfigNew();
const YGNodeRef root = YGNodeNewWithConfig(config);
YGNodeStyleSetAlignContent(root, YGAlignStretch);
YGNodeStyleSetWidth(root, 1000);
YGNodeStyleSetHeight(root, 1584);
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
YGNodeStyleSetFlexDirection(root_child0, YGFlexDirectionRow);
YGNodeStyleSetAlignContent(root_child0, YGAlignStretch);
YGNodeInsertChild(root, root_child0, 0);
const YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config);
YGNodeStyleSetFlexDirection(root_child0_child0, YGFlexDirectionRow);
YGNodeStyleSetJustifyContent(root_child0_child0, YGJustifyCenter);
YGNodeStyleSetAlignContent(root_child0_child0, YGAlignStretch);
YGNodeStyleSetMinWidth(root_child0_child0, 400);
YGNodeStyleSetPadding(root_child0_child0, YGEdgeHorizontal, 100);
YGNodeInsertChild(root_child0, root_child0_child0, 0);
const YGNodeRef root_child0_child0_child0 = YGNodeNewWithConfig(config);
YGNodeStyleSetFlexDirection(root_child0_child0_child0, YGFlexDirectionRow);
YGNodeStyleSetAlignContent(root_child0_child0_child0, YGAlignStretch);
YGNodeStyleSetWidth(root_child0_child0_child0, 300);
YGNodeStyleSetHeight(root_child0_child0_child0, 100);
YGNodeInsertChild(root_child0_child0, root_child0_child0_child0, 0);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
ASSERT_FLOAT_EQ(1000, YGNodeLayoutGetWidth(root));
ASSERT_FLOAT_EQ(1584, YGNodeLayoutGetHeight(root));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
ASSERT_FLOAT_EQ(1000, YGNodeLayoutGetWidth(root_child0));
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0));
ASSERT_FLOAT_EQ(500, YGNodeLayoutGetWidth(root_child0_child0));
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0_child0));
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child0_child0_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0_child0));
ASSERT_FLOAT_EQ(300, YGNodeLayoutGetWidth(root_child0_child0_child0));
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0_child0_child0));
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
ASSERT_FLOAT_EQ(1000, YGNodeLayoutGetWidth(root));
ASSERT_FLOAT_EQ(1584, YGNodeLayoutGetHeight(root));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
ASSERT_FLOAT_EQ(1000, YGNodeLayoutGetWidth(root_child0));
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0));
ASSERT_FLOAT_EQ(500, YGNodeLayoutGetLeft(root_child0_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0));
ASSERT_FLOAT_EQ(500, YGNodeLayoutGetWidth(root_child0_child0));
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0_child0));
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child0_child0_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0_child0));
ASSERT_FLOAT_EQ(300, YGNodeLayoutGetWidth(root_child0_child0_child0));
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0_child0_child0));
YGNodeFreeRecursive(root);
YGConfigFree(config);
}
TEST(
YogaTest,
justify_content_min_width_with_padding_child_width_lower_than_parent) {
const YGConfigRef config = YGConfigNew();
const YGNodeRef root = YGNodeNewWithConfig(config);
YGNodeStyleSetAlignContent(root, YGAlignStretch);
YGNodeStyleSetWidth(root, 1080);
YGNodeStyleSetHeight(root, 1584);
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
YGNodeStyleSetFlexDirection(root_child0, YGFlexDirectionRow);
YGNodeStyleSetAlignContent(root_child0, YGAlignStretch);
YGNodeInsertChild(root, root_child0, 0);
const YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config);
YGNodeStyleSetFlexDirection(root_child0_child0, YGFlexDirectionRow);
YGNodeStyleSetJustifyContent(root_child0_child0, YGJustifyCenter);
YGNodeStyleSetAlignContent(root_child0_child0, YGAlignStretch);
YGNodeStyleSetMinWidth(root_child0_child0, 400);
YGNodeStyleSetPadding(root_child0_child0, YGEdgeHorizontal, 100);
YGNodeInsertChild(root_child0, root_child0_child0, 0);
const YGNodeRef root_child0_child0_child0 = YGNodeNewWithConfig(config);
YGNodeStyleSetFlexDirection(root_child0_child0_child0, YGFlexDirectionRow);
YGNodeStyleSetAlignContent(root_child0_child0_child0, YGAlignStretch);
YGNodeStyleSetWidth(root_child0_child0_child0, 199);
YGNodeStyleSetHeight(root_child0_child0_child0, 100);
YGNodeInsertChild(root_child0_child0, root_child0_child0_child0, 0);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
ASSERT_FLOAT_EQ(1080, YGNodeLayoutGetWidth(root));
ASSERT_FLOAT_EQ(1584, YGNodeLayoutGetHeight(root));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
ASSERT_FLOAT_EQ(1080, YGNodeLayoutGetWidth(root_child0));
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0));
ASSERT_FLOAT_EQ(400, YGNodeLayoutGetWidth(root_child0_child0));
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0_child0));
ASSERT_FLOAT_EQ(101, YGNodeLayoutGetLeft(root_child0_child0_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0_child0));
ASSERT_FLOAT_EQ(199, YGNodeLayoutGetWidth(root_child0_child0_child0));
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0_child0_child0));
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
ASSERT_FLOAT_EQ(1080, YGNodeLayoutGetWidth(root));
ASSERT_FLOAT_EQ(1584, YGNodeLayoutGetHeight(root));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
ASSERT_FLOAT_EQ(1080, YGNodeLayoutGetWidth(root_child0));
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0));
ASSERT_FLOAT_EQ(680, YGNodeLayoutGetLeft(root_child0_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0));
ASSERT_FLOAT_EQ(400, YGNodeLayoutGetWidth(root_child0_child0));
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0_child0));
ASSERT_FLOAT_EQ(101, YGNodeLayoutGetLeft(root_child0_child0_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0_child0));
ASSERT_FLOAT_EQ(199, YGNodeLayoutGetWidth(root_child0_child0_child0));
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0_child0_child0));
//
YGNodeFreeRecursive(root);
YGConfigFree(config);
}
TEST(YogaTest, justify_content_row_max_width_and_margin) {
const YGConfigRef config = YGConfigNew();

View File

@@ -1,10 +1,10 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
/*
* Copyright (c) 2014-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
// @Generated by gentest/gentest.rb from gentest/fixtures/YGPaddingTest.html
#include <gtest/gtest.h>

View File

@@ -2396,20 +2396,13 @@ static void YGJustifyMainAxis(
const bool& performLayout) {
const YGStyle& style = node->getStyle();
// If we are using "at most" rules in the main axis. Calculate the remaining
// space when constraint by the min size defined for the main axis.
// If we are using "at most" rules in the main axis, make sure that
// remainingFreeSpace is 0 when min main dimension is not given
if (measureModeMainDim == YGMeasureModeAtMost &&
collectedFlexItemsValues.remainingFreeSpace > 0) {
if (style.minDimensions[dim[mainAxis]].unit != YGUnitUndefined &&
!YGResolveValue(style.minDimensions[dim[mainAxis]], mainAxisownerSize)
.isUndefined()) {
collectedFlexItemsValues.remainingFreeSpace = YGFloatMax(
0,
YGUnwrapFloatOptional(YGResolveValue(
style.minDimensions[dim[mainAxis]], mainAxisownerSize)) -
(availableInnerMainDim -
collectedFlexItemsValues.remainingFreeSpace));
} else {
if (style.minDimensions[dim[mainAxis]].unit == YGUnitUndefined ||
YGResolveValue(style.minDimensions[dim[mainAxis]], mainAxisownerSize)
.isUndefined()) {
collectedFlexItemsValues.remainingFreeSpace = 0;
}
}