Fixed issue with first line element gap handling. (#1408)

Summary:
If the first element of a line is not contributing (e.g. position absolute), an additional gap will be added to the line, because the first gap element of the line is never identified (wrong start index).
Fix: raise the index of the first line element until we find an element that is contributing to the line.

Pull Request resolved: https://github.com/facebook/yoga/pull/1408

Reviewed By: yungsters

Differential Revision: D49722065

Pulled By: NickGerleman

fbshipit-source-id: 1068cb0b11ae4b04ec8d063e70540cce06181d5a
This commit is contained in:
jlmip
2023-10-03 06:24:48 -07:00
committed by Facebook GitHub Bot
parent b03a821884
commit 07cabca526
5 changed files with 288 additions and 1 deletions

View File

@@ -485,6 +485,95 @@ public class YGGapTest {
assertEquals(20f, root_child8.getLayoutHeight(), 0.0f);
}
@Test
public void test_column_gap_start_index() {
YogaConfig config = YogaConfigFactory.create();
config.setExperimentalFeatureEnabled(YogaExperimentalFeature.ABSOLUTE_PERCENTAGE_AGAINST_PADDING_EDGE, true);
final YogaNode root = createNode(config);
root.setFlexDirection(YogaFlexDirection.ROW);
root.setWrap(YogaWrap.WRAP);
root.setWidth(80f);
root.setGap(YogaGutter.COLUMN, 10f);
root.setGap(YogaGutter.ROW, 20f);
final YogaNode root_child0 = createNode(config);
root_child0.setPositionType(YogaPositionType.ABSOLUTE);
root_child0.setWidth(20f);
root_child0.setHeight(20f);
root.addChildAt(root_child0, 0);
final YogaNode root_child1 = createNode(config);
root_child1.setWidth(20f);
root_child1.setHeight(20f);
root.addChildAt(root_child1, 1);
final YogaNode root_child2 = createNode(config);
root_child2.setWidth(20f);
root_child2.setHeight(20f);
root.addChildAt(root_child2, 2);
final YogaNode root_child3 = createNode(config);
root_child3.setWidth(20f);
root_child3.setHeight(20f);
root.addChildAt(root_child3, 3);
root.setDirection(YogaDirection.LTR);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(80f, root.getLayoutWidth(), 0.0f);
assertEquals(20f, root.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(20f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(20f, root_child0.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child1.getLayoutX(), 0.0f);
assertEquals(0f, root_child1.getLayoutY(), 0.0f);
assertEquals(20f, root_child1.getLayoutWidth(), 0.0f);
assertEquals(20f, root_child1.getLayoutHeight(), 0.0f);
assertEquals(30f, root_child2.getLayoutX(), 0.0f);
assertEquals(0f, root_child2.getLayoutY(), 0.0f);
assertEquals(20f, root_child2.getLayoutWidth(), 0.0f);
assertEquals(20f, root_child2.getLayoutHeight(), 0.0f);
assertEquals(60f, root_child3.getLayoutX(), 0.0f);
assertEquals(0f, root_child3.getLayoutY(), 0.0f);
assertEquals(20f, root_child3.getLayoutWidth(), 0.0f);
assertEquals(20f, root_child3.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(80f, root.getLayoutWidth(), 0.0f);
assertEquals(20f, root.getLayoutHeight(), 0.0f);
assertEquals(60f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(20f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(20f, root_child0.getLayoutHeight(), 0.0f);
assertEquals(60f, root_child1.getLayoutX(), 0.0f);
assertEquals(0f, root_child1.getLayoutY(), 0.0f);
assertEquals(20f, root_child1.getLayoutWidth(), 0.0f);
assertEquals(20f, root_child1.getLayoutHeight(), 0.0f);
assertEquals(30f, root_child2.getLayoutX(), 0.0f);
assertEquals(0f, root_child2.getLayoutY(), 0.0f);
assertEquals(20f, root_child2.getLayoutWidth(), 0.0f);
assertEquals(20f, root_child2.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child3.getLayoutX(), 0.0f);
assertEquals(0f, root_child3.getLayoutY(), 0.0f);
assertEquals(20f, root_child3.getLayoutWidth(), 0.0f);
assertEquals(20f, root_child3.getLayoutHeight(), 0.0f);
}
@Test
public void test_column_gap_justify_flex_start() {
YogaConfig config = YogaConfigFactory.create();