From 1bcb924c047acda8d68b9b1df4f226ec202d1acc Mon Sep 17 00:00:00 2001 From: Joe Vilches Date: Mon, 4 Dec 2023 13:50:09 -0800 Subject: [PATCH] Insets no longer apply to statically positioned nodes (#41369) Summary: X-link: https://github.com/facebook/yoga/pull/1454 One of the most basic aspects of statically positioned nodes is that [insets do not apply to them](https://developer.mozilla.org/en-US/docs/Web/CSS/position#static). So I put a guard inside `Node::relativePosition` where we take that into account when setting the position. Reviewed By: NickGerleman Differential Revision: D50507808 --- .../react-native/ReactCommon/yoga/yoga/node/Node.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/react-native/ReactCommon/yoga/yoga/node/Node.cpp b/packages/react-native/ReactCommon/yoga/yoga/node/Node.cpp index faf812e8cf1949..63639aafd01bd2 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/node/Node.cpp +++ b/packages/react-native/ReactCommon/yoga/yoga/node/Node.cpp @@ -488,11 +488,16 @@ void Node::setLayoutDimension(float LengthValue, Dimension dimension) { } // If both left and right are defined, then use left. Otherwise return +left or -// -right depending on which is defined. +// -right depending on which is defined. Ignore statically positioned nodes as +// insets do not apply to them. float Node::relativePosition( FlexDirection axis, Direction direction, float axisSize) const { + if (style_.positionType() == PositionType::Static && + !hasErrata(Errata::PositionStaticBehavesLikeRelative)) { + return 0; + } if (isInlineStartPositionDefined(axis, direction)) { return getInlineStartPosition(axis, direction, axisSize); } @@ -514,8 +519,7 @@ void Node::setPosition( const FlexDirection crossAxis = yoga::resolveCrossDirection(mainAxis, directionRespectingRoot); - // Here we should check for `PositionType::Static` and in this case zero inset - // properties (left, right, top, bottom, begin, end). + // In the case of position static these are just 0. See: // https://www.w3.org/TR/css-position-3/#valdef-position-static const float relativePositionMain = relativePosition(mainAxis, directionRespectingRoot, mainSize);