Move configuration to new YGConfig and pass them down to CalculateLayout
Summary: Move configuration to new ```YGConfig``` and pass them down to CalculateLayout. See #418 . Adds ```YGConfigNew()``` + ```YGConfigFree```, and changed ```YGSetExperimentalFeatureEnabled``` to use the config. New function for calculation is ```YGNodeCalculateLayoutWithConfig```. Closes https://github.com/facebook/yoga/pull/432 Reviewed By: astreet Differential Revision: D4611359 Pulled By: emilsjolander fbshipit-source-id: a1332f0e1b21cec02129dd021ee57408449e10b0
This commit is contained in:
committed by
Facebook Github Bot
parent
8668e43f6d
commit
37c48257ae
@@ -18,22 +18,23 @@ import static org.junit.Assert.assertEquals;
|
||||
public class YGRoundingTest {
|
||||
@Test
|
||||
public void test_rounding_flex_basis_flex_grow_row_width_of_100() {
|
||||
YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, true);
|
||||
YogaConfig config = new YogaConfig();
|
||||
config.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, true);
|
||||
|
||||
final YogaNode root = new YogaNode();
|
||||
final YogaNode root = new YogaNode(config);
|
||||
root.setFlexDirection(YogaFlexDirection.ROW);
|
||||
root.setWidth(100f);
|
||||
root.setHeight(100f);
|
||||
|
||||
final YogaNode root_child0 = new YogaNode();
|
||||
final YogaNode root_child0 = new YogaNode(config);
|
||||
root_child0.setFlexGrow(1f);
|
||||
root.addChildAt(root_child0, 0);
|
||||
|
||||
final YogaNode root_child1 = new YogaNode();
|
||||
final YogaNode root_child1 = new YogaNode(config);
|
||||
root_child1.setFlexGrow(1f);
|
||||
root.addChildAt(root_child1, 1);
|
||||
|
||||
final YogaNode root_child2 = new YogaNode();
|
||||
final YogaNode root_child2 = new YogaNode(config);
|
||||
root_child2.setFlexGrow(1f);
|
||||
root.addChildAt(root_child2, 2);
|
||||
root.setDirection(YogaDirection.LTR);
|
||||
@@ -81,36 +82,35 @@ public class YGRoundingTest {
|
||||
assertEquals(0f, root_child2.getLayoutY(), 0.0f);
|
||||
assertEquals(33f, root_child2.getLayoutWidth(), 0.0f);
|
||||
assertEquals(100f, root_child2.getLayoutHeight(), 0.0f);
|
||||
|
||||
YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_rounding_flex_basis_flex_grow_row_prime_number_width() {
|
||||
YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, true);
|
||||
YogaConfig config = new YogaConfig();
|
||||
config.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, true);
|
||||
|
||||
final YogaNode root = new YogaNode();
|
||||
final YogaNode root = new YogaNode(config);
|
||||
root.setFlexDirection(YogaFlexDirection.ROW);
|
||||
root.setWidth(113f);
|
||||
root.setHeight(100f);
|
||||
|
||||
final YogaNode root_child0 = new YogaNode();
|
||||
final YogaNode root_child0 = new YogaNode(config);
|
||||
root_child0.setFlexGrow(1f);
|
||||
root.addChildAt(root_child0, 0);
|
||||
|
||||
final YogaNode root_child1 = new YogaNode();
|
||||
final YogaNode root_child1 = new YogaNode(config);
|
||||
root_child1.setFlexGrow(1f);
|
||||
root.addChildAt(root_child1, 1);
|
||||
|
||||
final YogaNode root_child2 = new YogaNode();
|
||||
final YogaNode root_child2 = new YogaNode(config);
|
||||
root_child2.setFlexGrow(1f);
|
||||
root.addChildAt(root_child2, 2);
|
||||
|
||||
final YogaNode root_child3 = new YogaNode();
|
||||
final YogaNode root_child3 = new YogaNode(config);
|
||||
root_child3.setFlexGrow(1f);
|
||||
root.addChildAt(root_child3, 3);
|
||||
|
||||
final YogaNode root_child4 = new YogaNode();
|
||||
final YogaNode root_child4 = new YogaNode(config);
|
||||
root_child4.setFlexGrow(1f);
|
||||
root.addChildAt(root_child4, 4);
|
||||
root.setDirection(YogaDirection.LTR);
|
||||
@@ -178,29 +178,28 @@ public class YGRoundingTest {
|
||||
assertEquals(0f, root_child4.getLayoutY(), 0.0f);
|
||||
assertEquals(23f, root_child4.getLayoutWidth(), 0.0f);
|
||||
assertEquals(100f, root_child4.getLayoutHeight(), 0.0f);
|
||||
|
||||
YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_rounding_flex_basis_flex_shrink_row() {
|
||||
YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, true);
|
||||
YogaConfig config = new YogaConfig();
|
||||
config.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, true);
|
||||
|
||||
final YogaNode root = new YogaNode();
|
||||
final YogaNode root = new YogaNode(config);
|
||||
root.setFlexDirection(YogaFlexDirection.ROW);
|
||||
root.setWidth(101f);
|
||||
root.setHeight(100f);
|
||||
|
||||
final YogaNode root_child0 = new YogaNode();
|
||||
final YogaNode root_child0 = new YogaNode(config);
|
||||
root_child0.setFlexShrink(1f);
|
||||
root_child0.setFlexBasis(100f);
|
||||
root.addChildAt(root_child0, 0);
|
||||
|
||||
final YogaNode root_child1 = new YogaNode();
|
||||
final YogaNode root_child1 = new YogaNode(config);
|
||||
root_child1.setFlexBasis(25f);
|
||||
root.addChildAt(root_child1, 1);
|
||||
|
||||
final YogaNode root_child2 = new YogaNode();
|
||||
final YogaNode root_child2 = new YogaNode(config);
|
||||
root_child2.setFlexBasis(25f);
|
||||
root.addChildAt(root_child2, 2);
|
||||
root.setDirection(YogaDirection.LTR);
|
||||
@@ -248,30 +247,29 @@ public class YGRoundingTest {
|
||||
assertEquals(0f, root_child2.getLayoutY(), 0.0f);
|
||||
assertEquals(25f, root_child2.getLayoutWidth(), 0.0f);
|
||||
assertEquals(100f, root_child2.getLayoutHeight(), 0.0f);
|
||||
|
||||
YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_rounding_flex_basis_overrides_main_size() {
|
||||
YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, true);
|
||||
YogaConfig config = new YogaConfig();
|
||||
config.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, true);
|
||||
|
||||
final YogaNode root = new YogaNode();
|
||||
final YogaNode root = new YogaNode(config);
|
||||
root.setWidth(100f);
|
||||
root.setHeight(113f);
|
||||
|
||||
final YogaNode root_child0 = new YogaNode();
|
||||
final YogaNode root_child0 = new YogaNode(config);
|
||||
root_child0.setFlexGrow(1f);
|
||||
root_child0.setFlexBasis(50f);
|
||||
root_child0.setHeight(20f);
|
||||
root.addChildAt(root_child0, 0);
|
||||
|
||||
final YogaNode root_child1 = new YogaNode();
|
||||
final YogaNode root_child1 = new YogaNode(config);
|
||||
root_child1.setFlexGrow(1f);
|
||||
root_child1.setHeight(10f);
|
||||
root.addChildAt(root_child1, 1);
|
||||
|
||||
final YogaNode root_child2 = new YogaNode();
|
||||
final YogaNode root_child2 = new YogaNode(config);
|
||||
root_child2.setFlexGrow(1f);
|
||||
root_child2.setHeight(10f);
|
||||
root.addChildAt(root_child2, 2);
|
||||
@@ -320,30 +318,29 @@ public class YGRoundingTest {
|
||||
assertEquals(89f, root_child2.getLayoutY(), 0.0f);
|
||||
assertEquals(100f, root_child2.getLayoutWidth(), 0.0f);
|
||||
assertEquals(24f, root_child2.getLayoutHeight(), 0.0f);
|
||||
|
||||
YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_rounding_total_fractial() {
|
||||
YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, true);
|
||||
YogaConfig config = new YogaConfig();
|
||||
config.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, true);
|
||||
|
||||
final YogaNode root = new YogaNode();
|
||||
final YogaNode root = new YogaNode(config);
|
||||
root.setWidth(87.4f);
|
||||
root.setHeight(113.4f);
|
||||
|
||||
final YogaNode root_child0 = new YogaNode();
|
||||
final YogaNode root_child0 = new YogaNode(config);
|
||||
root_child0.setFlexGrow(0.7f);
|
||||
root_child0.setFlexBasis(50.3f);
|
||||
root_child0.setHeight(20.3f);
|
||||
root.addChildAt(root_child0, 0);
|
||||
|
||||
final YogaNode root_child1 = new YogaNode();
|
||||
final YogaNode root_child1 = new YogaNode(config);
|
||||
root_child1.setFlexGrow(1.6f);
|
||||
root_child1.setHeight(10f);
|
||||
root.addChildAt(root_child1, 1);
|
||||
|
||||
final YogaNode root_child2 = new YogaNode();
|
||||
final YogaNode root_child2 = new YogaNode(config);
|
||||
root_child2.setFlexGrow(1.1f);
|
||||
root_child2.setHeight(10.7f);
|
||||
root.addChildAt(root_child2, 2);
|
||||
@@ -392,44 +389,43 @@ public class YGRoundingTest {
|
||||
assertEquals(89f, root_child2.getLayoutY(), 0.0f);
|
||||
assertEquals(87f, root_child2.getLayoutWidth(), 0.0f);
|
||||
assertEquals(24f, root_child2.getLayoutHeight(), 0.0f);
|
||||
|
||||
YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_rounding_total_fractial_nested() {
|
||||
YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, true);
|
||||
YogaConfig config = new YogaConfig();
|
||||
config.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, true);
|
||||
|
||||
final YogaNode root = new YogaNode();
|
||||
final YogaNode root = new YogaNode(config);
|
||||
root.setWidth(87.4f);
|
||||
root.setHeight(113.4f);
|
||||
|
||||
final YogaNode root_child0 = new YogaNode();
|
||||
final YogaNode root_child0 = new YogaNode(config);
|
||||
root_child0.setFlexGrow(0.7f);
|
||||
root_child0.setFlexBasis(50.3f);
|
||||
root_child0.setHeight(20.3f);
|
||||
root.addChildAt(root_child0, 0);
|
||||
|
||||
final YogaNode root_child0_child0 = new YogaNode();
|
||||
final YogaNode root_child0_child0 = new YogaNode(config);
|
||||
root_child0_child0.setFlexGrow(1f);
|
||||
root_child0_child0.setFlexBasis(0.3f);
|
||||
root_child0_child0.setPosition(YogaEdge.BOTTOM, 13.3f);
|
||||
root_child0_child0.setHeight(9.9f);
|
||||
root_child0.addChildAt(root_child0_child0, 0);
|
||||
|
||||
final YogaNode root_child0_child1 = new YogaNode();
|
||||
final YogaNode root_child0_child1 = new YogaNode(config);
|
||||
root_child0_child1.setFlexGrow(4f);
|
||||
root_child0_child1.setFlexBasis(0.3f);
|
||||
root_child0_child1.setPosition(YogaEdge.TOP, 13.3f);
|
||||
root_child0_child1.setHeight(1.1f);
|
||||
root_child0.addChildAt(root_child0_child1, 1);
|
||||
|
||||
final YogaNode root_child1 = new YogaNode();
|
||||
final YogaNode root_child1 = new YogaNode(config);
|
||||
root_child1.setFlexGrow(1.6f);
|
||||
root_child1.setHeight(10f);
|
||||
root.addChildAt(root_child1, 1);
|
||||
|
||||
final YogaNode root_child2 = new YogaNode();
|
||||
final YogaNode root_child2 = new YogaNode(config);
|
||||
root_child2.setFlexGrow(1.1f);
|
||||
root_child2.setHeight(10.7f);
|
||||
root.addChildAt(root_child2, 2);
|
||||
@@ -498,30 +494,29 @@ public class YGRoundingTest {
|
||||
assertEquals(89f, root_child2.getLayoutY(), 0.0f);
|
||||
assertEquals(87f, root_child2.getLayoutWidth(), 0.0f);
|
||||
assertEquals(24f, root_child2.getLayoutHeight(), 0.0f);
|
||||
|
||||
YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_rounding_fractial_input_1() {
|
||||
YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, true);
|
||||
YogaConfig config = new YogaConfig();
|
||||
config.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, true);
|
||||
|
||||
final YogaNode root = new YogaNode();
|
||||
final YogaNode root = new YogaNode(config);
|
||||
root.setWidth(100f);
|
||||
root.setHeight(113.4f);
|
||||
|
||||
final YogaNode root_child0 = new YogaNode();
|
||||
final YogaNode root_child0 = new YogaNode(config);
|
||||
root_child0.setFlexGrow(1f);
|
||||
root_child0.setFlexBasis(50f);
|
||||
root_child0.setHeight(20f);
|
||||
root.addChildAt(root_child0, 0);
|
||||
|
||||
final YogaNode root_child1 = new YogaNode();
|
||||
final YogaNode root_child1 = new YogaNode(config);
|
||||
root_child1.setFlexGrow(1f);
|
||||
root_child1.setHeight(10f);
|
||||
root.addChildAt(root_child1, 1);
|
||||
|
||||
final YogaNode root_child2 = new YogaNode();
|
||||
final YogaNode root_child2 = new YogaNode(config);
|
||||
root_child2.setFlexGrow(1f);
|
||||
root_child2.setHeight(10f);
|
||||
root.addChildAt(root_child2, 2);
|
||||
@@ -570,30 +565,29 @@ public class YGRoundingTest {
|
||||
assertEquals(89f, root_child2.getLayoutY(), 0.0f);
|
||||
assertEquals(100f, root_child2.getLayoutWidth(), 0.0f);
|
||||
assertEquals(24f, root_child2.getLayoutHeight(), 0.0f);
|
||||
|
||||
YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_rounding_fractial_input_2() {
|
||||
YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, true);
|
||||
YogaConfig config = new YogaConfig();
|
||||
config.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, true);
|
||||
|
||||
final YogaNode root = new YogaNode();
|
||||
final YogaNode root = new YogaNode(config);
|
||||
root.setWidth(100f);
|
||||
root.setHeight(113.6f);
|
||||
|
||||
final YogaNode root_child0 = new YogaNode();
|
||||
final YogaNode root_child0 = new YogaNode(config);
|
||||
root_child0.setFlexGrow(1f);
|
||||
root_child0.setFlexBasis(50f);
|
||||
root_child0.setHeight(20f);
|
||||
root.addChildAt(root_child0, 0);
|
||||
|
||||
final YogaNode root_child1 = new YogaNode();
|
||||
final YogaNode root_child1 = new YogaNode(config);
|
||||
root_child1.setFlexGrow(1f);
|
||||
root_child1.setHeight(10f);
|
||||
root.addChildAt(root_child1, 1);
|
||||
|
||||
final YogaNode root_child2 = new YogaNode();
|
||||
final YogaNode root_child2 = new YogaNode(config);
|
||||
root_child2.setFlexGrow(1f);
|
||||
root_child2.setHeight(10f);
|
||||
root.addChildAt(root_child2, 2);
|
||||
@@ -642,31 +636,30 @@ public class YGRoundingTest {
|
||||
assertEquals(89f, root_child2.getLayoutY(), 0.0f);
|
||||
assertEquals(100f, root_child2.getLayoutWidth(), 0.0f);
|
||||
assertEquals(25f, root_child2.getLayoutHeight(), 0.0f);
|
||||
|
||||
YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_rounding_fractial_input_3() {
|
||||
YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, true);
|
||||
YogaConfig config = new YogaConfig();
|
||||
config.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, true);
|
||||
|
||||
final YogaNode root = new YogaNode();
|
||||
final YogaNode root = new YogaNode(config);
|
||||
root.setPosition(YogaEdge.TOP, 0.3f);
|
||||
root.setWidth(100f);
|
||||
root.setHeight(113.4f);
|
||||
|
||||
final YogaNode root_child0 = new YogaNode();
|
||||
final YogaNode root_child0 = new YogaNode(config);
|
||||
root_child0.setFlexGrow(1f);
|
||||
root_child0.setFlexBasis(50f);
|
||||
root_child0.setHeight(20f);
|
||||
root.addChildAt(root_child0, 0);
|
||||
|
||||
final YogaNode root_child1 = new YogaNode();
|
||||
final YogaNode root_child1 = new YogaNode(config);
|
||||
root_child1.setFlexGrow(1f);
|
||||
root_child1.setHeight(10f);
|
||||
root.addChildAt(root_child1, 1);
|
||||
|
||||
final YogaNode root_child2 = new YogaNode();
|
||||
final YogaNode root_child2 = new YogaNode(config);
|
||||
root_child2.setFlexGrow(1f);
|
||||
root_child2.setHeight(10f);
|
||||
root.addChildAt(root_child2, 2);
|
||||
@@ -715,31 +708,30 @@ public class YGRoundingTest {
|
||||
assertEquals(89f, root_child2.getLayoutY(), 0.0f);
|
||||
assertEquals(100f, root_child2.getLayoutWidth(), 0.0f);
|
||||
assertEquals(24f, root_child2.getLayoutHeight(), 0.0f);
|
||||
|
||||
YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_rounding_fractial_input_4() {
|
||||
YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, true);
|
||||
YogaConfig config = new YogaConfig();
|
||||
config.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, true);
|
||||
|
||||
final YogaNode root = new YogaNode();
|
||||
final YogaNode root = new YogaNode(config);
|
||||
root.setPosition(YogaEdge.TOP, 0.7f);
|
||||
root.setWidth(100f);
|
||||
root.setHeight(113.4f);
|
||||
|
||||
final YogaNode root_child0 = new YogaNode();
|
||||
final YogaNode root_child0 = new YogaNode(config);
|
||||
root_child0.setFlexGrow(1f);
|
||||
root_child0.setFlexBasis(50f);
|
||||
root_child0.setHeight(20f);
|
||||
root.addChildAt(root_child0, 0);
|
||||
|
||||
final YogaNode root_child1 = new YogaNode();
|
||||
final YogaNode root_child1 = new YogaNode(config);
|
||||
root_child1.setFlexGrow(1f);
|
||||
root_child1.setHeight(10f);
|
||||
root.addChildAt(root_child1, 1);
|
||||
|
||||
final YogaNode root_child2 = new YogaNode();
|
||||
final YogaNode root_child2 = new YogaNode(config);
|
||||
root_child2.setFlexGrow(1f);
|
||||
root_child2.setHeight(10f);
|
||||
root.addChildAt(root_child2, 2);
|
||||
@@ -788,8 +780,6 @@ public class YGRoundingTest {
|
||||
assertEquals(89f, root_child2.getLayoutY(), 0.0f);
|
||||
assertEquals(100f, root_child2.getLayoutWidth(), 0.0f);
|
||||
assertEquals(24f, root_child2.getLayoutHeight(), 0.0f);
|
||||
|
||||
YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, false);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user