From f7fe9a62197c0205ddbee62b515e062ac89482cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20W=C3=B6hrl?= Date: Tue, 11 Apr 2017 13:00:02 -0700 Subject: [PATCH] Fix position on root node with RTL direction Summary: If the root node has a position and we have a RTL layout, that position must be like LTR direction. See #477. Closes https://github.com/facebook/yoga/pull/502 Differential Revision: D4867144 Pulled By: emilsjolander fbshipit-source-id: b5ad3d87e7054090da12d7665a3d1abe8496a548 --- ReactCommon/yoga/yoga/Yoga.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ReactCommon/yoga/yoga/Yoga.c b/ReactCommon/yoga/yoga/Yoga.c index 6a550206af8587..10bd80e4447d03 100644 --- a/ReactCommon/yoga/yoga/Yoga.c +++ b/ReactCommon/yoga/yoga/Yoga.c @@ -1324,8 +1324,12 @@ static void YGNodeSetPosition(const YGNodeRef node, const float mainSize, const float crossSize, const float parentWidth) { - const YGFlexDirection mainAxis = YGResolveFlexDirection(node->style.flexDirection, direction); - const YGFlexDirection crossAxis = YGFlexDirectionCross(mainAxis, direction); + /* Root nodes should be always layouted as LTR, so we don't return negative values. */ + const YGDirection directionRespectingRoot = node->parent != NULL ? direction : YGDirectionLTR; + const YGFlexDirection mainAxis = + YGResolveFlexDirection(node->style.flexDirection, directionRespectingRoot); + const YGFlexDirection crossAxis = YGFlexDirectionCross(mainAxis, directionRespectingRoot); + const float relativePositionMain = YGNodeRelativePosition(node, mainAxis, mainSize); const float relativePositionCross = YGNodeRelativePosition(node, crossAxis, crossSize);