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:
Lukas Wöhrl
2017-03-01 09:19:55 -08:00
committed by Facebook Github Bot
parent 8668e43f6d
commit 37c48257ae
89 changed files with 4536 additions and 3049 deletions

View File

@@ -13,11 +13,11 @@ var Yoga = Yoga || require("../../sources/entry-" + process.env.TEST_ENTRY);
it("max_width", function () {
try {
var root = Yoga.Node.create();
var root = Yoga.Node.create(config);
root.setWidth(100);
root.setHeight(100);
var root_child0 = Yoga.Node.create();
var root_child0 = Yoga.Node.create(config);
root_child0.setMaxWidth(50);
root_child0.setHeight(10);
root.insertChild(root_child0, 0);
@@ -52,12 +52,12 @@ it("max_width", function () {
});
it("max_height", function () {
try {
var root = Yoga.Node.create();
var root = Yoga.Node.create(config);
root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW);
root.setWidth(100);
root.setHeight(100);
var root_child0 = Yoga.Node.create();
var root_child0 = Yoga.Node.create(config);
root_child0.setWidth(10);
root_child0.setMaxHeight(50);
root.insertChild(root_child0, 0);
@@ -92,16 +92,16 @@ it("max_height", function () {
});
it("min_height", function () {
try {
var root = Yoga.Node.create();
var root = Yoga.Node.create(config);
root.setWidth(100);
root.setHeight(100);
var root_child0 = Yoga.Node.create();
var root_child0 = Yoga.Node.create(config);
root_child0.setFlexGrow(1);
root_child0.setMinHeight(60);
root.insertChild(root_child0, 0);
var root_child1 = Yoga.Node.create();
var root_child1 = Yoga.Node.create(config);
root_child1.setFlexGrow(1);
root.insertChild(root_child1, 1);
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_LTR);
@@ -145,17 +145,17 @@ it("min_height", function () {
});
it("min_width", function () {
try {
var root = Yoga.Node.create();
var root = Yoga.Node.create(config);
root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW);
root.setWidth(100);
root.setHeight(100);
var root_child0 = Yoga.Node.create();
var root_child0 = Yoga.Node.create(config);
root_child0.setFlexGrow(1);
root_child0.setMinWidth(60);
root.insertChild(root_child0, 0);
var root_child1 = Yoga.Node.create();
var root_child1 = Yoga.Node.create(config);
root_child1.setFlexGrow(1);
root.insertChild(root_child1, 1);
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_LTR);
@@ -199,13 +199,13 @@ it("min_width", function () {
});
it("justify_content_min_max", function () {
try {
var root = Yoga.Node.create();
var root = Yoga.Node.create(config);
root.setJustifyContent(Yoga.JUSTIFY_CENTER);
root.setWidth(100);
root.setMinHeight(100);
root.setMaxHeight(200);
var root_child0 = Yoga.Node.create();
var root_child0 = Yoga.Node.create(config);
root_child0.setWidth(60);
root_child0.setHeight(60);
root.insertChild(root_child0, 0);
@@ -240,13 +240,13 @@ it("justify_content_min_max", function () {
});
it("align_items_min_max", function () {
try {
var root = Yoga.Node.create();
var root = Yoga.Node.create(config);
root.setAlignItems(Yoga.ALIGN_CENTER);
root.setMinWidth(100);
root.setMaxWidth(200);
root.setHeight(100);
var root_child0 = Yoga.Node.create();
var root_child0 = Yoga.Node.create(config);
root_child0.setWidth(60);
root_child0.setHeight(60);
root.insertChild(root_child0, 0);
@@ -281,22 +281,22 @@ it("align_items_min_max", function () {
});
it("justify_content_overflow_min_max", function () {
try {
var root = Yoga.Node.create();
var root = Yoga.Node.create(config);
root.setJustifyContent(Yoga.JUSTIFY_CENTER);
root.setMinHeight(100);
root.setMaxHeight(110);
var root_child0 = Yoga.Node.create();
var root_child0 = Yoga.Node.create(config);
root_child0.setWidth(50);
root_child0.setHeight(50);
root.insertChild(root_child0, 0);
var root_child1 = Yoga.Node.create();
var root_child1 = Yoga.Node.create(config);
root_child1.setWidth(50);
root_child1.setHeight(50);
root.insertChild(root_child1, 1);
var root_child2 = Yoga.Node.create();
var root_child2 = Yoga.Node.create(config);
root_child2.setWidth(50);
root_child2.setHeight(50);
root.insertChild(root_child2, 2);
@@ -353,17 +353,17 @@ it("flex_grow_to_min", function () {
Yoga.setExperimentalFeatureEnabled(Yoga.EXPERIMENTAL_FEATURE_MIN_FLEX_FIX, true);
try {
var root = Yoga.Node.create();
var root = Yoga.Node.create(config);
root.setWidth(100);
root.setMinHeight(100);
root.setMaxHeight(500);
var root_child0 = Yoga.Node.create();
var root_child0 = Yoga.Node.create(config);
root_child0.setFlexGrow(1);
root_child0.setFlexShrink(1);
root.insertChild(root_child0, 0);
var root_child1 = Yoga.Node.create();
var root_child1 = Yoga.Node.create(config);
root_child1.setHeight(50);
root.insertChild(root_child1, 1);
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_LTR);
@@ -411,17 +411,17 @@ it("flex_grow_in_at_most_container", function () {
Yoga.setExperimentalFeatureEnabled(Yoga.EXPERIMENTAL_FEATURE_MIN_FLEX_FIX, true);
try {
var root = Yoga.Node.create();
var root = Yoga.Node.create(config);
root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW);
root.setAlignItems(Yoga.ALIGN_FLEX_START);
root.setWidth(100);
root.setHeight(100);
var root_child0 = Yoga.Node.create();
var root_child0 = Yoga.Node.create(config);
root_child0.setFlexDirection(Yoga.FLEX_DIRECTION_ROW);
root.insertChild(root_child0, 0);
var root_child0_child0 = Yoga.Node.create();
var root_child0_child0 = Yoga.Node.create(config);
root_child0_child0.setFlexGrow(1);
root_child0_child0.setFlexBasis(0);
root_child0.insertChild(root_child0_child0, 0);
@@ -468,16 +468,16 @@ it("flex_grow_in_at_most_container", function () {
});
it("flex_grow_within_max_width", function () {
try {
var root = Yoga.Node.create();
var root = Yoga.Node.create(config);
root.setWidth(200);
root.setHeight(100);
var root_child0 = Yoga.Node.create();
var root_child0 = Yoga.Node.create(config);
root_child0.setFlexDirection(Yoga.FLEX_DIRECTION_ROW);
root_child0.setMaxWidth(100);
root.insertChild(root_child0, 0);
var root_child0_child0 = Yoga.Node.create();
var root_child0_child0 = Yoga.Node.create(config);
root_child0_child0.setFlexGrow(1);
root_child0_child0.setHeight(20);
root_child0.insertChild(root_child0_child0, 0);
@@ -522,16 +522,16 @@ it("flex_grow_within_max_width", function () {
});
it("flex_grow_within_constrained_max_width", function () {
try {
var root = Yoga.Node.create();
var root = Yoga.Node.create(config);
root.setWidth(200);
root.setHeight(100);
var root_child0 = Yoga.Node.create();
var root_child0 = Yoga.Node.create(config);
root_child0.setFlexDirection(Yoga.FLEX_DIRECTION_ROW);
root_child0.setMaxWidth(300);
root.insertChild(root_child0, 0);
var root_child0_child0 = Yoga.Node.create();
var root_child0_child0 = Yoga.Node.create(config);
root_child0_child0.setFlexGrow(1);
root_child0_child0.setHeight(20);
root_child0.insertChild(root_child0_child0, 0);
@@ -576,16 +576,16 @@ it("flex_grow_within_constrained_max_width", function () {
});
it("flex_grow_within_constrained_min_row", function () {
try {
var root = Yoga.Node.create();
var root = Yoga.Node.create(config);
root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW);
root.setMinWidth(100);
root.setHeight(100);
var root_child0 = Yoga.Node.create();
var root_child0 = Yoga.Node.create(config);
root_child0.setFlexGrow(1);
root.insertChild(root_child0, 0);
var root_child1 = Yoga.Node.create();
var root_child1 = Yoga.Node.create(config);
root_child1.setWidth(50);
root.insertChild(root_child1, 1);
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_LTR);
@@ -629,14 +629,14 @@ it("flex_grow_within_constrained_min_row", function () {
});
it("flex_grow_within_constrained_min_column", function () {
try {
var root = Yoga.Node.create();
var root = Yoga.Node.create(config);
root.setMinHeight(100);
var root_child0 = Yoga.Node.create();
var root_child0 = Yoga.Node.create(config);
root_child0.setFlexGrow(1);
root.insertChild(root_child0, 0);
var root_child1 = Yoga.Node.create();
var root_child1 = Yoga.Node.create(config);
root_child1.setHeight(50);
root.insertChild(root_child1, 1);
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_LTR);
@@ -680,21 +680,21 @@ it("flex_grow_within_constrained_min_column", function () {
});
it("flex_grow_within_constrained_max_row", function () {
try {
var root = Yoga.Node.create();
var root = Yoga.Node.create(config);
root.setWidth(200);
var root_child0 = Yoga.Node.create();
var root_child0 = Yoga.Node.create(config);
root_child0.setFlexDirection(Yoga.FLEX_DIRECTION_ROW);
root_child0.setMaxWidth(100);
root_child0.setHeight(100);
root.insertChild(root_child0, 0);
var root_child0_child0 = Yoga.Node.create();
var root_child0_child0 = Yoga.Node.create(config);
root_child0_child0.setFlexShrink(1);
root_child0_child0.setFlexBasis(100);
root_child0.insertChild(root_child0_child0, 0);
var root_child0_child1 = Yoga.Node.create();
var root_child0_child1 = Yoga.Node.create(config);
root_child0_child1.setWidth(50);
root_child0.insertChild(root_child0_child1, 1);
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_LTR);
@@ -748,16 +748,16 @@ it("flex_grow_within_constrained_max_row", function () {
});
it("flex_grow_within_constrained_max_column", function () {
try {
var root = Yoga.Node.create();
var root = Yoga.Node.create(config);
root.setWidth(100);
root.setMaxHeight(100);
var root_child0 = Yoga.Node.create();
var root_child0 = Yoga.Node.create(config);
root_child0.setFlexShrink(1);
root_child0.setFlexBasis(100);
root.insertChild(root_child0, 0);
var root_child1 = Yoga.Node.create();
var root_child1 = Yoga.Node.create(config);
root_child1.setHeight(50);
root.insertChild(root_child1, 1);
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_LTR);
@@ -801,7 +801,7 @@ it("flex_grow_within_constrained_max_column", function () {
});
it("min_width_overrides_width", function () {
try {
var root = Yoga.Node.create();
var root = Yoga.Node.create(config);
root.setWidth(50);
root.setMinWidth(100);
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_LTR);
@@ -825,7 +825,7 @@ it("min_width_overrides_width", function () {
});
it("max_width_overrides_width", function () {
try {
var root = Yoga.Node.create();
var root = Yoga.Node.create(config);
root.setWidth(200);
root.setMaxWidth(100);
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_LTR);
@@ -849,7 +849,7 @@ it("max_width_overrides_width", function () {
});
it("min_height_overrides_height", function () {
try {
var root = Yoga.Node.create();
var root = Yoga.Node.create(config);
root.setHeight(50);
root.setMinHeight(100);
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_LTR);
@@ -873,7 +873,7 @@ it("min_height_overrides_height", function () {
});
it("max_height_overrides_height", function () {
try {
var root = Yoga.Node.create();
var root = Yoga.Node.create(config);
root.setHeight(200);
root.setMaxHeight(100);
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_LTR);
@@ -897,12 +897,12 @@ it("max_height_overrides_height", function () {
});
it("min_max_percent_no_width_height", function () {
try {
var root = Yoga.Node.create();
var root = Yoga.Node.create(config);
root.setAlignItems(Yoga.ALIGN_FLEX_START);
root.setWidth(100);
root.setHeight(100);
var root_child0 = Yoga.Node.create();
var root_child0 = Yoga.Node.create(config);
root_child0.setMinWidth("10%");
root_child0.setMaxWidth("10%");
root_child0.setMinHeight("10%");