The total flex factores need to be a minimum of 1 if any

Summary:
The only thing I found in the spec for this change is the following. Not exactly sure if this is the thing this PR is about:

> For each flex item, subtract its outer flex base size from its max-content contribution size. If that result is not zero, divide it by (if the result was positive) its **flex grow factor floored at 1** or (if the result was negative) by its scaled flex shrink factor, having **floored the flex shrink factor at 1**. This is the item’s max-content flex fraction.

But at least it seems a required change.

Fixes facebook/yoga#566
Closes https://github.com/facebook/yoga/pull/572

Differential Revision: D5264388

Pulled By: emilsjolander

fbshipit-source-id: 0004d1c3b9bad070a98cd6766c1adc06a54475f8
This commit is contained in:
Lukas Wöhrl
2017-06-16 07:31:19 -07:00
committed by Facebook Github Bot
parent 6c67684fa6
commit ca2c607f90
6 changed files with 290 additions and 0 deletions

View File

@@ -421,4 +421,71 @@ public class YGFlexTest {
assertEquals(0f, root_child0_child0.getLayoutHeight(), 0.0f);
}
@Test
public void test_flex_grow_less_than_factor_one() {
YogaConfig config = new YogaConfig();
final YogaNode root = new YogaNode(config);
root.setWidth(200f);
root.setHeight(500f);
final YogaNode root_child0 = new YogaNode(config);
root_child0.setFlexGrow(0.2f);
root_child0.setFlexBasis(40f);
root.addChildAt(root_child0, 0);
final YogaNode root_child1 = new YogaNode(config);
root_child1.setFlexGrow(0.2f);
root.addChildAt(root_child1, 1);
final YogaNode root_child2 = new YogaNode(config);
root_child2.setFlexGrow(0.4f);
root.addChildAt(root_child2, 2);
root.setDirection(YogaDirection.LTR);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(200f, root.getLayoutWidth(), 0.0f);
assertEquals(500f, root.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(200f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(132f, root_child0.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child1.getLayoutX(), 0.0f);
assertEquals(132f, root_child1.getLayoutY(), 0.0f);
assertEquals(200f, root_child1.getLayoutWidth(), 0.0f);
assertEquals(92f, root_child1.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child2.getLayoutX(), 0.0f);
assertEquals(224f, root_child2.getLayoutY(), 0.0f);
assertEquals(200f, root_child2.getLayoutWidth(), 0.0f);
assertEquals(184f, root_child2.getLayoutHeight(), 0.0f);
root.setDirection(YogaDirection.RTL);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(200f, root.getLayoutWidth(), 0.0f);
assertEquals(500f, root.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(200f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(132f, root_child0.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child1.getLayoutX(), 0.0f);
assertEquals(132f, root_child1.getLayoutY(), 0.0f);
assertEquals(200f, root_child1.getLayoutWidth(), 0.0f);
assertEquals(92f, root_child1.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child2.getLayoutX(), 0.0f);
assertEquals(224f, root_child2.getLayoutY(), 0.0f);
assertEquals(200f, root_child2.getLayoutWidth(), 0.0f);
assertEquals(184f, root_child2.getLayoutHeight(), 0.0f);
}
}