Include margin when calculating if children overflow

Summary: Include margin when calculating if children overflow

Reviewed By: passy

Differential Revision: D5044471

fbshipit-source-id: e7c1eb694445ffb898bcf375d9deefc558c49f11
This commit is contained in:
Emil Sjolander
2017-05-12 09:03:23 -07:00
committed by Facebook Github Bot
parent 85c2e406e4
commit 488a7c1fe0
6 changed files with 413 additions and 5 deletions

View File

@@ -1526,4 +1526,101 @@ public class YGFlexWrapTest {
assertEquals(100f, root_child2.getLayoutHeight(), 0.0f);
}
@Test
public void test_wrap_nodes_with_content_sizing_overflowing_margin() {
YogaConfig config = new YogaConfig();
final YogaNode root = new YogaNode(config);
root.setWidth(500f);
root.setHeight(500f);
final YogaNode root_child0 = new YogaNode(config);
root_child0.setFlexDirection(YogaFlexDirection.ROW);
root_child0.setWrap(YogaWrap.WRAP);
root_child0.setWidth(85f);
root.addChildAt(root_child0, 0);
final YogaNode root_child0_child0 = new YogaNode(config);
root_child0.addChildAt(root_child0_child0, 0);
final YogaNode root_child0_child0_child0 = new YogaNode(config);
root_child0_child0_child0.setWidth(40f);
root_child0_child0_child0.setHeight(40f);
root_child0_child0.addChildAt(root_child0_child0_child0, 0);
final YogaNode root_child0_child1 = new YogaNode(config);
root_child0_child1.setMargin(YogaEdge.RIGHT, 10f);
root_child0.addChildAt(root_child0_child1, 1);
final YogaNode root_child0_child1_child0 = new YogaNode(config);
root_child0_child1_child0.setWidth(40f);
root_child0_child1_child0.setHeight(40f);
root_child0_child1.addChildAt(root_child0_child1_child0, 0);
root.setDirection(YogaDirection.LTR);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(500f, 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(85f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(80f, root_child0.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f);
assertEquals(40f, root_child0_child0.getLayoutWidth(), 0.0f);
assertEquals(40f, root_child0_child0.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0_child0_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0_child0_child0.getLayoutY(), 0.0f);
assertEquals(40f, root_child0_child0_child0.getLayoutWidth(), 0.0f);
assertEquals(40f, root_child0_child0_child0.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0_child1.getLayoutX(), 0.0f);
assertEquals(40f, root_child0_child1.getLayoutY(), 0.0f);
assertEquals(40f, root_child0_child1.getLayoutWidth(), 0.0f);
assertEquals(40f, root_child0_child1.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0_child1_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0_child1_child0.getLayoutY(), 0.0f);
assertEquals(40f, root_child0_child1_child0.getLayoutWidth(), 0.0f);
assertEquals(40f, root_child0_child1_child0.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(500f, root.getLayoutWidth(), 0.0f);
assertEquals(500f, root.getLayoutHeight(), 0.0f);
assertEquals(415f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(85f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(80f, root_child0.getLayoutHeight(), 0.0f);
assertEquals(45f, root_child0_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f);
assertEquals(40f, root_child0_child0.getLayoutWidth(), 0.0f);
assertEquals(40f, root_child0_child0.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0_child0_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0_child0_child0.getLayoutY(), 0.0f);
assertEquals(40f, root_child0_child0_child0.getLayoutWidth(), 0.0f);
assertEquals(40f, root_child0_child0_child0.getLayoutHeight(), 0.0f);
assertEquals(35f, root_child0_child1.getLayoutX(), 0.0f);
assertEquals(40f, root_child0_child1.getLayoutY(), 0.0f);
assertEquals(40f, root_child0_child1.getLayoutWidth(), 0.0f);
assertEquals(40f, root_child0_child1.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0_child1_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0_child1_child0.getLayoutY(), 0.0f);
assertEquals(40f, root_child0_child1_child0.getLayoutWidth(), 0.0f);
assertEquals(40f, root_child0_child1_child0.getLayoutHeight(), 0.0f);
}
}