@@ -278,6 +278,30 @@ public void test_absolute_layout_within_border() {
278278 root_child1 .setWidth (50f );
279279 root_child1 .setHeight (50f );
280280 root .addChildAt (root_child1 , 1 );
281+
282+ final YogaNode root_child2 = new YogaNode (config );
283+ root_child2 .setPositionType (YogaPositionType .ABSOLUTE );
284+ root_child2 .setPosition (YogaEdge .LEFT , 0f );
285+ root_child2 .setPosition (YogaEdge .TOP , 0f );
286+ root_child2 .setMargin (YogaEdge .LEFT , 10f );
287+ root_child2 .setMargin (YogaEdge .TOP , 10f );
288+ root_child2 .setMargin (YogaEdge .RIGHT , 10f );
289+ root_child2 .setMargin (YogaEdge .BOTTOM , 10f );
290+ root_child2 .setWidth (50f );
291+ root_child2 .setHeight (50f );
292+ root .addChildAt (root_child2 , 2 );
293+
294+ final YogaNode root_child3 = new YogaNode (config );
295+ root_child3 .setPositionType (YogaPositionType .ABSOLUTE );
296+ root_child3 .setPosition (YogaEdge .RIGHT , 0f );
297+ root_child3 .setPosition (YogaEdge .BOTTOM , 0f );
298+ root_child3 .setMargin (YogaEdge .LEFT , 10f );
299+ root_child3 .setMargin (YogaEdge .TOP , 10f );
300+ root_child3 .setMargin (YogaEdge .RIGHT , 10f );
301+ root_child3 .setMargin (YogaEdge .BOTTOM , 10f );
302+ root_child3 .setWidth (50f );
303+ root_child3 .setHeight (50f );
304+ root .addChildAt (root_child3 , 3 );
281305 root .setDirection (YogaDirection .LTR );
282306 root .calculateLayout (YogaConstants .UNDEFINED , YogaConstants .UNDEFINED );
283307
@@ -296,6 +320,16 @@ public void test_absolute_layout_within_border() {
296320 assertEquals (50f , root_child1 .getLayoutWidth (), 0.0f );
297321 assertEquals (50f , root_child1 .getLayoutHeight (), 0.0f );
298322
323+ assertEquals (20f , root_child2 .getLayoutX (), 0.0f );
324+ assertEquals (20f , root_child2 .getLayoutY (), 0.0f );
325+ assertEquals (50f , root_child2 .getLayoutWidth (), 0.0f );
326+ assertEquals (50f , root_child2 .getLayoutHeight (), 0.0f );
327+
328+ assertEquals (30f , root_child3 .getLayoutX (), 0.0f );
329+ assertEquals (30f , root_child3 .getLayoutY (), 0.0f );
330+ assertEquals (50f , root_child3 .getLayoutWidth (), 0.0f );
331+ assertEquals (50f , root_child3 .getLayoutHeight (), 0.0f );
332+
299333 root .setDirection (YogaDirection .RTL );
300334 root .calculateLayout (YogaConstants .UNDEFINED , YogaConstants .UNDEFINED );
301335
@@ -313,6 +347,16 @@ public void test_absolute_layout_within_border() {
313347 assertEquals (40f , root_child1 .getLayoutY (), 0.0f );
314348 assertEquals (50f , root_child1 .getLayoutWidth (), 0.0f );
315349 assertEquals (50f , root_child1 .getLayoutHeight (), 0.0f );
350+
351+ assertEquals (20f , root_child2 .getLayoutX (), 0.0f );
352+ assertEquals (20f , root_child2 .getLayoutY (), 0.0f );
353+ assertEquals (50f , root_child2 .getLayoutWidth (), 0.0f );
354+ assertEquals (50f , root_child2 .getLayoutHeight (), 0.0f );
355+
356+ assertEquals (30f , root_child3 .getLayoutX (), 0.0f );
357+ assertEquals (30f , root_child3 .getLayoutY (), 0.0f );
358+ assertEquals (50f , root_child3 .getLayoutWidth (), 0.0f );
359+ assertEquals (50f , root_child3 .getLayoutHeight (), 0.0f );
316360 }
317361
318362 @ Test
@@ -728,4 +772,79 @@ public void test_position_root_with_rtl_should_position_withoutdirection() {
728772 assertEquals (52f , root .getLayoutHeight (), 0.0f );
729773 }
730774
775+ @ Test
776+ public void test_absolute_layout_percentage_bottom_based_on_parent_height () {
777+ YogaConfig config = new YogaConfig ();
778+
779+ final YogaNode root = new YogaNode (config );
780+ root .setWidth (100f );
781+ root .setHeight (200f );
782+
783+ final YogaNode root_child0 = new YogaNode (config );
784+ root_child0 .setPositionType (YogaPositionType .ABSOLUTE );
785+ root_child0 .setPositionPercent (YogaEdge .TOP , 50f );
786+ root_child0 .setWidth (10f );
787+ root_child0 .setHeight (10f );
788+ root .addChildAt (root_child0 , 0 );
789+
790+ final YogaNode root_child1 = new YogaNode (config );
791+ root_child1 .setPositionType (YogaPositionType .ABSOLUTE );
792+ root_child1 .setPositionPercent (YogaEdge .BOTTOM , 50f );
793+ root_child1 .setWidth (10f );
794+ root_child1 .setHeight (10f );
795+ root .addChildAt (root_child1 , 1 );
796+
797+ final YogaNode root_child2 = new YogaNode (config );
798+ root_child2 .setPositionType (YogaPositionType .ABSOLUTE );
799+ root_child2 .setPositionPercent (YogaEdge .TOP , 10f );
800+ root_child2 .setPositionPercent (YogaEdge .BOTTOM , 10f );
801+ root_child2 .setWidth (10f );
802+ root .addChildAt (root_child2 , 2 );
803+ root .setDirection (YogaDirection .LTR );
804+ root .calculateLayout (YogaConstants .UNDEFINED , YogaConstants .UNDEFINED );
805+
806+ assertEquals (0f , root .getLayoutX (), 0.0f );
807+ assertEquals (0f , root .getLayoutY (), 0.0f );
808+ assertEquals (100f , root .getLayoutWidth (), 0.0f );
809+ assertEquals (200f , root .getLayoutHeight (), 0.0f );
810+
811+ assertEquals (0f , root_child0 .getLayoutX (), 0.0f );
812+ assertEquals (100f , root_child0 .getLayoutY (), 0.0f );
813+ assertEquals (10f , root_child0 .getLayoutWidth (), 0.0f );
814+ assertEquals (10f , root_child0 .getLayoutHeight (), 0.0f );
815+
816+ assertEquals (0f , root_child1 .getLayoutX (), 0.0f );
817+ assertEquals (90f , root_child1 .getLayoutY (), 0.0f );
818+ assertEquals (10f , root_child1 .getLayoutWidth (), 0.0f );
819+ assertEquals (10f , root_child1 .getLayoutHeight (), 0.0f );
820+
821+ assertEquals (0f , root_child2 .getLayoutX (), 0.0f );
822+ assertEquals (20f , root_child2 .getLayoutY (), 0.0f );
823+ assertEquals (10f , root_child2 .getLayoutWidth (), 0.0f );
824+ assertEquals (160f , root_child2 .getLayoutHeight (), 0.0f );
825+
826+ root .setDirection (YogaDirection .RTL );
827+ root .calculateLayout (YogaConstants .UNDEFINED , YogaConstants .UNDEFINED );
828+
829+ assertEquals (0f , root .getLayoutX (), 0.0f );
830+ assertEquals (0f , root .getLayoutY (), 0.0f );
831+ assertEquals (100f , root .getLayoutWidth (), 0.0f );
832+ assertEquals (200f , root .getLayoutHeight (), 0.0f );
833+
834+ assertEquals (90f , root_child0 .getLayoutX (), 0.0f );
835+ assertEquals (100f , root_child0 .getLayoutY (), 0.0f );
836+ assertEquals (10f , root_child0 .getLayoutWidth (), 0.0f );
837+ assertEquals (10f , root_child0 .getLayoutHeight (), 0.0f );
838+
839+ assertEquals (90f , root_child1 .getLayoutX (), 0.0f );
840+ assertEquals (90f , root_child1 .getLayoutY (), 0.0f );
841+ assertEquals (10f , root_child1 .getLayoutWidth (), 0.0f );
842+ assertEquals (10f , root_child1 .getLayoutHeight (), 0.0f );
843+
844+ assertEquals (90f , root_child2 .getLayoutX (), 0.0f );
845+ assertEquals (20f , root_child2 .getLayoutY (), 0.0f );
846+ assertEquals (10f , root_child2 .getLayoutWidth (), 0.0f );
847+ assertEquals (160f , root_child2 .getLayoutHeight (), 0.0f );
848+ }
849+
731850}
0 commit comments