From e48da2aff33b5d7831e0946b6e492b849de43344 Mon Sep 17 00:00:00 2001 From: Joe Vilches Date: Mon, 4 Dec 2023 19:35:30 -0800 Subject: [PATCH] Insets no longer apply to statically positioned nodes (#41369) Summary: X-link: https://github.com/facebook/yoga/pull/1454 Pull Request resolved: https://github.com/facebook/react-native/pull/41369 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 fbshipit-source-id: 7aab4138b06e60936db0ddb6019a9a30f1ded2db --- .../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 faf812e8cf1..63639aafd01 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);