Skip to content

Commit ff59646

Browse files
joevilchesfacebook-github-bot
authored andcommitted
Fix issue where we were not applying flex end correctly when justifying (#1487)
Summary: Pull Request resolved: #1487 X-link: facebook/react-native#41691 The code here was just wrong. I changed it to be the same logic as the Justify:FlexStart case, but with the flex end sides. Then I get the position for the opposite edge since we need to write to flex start side. Reviewed By: NickGerleman Differential Revision: D51383792 fbshipit-source-id: 4454c7eb438b96f53a38f51d2f2180f00eb5da23
1 parent 73674ab commit ff59646

File tree

5 files changed

+764
-2
lines changed

5 files changed

+764
-2
lines changed

gentest/fixtures/YGStaticPositionTest.html

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,3 +529,29 @@
529529
</div>
530530
</div>
531531
</div>
532+
533+
<div id="static_position_justify_flex_end_amalgamation">
534+
<div style="position: relative; margin: 5px 9px 1px 4px; border-width: 6px 7px 8px 5px; padding: 9px 11px 13px 2px">
535+
<div
536+
style="position: static; margin: 6px 3px 9px 8px; border-width: 10px 2px 1px 8px; padding: 7px 9px 4px 1px; justify-content: flex-end;">
537+
<div
538+
style="position: absolute; width: 21%; margin: 12px 4px 7px 9px; border-width: 1px 5px 9px 2px; padding: 3px 8px 10px 5px">
539+
<div
540+
style="width: 100px; height: 50px; position: relative; margin: 12px 4px 7px 9px; border-width: 1px 5px 9px 2px; padding: 3px 8px 10px 5px">
541+
</div>
542+
</div>
543+
<div
544+
style="position: relative; width: 10%; margin: 12px 4px 7px 9px; border-width: 1px 5px 9px 2px; padding: 3px 8px 10px 5px">
545+
<div
546+
style="width: 100px; height: 50px; position: relative; margin: 12px 4px 7px 9px; border-width: 1px 5px 9px 2px; padding: 3px 8px 10px 5px">
547+
</div>
548+
</div>
549+
<div
550+
style="position: relative; width: 10%; margin: 12px 4px 7px 9px; border-width: 1px 5px 9px 2px; padding: 3px 8px 10px 5px">
551+
<div
552+
style="width: 100px; height: 50px; position: relative; margin: 12px 4px 7px 9px; border-width: 1px 5px 9px 2px; padding: 3px 8px 10px 5px">
553+
</div>
554+
</div>
555+
</div>
556+
</div>
557+
</div>

java/tests/com/facebook/yoga/YGStaticPositionTest.java

Lines changed: 241 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4517,6 +4517,247 @@ public void test_static_position_justify_center_amalgamation() {
45174517
assertEquals(50f, root_child0_child0_child2_child0.getLayoutHeight(), 0.0f);
45184518
}
45194519

4520+
@Test
4521+
public void test_static_position_justify_flex_end_amalgamation() {
4522+
YogaConfig config = YogaConfigFactory.create();
4523+
config.setExperimentalFeatureEnabled(YogaExperimentalFeature.ABSOLUTE_PERCENTAGE_AGAINST_PADDING_EDGE, true);
4524+
4525+
final YogaNode root = createNode(config);
4526+
root.setPositionType(YogaPositionType.ABSOLUTE);
4527+
4528+
final YogaNode root_child0 = createNode(config);
4529+
root_child0.setPositionType(YogaPositionType.RELATIVE);
4530+
root_child0.setMargin(YogaEdge.LEFT, 4f);
4531+
root_child0.setMargin(YogaEdge.TOP, 5f);
4532+
root_child0.setMargin(YogaEdge.RIGHT, 9f);
4533+
root_child0.setMargin(YogaEdge.BOTTOM, 1f);
4534+
root_child0.setPadding(YogaEdge.LEFT, 2);
4535+
root_child0.setPadding(YogaEdge.TOP, 9);
4536+
root_child0.setPadding(YogaEdge.RIGHT, 11);
4537+
root_child0.setPadding(YogaEdge.BOTTOM, 13);
4538+
root_child0.setBorder(YogaEdge.LEFT, 5f);
4539+
root_child0.setBorder(YogaEdge.TOP, 6f);
4540+
root_child0.setBorder(YogaEdge.RIGHT, 7f);
4541+
root_child0.setBorder(YogaEdge.BOTTOM, 8f);
4542+
root.addChildAt(root_child0, 0);
4543+
4544+
final YogaNode root_child0_child0 = createNode(config);
4545+
root_child0_child0.setJustifyContent(YogaJustify.FLEX_END);
4546+
root_child0_child0.setMargin(YogaEdge.LEFT, 8f);
4547+
root_child0_child0.setMargin(YogaEdge.TOP, 6f);
4548+
root_child0_child0.setMargin(YogaEdge.RIGHT, 3f);
4549+
root_child0_child0.setMargin(YogaEdge.BOTTOM, 9f);
4550+
root_child0_child0.setPadding(YogaEdge.LEFT, 1);
4551+
root_child0_child0.setPadding(YogaEdge.TOP, 7);
4552+
root_child0_child0.setPadding(YogaEdge.RIGHT, 9);
4553+
root_child0_child0.setPadding(YogaEdge.BOTTOM, 4);
4554+
root_child0_child0.setBorder(YogaEdge.LEFT, 8f);
4555+
root_child0_child0.setBorder(YogaEdge.TOP, 10f);
4556+
root_child0_child0.setBorder(YogaEdge.RIGHT, 2f);
4557+
root_child0_child0.setBorder(YogaEdge.BOTTOM, 1f);
4558+
root_child0.addChildAt(root_child0_child0, 0);
4559+
4560+
final YogaNode root_child0_child0_child0 = createNode(config);
4561+
root_child0_child0_child0.setPositionType(YogaPositionType.ABSOLUTE);
4562+
root_child0_child0_child0.setMargin(YogaEdge.LEFT, 9f);
4563+
root_child0_child0_child0.setMargin(YogaEdge.TOP, 12f);
4564+
root_child0_child0_child0.setMargin(YogaEdge.RIGHT, 4f);
4565+
root_child0_child0_child0.setMargin(YogaEdge.BOTTOM, 7f);
4566+
root_child0_child0_child0.setPadding(YogaEdge.LEFT, 5);
4567+
root_child0_child0_child0.setPadding(YogaEdge.TOP, 3);
4568+
root_child0_child0_child0.setPadding(YogaEdge.RIGHT, 8);
4569+
root_child0_child0_child0.setPadding(YogaEdge.BOTTOM, 10);
4570+
root_child0_child0_child0.setBorder(YogaEdge.LEFT, 2f);
4571+
root_child0_child0_child0.setBorder(YogaEdge.TOP, 1f);
4572+
root_child0_child0_child0.setBorder(YogaEdge.RIGHT, 5f);
4573+
root_child0_child0_child0.setBorder(YogaEdge.BOTTOM, 9f);
4574+
root_child0_child0_child0.setWidthPercent(21f);
4575+
root_child0_child0.addChildAt(root_child0_child0_child0, 0);
4576+
4577+
final YogaNode root_child0_child0_child0_child0 = createNode(config);
4578+
root_child0_child0_child0_child0.setPositionType(YogaPositionType.RELATIVE);
4579+
root_child0_child0_child0_child0.setMargin(YogaEdge.LEFT, 9f);
4580+
root_child0_child0_child0_child0.setMargin(YogaEdge.TOP, 12f);
4581+
root_child0_child0_child0_child0.setMargin(YogaEdge.RIGHT, 4f);
4582+
root_child0_child0_child0_child0.setMargin(YogaEdge.BOTTOM, 7f);
4583+
root_child0_child0_child0_child0.setPadding(YogaEdge.LEFT, 5);
4584+
root_child0_child0_child0_child0.setPadding(YogaEdge.TOP, 3);
4585+
root_child0_child0_child0_child0.setPadding(YogaEdge.RIGHT, 8);
4586+
root_child0_child0_child0_child0.setPadding(YogaEdge.BOTTOM, 10);
4587+
root_child0_child0_child0_child0.setBorder(YogaEdge.LEFT, 2f);
4588+
root_child0_child0_child0_child0.setBorder(YogaEdge.TOP, 1f);
4589+
root_child0_child0_child0_child0.setBorder(YogaEdge.RIGHT, 5f);
4590+
root_child0_child0_child0_child0.setBorder(YogaEdge.BOTTOM, 9f);
4591+
root_child0_child0_child0_child0.setWidth(100f);
4592+
root_child0_child0_child0_child0.setHeight(50f);
4593+
root_child0_child0_child0.addChildAt(root_child0_child0_child0_child0, 0);
4594+
4595+
final YogaNode root_child0_child0_child1 = createNode(config);
4596+
root_child0_child0_child1.setPositionType(YogaPositionType.RELATIVE);
4597+
root_child0_child0_child1.setMargin(YogaEdge.LEFT, 9f);
4598+
root_child0_child0_child1.setMargin(YogaEdge.TOP, 12f);
4599+
root_child0_child0_child1.setMargin(YogaEdge.RIGHT, 4f);
4600+
root_child0_child0_child1.setMargin(YogaEdge.BOTTOM, 7f);
4601+
root_child0_child0_child1.setPadding(YogaEdge.LEFT, 5);
4602+
root_child0_child0_child1.setPadding(YogaEdge.TOP, 3);
4603+
root_child0_child0_child1.setPadding(YogaEdge.RIGHT, 8);
4604+
root_child0_child0_child1.setPadding(YogaEdge.BOTTOM, 10);
4605+
root_child0_child0_child1.setBorder(YogaEdge.LEFT, 2f);
4606+
root_child0_child0_child1.setBorder(YogaEdge.TOP, 1f);
4607+
root_child0_child0_child1.setBorder(YogaEdge.RIGHT, 5f);
4608+
root_child0_child0_child1.setBorder(YogaEdge.BOTTOM, 9f);
4609+
root_child0_child0_child1.setWidthPercent(10f);
4610+
root_child0_child0.addChildAt(root_child0_child0_child1, 1);
4611+
4612+
final YogaNode root_child0_child0_child1_child0 = createNode(config);
4613+
root_child0_child0_child1_child0.setPositionType(YogaPositionType.RELATIVE);
4614+
root_child0_child0_child1_child0.setMargin(YogaEdge.LEFT, 9f);
4615+
root_child0_child0_child1_child0.setMargin(YogaEdge.TOP, 12f);
4616+
root_child0_child0_child1_child0.setMargin(YogaEdge.RIGHT, 4f);
4617+
root_child0_child0_child1_child0.setMargin(YogaEdge.BOTTOM, 7f);
4618+
root_child0_child0_child1_child0.setPadding(YogaEdge.LEFT, 5);
4619+
root_child0_child0_child1_child0.setPadding(YogaEdge.TOP, 3);
4620+
root_child0_child0_child1_child0.setPadding(YogaEdge.RIGHT, 8);
4621+
root_child0_child0_child1_child0.setPadding(YogaEdge.BOTTOM, 10);
4622+
root_child0_child0_child1_child0.setBorder(YogaEdge.LEFT, 2f);
4623+
root_child0_child0_child1_child0.setBorder(YogaEdge.TOP, 1f);
4624+
root_child0_child0_child1_child0.setBorder(YogaEdge.RIGHT, 5f);
4625+
root_child0_child0_child1_child0.setBorder(YogaEdge.BOTTOM, 9f);
4626+
root_child0_child0_child1_child0.setWidth(100f);
4627+
root_child0_child0_child1_child0.setHeight(50f);
4628+
root_child0_child0_child1.addChildAt(root_child0_child0_child1_child0, 0);
4629+
4630+
final YogaNode root_child0_child0_child2 = createNode(config);
4631+
root_child0_child0_child2.setPositionType(YogaPositionType.RELATIVE);
4632+
root_child0_child0_child2.setMargin(YogaEdge.LEFT, 9f);
4633+
root_child0_child0_child2.setMargin(YogaEdge.TOP, 12f);
4634+
root_child0_child0_child2.setMargin(YogaEdge.RIGHT, 4f);
4635+
root_child0_child0_child2.setMargin(YogaEdge.BOTTOM, 7f);
4636+
root_child0_child0_child2.setPadding(YogaEdge.LEFT, 5);
4637+
root_child0_child0_child2.setPadding(YogaEdge.TOP, 3);
4638+
root_child0_child0_child2.setPadding(YogaEdge.RIGHT, 8);
4639+
root_child0_child0_child2.setPadding(YogaEdge.BOTTOM, 10);
4640+
root_child0_child0_child2.setBorder(YogaEdge.LEFT, 2f);
4641+
root_child0_child0_child2.setBorder(YogaEdge.TOP, 1f);
4642+
root_child0_child0_child2.setBorder(YogaEdge.RIGHT, 5f);
4643+
root_child0_child0_child2.setBorder(YogaEdge.BOTTOM, 9f);
4644+
root_child0_child0_child2.setWidthPercent(10f);
4645+
root_child0_child0.addChildAt(root_child0_child0_child2, 2);
4646+
4647+
final YogaNode root_child0_child0_child2_child0 = createNode(config);
4648+
root_child0_child0_child2_child0.setPositionType(YogaPositionType.RELATIVE);
4649+
root_child0_child0_child2_child0.setMargin(YogaEdge.LEFT, 9f);
4650+
root_child0_child0_child2_child0.setMargin(YogaEdge.TOP, 12f);
4651+
root_child0_child0_child2_child0.setMargin(YogaEdge.RIGHT, 4f);
4652+
root_child0_child0_child2_child0.setMargin(YogaEdge.BOTTOM, 7f);
4653+
root_child0_child0_child2_child0.setPadding(YogaEdge.LEFT, 5);
4654+
root_child0_child0_child2_child0.setPadding(YogaEdge.TOP, 3);
4655+
root_child0_child0_child2_child0.setPadding(YogaEdge.RIGHT, 8);
4656+
root_child0_child0_child2_child0.setPadding(YogaEdge.BOTTOM, 10);
4657+
root_child0_child0_child2_child0.setBorder(YogaEdge.LEFT, 2f);
4658+
root_child0_child0_child2_child0.setBorder(YogaEdge.TOP, 1f);
4659+
root_child0_child0_child2_child0.setBorder(YogaEdge.RIGHT, 5f);
4660+
root_child0_child0_child2_child0.setBorder(YogaEdge.BOTTOM, 9f);
4661+
root_child0_child0_child2_child0.setWidth(100f);
4662+
root_child0_child0_child2_child0.setHeight(50f);
4663+
root_child0_child0_child2.addChildAt(root_child0_child0_child2_child0, 0);
4664+
root.setDirection(YogaDirection.LTR);
4665+
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
4666+
4667+
assertEquals(0f, root.getLayoutX(), 0.0f);
4668+
assertEquals(0f, root.getLayoutY(), 0.0f);
4669+
assertEquals(215f, root.getLayoutWidth(), 0.0f);
4670+
assertEquals(301f, root.getLayoutHeight(), 0.0f);
4671+
4672+
assertEquals(4f, root_child0.getLayoutX(), 0.0f);
4673+
assertEquals(5f, root_child0.getLayoutY(), 0.0f);
4674+
assertEquals(202f, root_child0.getLayoutWidth(), 0.0f);
4675+
assertEquals(295f, root_child0.getLayoutHeight(), 0.0f);
4676+
4677+
assertEquals(15f, root_child0_child0.getLayoutX(), 0.0f);
4678+
assertEquals(21f, root_child0_child0.getLayoutY(), 0.0f);
4679+
assertEquals(166f, root_child0_child0.getLayoutWidth(), 0.0f);
4680+
assertEquals(244f, root_child0_child0.getLayoutHeight(), 0.0f);
4681+
4682+
assertEquals(18f, root_child0_child0_child0.getLayoutX(), 0.0f);
4683+
assertEquals(140f, root_child0_child0_child0.getLayoutY(), 0.0f);
4684+
assertEquals(40f, root_child0_child0_child0.getLayoutWidth(), 0.0f);
4685+
assertEquals(92f, root_child0_child0_child0.getLayoutHeight(), 0.0f);
4686+
4687+
assertEquals(16f, root_child0_child0_child0_child0.getLayoutX(), 0.0f);
4688+
assertEquals(16f, root_child0_child0_child0_child0.getLayoutY(), 0.0f);
4689+
assertEquals(100f, root_child0_child0_child0_child0.getLayoutWidth(), 0.0f);
4690+
assertEquals(50f, root_child0_child0_child0_child0.getLayoutHeight(), 0.0f);
4691+
4692+
assertEquals(18f, root_child0_child0_child1.getLayoutX(), 0.0f);
4693+
assertEquals(29f, root_child0_child0_child1.getLayoutY(), 0.0f);
4694+
assertEquals(20f, root_child0_child0_child1.getLayoutWidth(), 0.0f);
4695+
assertEquals(92f, root_child0_child0_child1.getLayoutHeight(), 0.0f);
4696+
4697+
assertEquals(16f, root_child0_child0_child1_child0.getLayoutX(), 0.0f);
4698+
assertEquals(16f, root_child0_child0_child1_child0.getLayoutY(), 0.0f);
4699+
assertEquals(100f, root_child0_child0_child1_child0.getLayoutWidth(), 0.0f);
4700+
assertEquals(50f, root_child0_child0_child1_child0.getLayoutHeight(), 0.0f);
4701+
4702+
assertEquals(18f, root_child0_child0_child2.getLayoutX(), 0.0f);
4703+
assertEquals(140f, root_child0_child0_child2.getLayoutY(), 0.0f);
4704+
assertEquals(20f, root_child0_child0_child2.getLayoutWidth(), 0.0f);
4705+
assertEquals(92f, root_child0_child0_child2.getLayoutHeight(), 0.0f);
4706+
4707+
assertEquals(16f, root_child0_child0_child2_child0.getLayoutX(), 0.0f);
4708+
assertEquals(16f, root_child0_child0_child2_child0.getLayoutY(), 0.0f);
4709+
assertEquals(100f, root_child0_child0_child2_child0.getLayoutWidth(), 0.0f);
4710+
assertEquals(50f, root_child0_child0_child2_child0.getLayoutHeight(), 0.0f);
4711+
4712+
root.setDirection(YogaDirection.RTL);
4713+
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
4714+
4715+
assertEquals(0f, root.getLayoutX(), 0.0f);
4716+
assertEquals(0f, root.getLayoutY(), 0.0f);
4717+
assertEquals(215f, root.getLayoutWidth(), 0.0f);
4718+
assertEquals(301f, root.getLayoutHeight(), 0.0f);
4719+
4720+
assertEquals(4f, root_child0.getLayoutX(), 0.0f);
4721+
assertEquals(5f, root_child0.getLayoutY(), 0.0f);
4722+
assertEquals(202f, root_child0.getLayoutWidth(), 0.0f);
4723+
assertEquals(295f, root_child0.getLayoutHeight(), 0.0f);
4724+
4725+
assertEquals(15f, root_child0_child0.getLayoutX(), 0.0f);
4726+
assertEquals(21f, root_child0_child0.getLayoutY(), 0.0f);
4727+
assertEquals(166f, root_child0_child0.getLayoutWidth(), 0.0f);
4728+
assertEquals(244f, root_child0_child0.getLayoutHeight(), 0.0f);
4729+
4730+
assertEquals(111f, root_child0_child0_child0.getLayoutX(), 0.0f);
4731+
assertEquals(140f, root_child0_child0_child0.getLayoutY(), 0.0f);
4732+
assertEquals(40f, root_child0_child0_child0.getLayoutWidth(), 0.0f);
4733+
assertEquals(92f, root_child0_child0_child0.getLayoutHeight(), 0.0f);
4734+
4735+
assertEquals(-77f, root_child0_child0_child0_child0.getLayoutX(), 0.0f);
4736+
assertEquals(16f, root_child0_child0_child0_child0.getLayoutY(), 0.0f);
4737+
assertEquals(100f, root_child0_child0_child0_child0.getLayoutWidth(), 0.0f);
4738+
assertEquals(50f, root_child0_child0_child0_child0.getLayoutHeight(), 0.0f);
4739+
4740+
assertEquals(131f, root_child0_child0_child1.getLayoutX(), 0.0f);
4741+
assertEquals(29f, root_child0_child0_child1.getLayoutY(), 0.0f);
4742+
assertEquals(20f, root_child0_child0_child1.getLayoutWidth(), 0.0f);
4743+
assertEquals(92f, root_child0_child0_child1.getLayoutHeight(), 0.0f);
4744+
4745+
assertEquals(-97f, root_child0_child0_child1_child0.getLayoutX(), 0.0f);
4746+
assertEquals(16f, root_child0_child0_child1_child0.getLayoutY(), 0.0f);
4747+
assertEquals(100f, root_child0_child0_child1_child0.getLayoutWidth(), 0.0f);
4748+
assertEquals(50f, root_child0_child0_child1_child0.getLayoutHeight(), 0.0f);
4749+
4750+
assertEquals(131f, root_child0_child0_child2.getLayoutX(), 0.0f);
4751+
assertEquals(140f, root_child0_child0_child2.getLayoutY(), 0.0f);
4752+
assertEquals(20f, root_child0_child0_child2.getLayoutWidth(), 0.0f);
4753+
assertEquals(92f, root_child0_child0_child2.getLayoutHeight(), 0.0f);
4754+
4755+
assertEquals(-97f, root_child0_child0_child2_child0.getLayoutX(), 0.0f);
4756+
assertEquals(16f, root_child0_child0_child2_child0.getLayoutY(), 0.0f);
4757+
assertEquals(100f, root_child0_child0_child2_child0.getLayoutWidth(), 0.0f);
4758+
assertEquals(50f, root_child0_child0_child2_child0.getLayoutHeight(), 0.0f);
4759+
}
4760+
45204761
private YogaNode createNode(YogaConfig config) {
45214762
return mNodeFactory.create(config);
45224763
}

0 commit comments

Comments
 (0)