Fix behaviour of wrapping container within align-items: not stretch

Summary: When a container's children wrap the container should match the parent size and not wrap to the new size of the children. This is confirmed behavior in chrome.

Reviewed By: astreet

Differential Revision: D4578614

fbshipit-source-id: 5d22a3a673735587384d775189158a87bb1d457d
This commit is contained in:
Emil Sjolander
2017-02-20 07:16:58 -08:00
committed by Facebook Github Bot
parent 78ade6cfb5
commit 6b39165801
6 changed files with 850 additions and 6 deletions

View File

@@ -1128,4 +1128,208 @@ public class YGFlexWrapTest {
assertEquals(50f, root_child4.getLayoutHeight(), 0.0f);
}
@Test
public void test_wrapped_row_within_align_items_center() {
final YogaNode root = new YogaNode();
root.setAlignItems(YogaAlign.CENTER);
root.setWidth(200f);
root.setHeight(200f);
final YogaNode root_child0 = new YogaNode();
root_child0.setFlexDirection(YogaFlexDirection.ROW);
root_child0.setWrap(YogaWrap.WRAP);
root.addChildAt(root_child0, 0);
final YogaNode root_child0_child0 = new YogaNode();
root_child0_child0.setWidth(150f);
root_child0_child0.setHeight(80f);
root_child0.addChildAt(root_child0_child0, 0);
final YogaNode root_child0_child1 = new YogaNode();
root_child0_child1.setWidth(80f);
root_child0_child1.setHeight(80f);
root_child0.addChildAt(root_child0_child1, 1);
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(200f, 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(160f, root_child0.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f);
assertEquals(150f, root_child0_child0.getLayoutWidth(), 0.0f);
assertEquals(80f, root_child0_child0.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0_child1.getLayoutX(), 0.0f);
assertEquals(80f, root_child0_child1.getLayoutY(), 0.0f);
assertEquals(80f, root_child0_child1.getLayoutWidth(), 0.0f);
assertEquals(80f, root_child0_child1.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(200f, 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(160f, root_child0.getLayoutHeight(), 0.0f);
assertEquals(50f, root_child0_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f);
assertEquals(150f, root_child0_child0.getLayoutWidth(), 0.0f);
assertEquals(80f, root_child0_child0.getLayoutHeight(), 0.0f);
assertEquals(120f, root_child0_child1.getLayoutX(), 0.0f);
assertEquals(80f, root_child0_child1.getLayoutY(), 0.0f);
assertEquals(80f, root_child0_child1.getLayoutWidth(), 0.0f);
assertEquals(80f, root_child0_child1.getLayoutHeight(), 0.0f);
}
@Test
public void test_wrapped_row_within_align_items_center2() {
final YogaNode root = new YogaNode();
root.setAlignItems(YogaAlign.FLEX_START);
root.setWidth(200f);
root.setHeight(200f);
final YogaNode root_child0 = new YogaNode();
root_child0.setFlexDirection(YogaFlexDirection.ROW);
root_child0.setWrap(YogaWrap.WRAP);
root.addChildAt(root_child0, 0);
final YogaNode root_child0_child0 = new YogaNode();
root_child0_child0.setWidth(150f);
root_child0_child0.setHeight(80f);
root_child0.addChildAt(root_child0_child0, 0);
final YogaNode root_child0_child1 = new YogaNode();
root_child0_child1.setWidth(80f);
root_child0_child1.setHeight(80f);
root_child0.addChildAt(root_child0_child1, 1);
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(200f, 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(160f, root_child0.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f);
assertEquals(150f, root_child0_child0.getLayoutWidth(), 0.0f);
assertEquals(80f, root_child0_child0.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0_child1.getLayoutX(), 0.0f);
assertEquals(80f, root_child0_child1.getLayoutY(), 0.0f);
assertEquals(80f, root_child0_child1.getLayoutWidth(), 0.0f);
assertEquals(80f, root_child0_child1.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(200f, 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(160f, root_child0.getLayoutHeight(), 0.0f);
assertEquals(50f, root_child0_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f);
assertEquals(150f, root_child0_child0.getLayoutWidth(), 0.0f);
assertEquals(80f, root_child0_child0.getLayoutHeight(), 0.0f);
assertEquals(120f, root_child0_child1.getLayoutX(), 0.0f);
assertEquals(80f, root_child0_child1.getLayoutY(), 0.0f);
assertEquals(80f, root_child0_child1.getLayoutWidth(), 0.0f);
assertEquals(80f, root_child0_child1.getLayoutHeight(), 0.0f);
}
@Test
public void test_wrapped_row_within_align_items_center3() {
final YogaNode root = new YogaNode();
root.setAlignItems(YogaAlign.FLEX_END);
root.setWidth(200f);
root.setHeight(200f);
final YogaNode root_child0 = new YogaNode();
root_child0.setFlexDirection(YogaFlexDirection.ROW);
root_child0.setWrap(YogaWrap.WRAP);
root.addChildAt(root_child0, 0);
final YogaNode root_child0_child0 = new YogaNode();
root_child0_child0.setWidth(150f);
root_child0_child0.setHeight(80f);
root_child0.addChildAt(root_child0_child0, 0);
final YogaNode root_child0_child1 = new YogaNode();
root_child0_child1.setWidth(80f);
root_child0_child1.setHeight(80f);
root_child0.addChildAt(root_child0_child1, 1);
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(200f, 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(160f, root_child0.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f);
assertEquals(150f, root_child0_child0.getLayoutWidth(), 0.0f);
assertEquals(80f, root_child0_child0.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0_child1.getLayoutX(), 0.0f);
assertEquals(80f, root_child0_child1.getLayoutY(), 0.0f);
assertEquals(80f, root_child0_child1.getLayoutWidth(), 0.0f);
assertEquals(80f, root_child0_child1.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(200f, 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(160f, root_child0.getLayoutHeight(), 0.0f);
assertEquals(50f, root_child0_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f);
assertEquals(150f, root_child0_child0.getLayoutWidth(), 0.0f);
assertEquals(80f, root_child0_child0.getLayoutHeight(), 0.0f);
assertEquals(120f, root_child0_child1.getLayoutX(), 0.0f);
assertEquals(80f, root_child0_child1.getLayoutY(), 0.0f);
assertEquals(80f, root_child0_child1.getLayoutWidth(), 0.0f);
assertEquals(80f, root_child0_child1.getLayoutHeight(), 0.0f);
}
}