From a2a84532ffb0ba759269f7bf331ec7e5e8b38a27 Mon Sep 17 00:00:00 2001 From: Emil Sjolander Date: Tue, 24 Jan 2017 17:04:54 -0800 Subject: [PATCH] Dont constrain absolute children to zero sized parents Summary: Absolute children should not be constraint to the size of their parent if the parent does not have a size as this was causes the layout of the child to be skipped. Reviewed By: gkassabli Differential Revision: D4453612 fbshipit-source-id: e8269521560d2f42b2d6f0f0ff264a1605a57d79 --- tests/YGMeasureTest.cpp | 21 +++++++++++++++++++++ yoga/Yoga.c | 9 ++++----- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/tests/YGMeasureTest.cpp b/tests/YGMeasureTest.cpp index 911f0c51..1e4ad175 100644 --- a/tests/YGMeasureTest.cpp +++ b/tests/YGMeasureTest.cpp @@ -47,6 +47,27 @@ TEST(YogaTest, dont_measure_single_grow_shrink_child) { YGNodeFreeRecursive(root); } +TEST(YogaTest, measure_absolute_child_with_no_constraints) { + const YGNodeRef root = YGNodeNew(); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeInsertChild(root, root_child0, 0); + + int measureCount = 0; + + const YGNodeRef root_child0_child0 = YGNodeNew(); + YGNodeStyleSetPositionType(root_child0_child0, YGPositionTypeAbsolute); + YGNodeSetContext(root_child0_child0, &measureCount); + YGNodeSetMeasureFunc(root_child0_child0, _measure); + YGNodeInsertChild(root_child0, root_child0_child0, 0); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_EQ(1, measureCount); + + YGNodeFreeRecursive(root); +} + #if GTEST_HAS_DEATH_TEST TEST(YogaTest, cannot_add_child_to_node_with_measure_func) { const YGNodeRef root = YGNodeNew(); diff --git a/yoga/Yoga.c b/yoga/Yoga.c index 4ebafec6..51a9287c 100644 --- a/yoga/Yoga.c +++ b/yoga/Yoga.c @@ -1431,11 +1431,10 @@ static void YGNodeAbsoluteLayoutChild(const YGNodeRef node, childHeightMeasureMode = YGFloatIsUndefined(childHeight) ? YGMeasureModeUndefined : YGMeasureModeExactly; - // According to the spec, if the main size is not definite and the - // child's inline axis is parallel to the main axis (i.e. it's - // horizontal), the child should be sized using "UNDEFINED" in - // the main size. Otherwise use "AT_MOST" in the cross axis. - if (!isMainAxisRow && YGFloatIsUndefined(childWidth) && widthMode != YGMeasureModeUndefined) { + // If the size of the parent is defined then try to constrain the absolute child to that size + // as well. This allows text within the absolute child to wrap to the size of its parent. + // This is the same behavior as many browsers implement. + if (!isMainAxisRow && YGFloatIsUndefined(childWidth) && widthMode != YGMeasureModeUndefined && width > 0) { childWidth = width; childWidthMeasureMode = YGMeasureModeAtMost; }