Open pklatka opened 1 month ago
For the relatively positioned element this seems to be the culprit
// If both left and right are defined, then use left. Otherwise return +left or
// -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) {
return 0;
}
if (style_.isInlineStartPositionDefined(axis, direction)) {
return style_.computeInlineStartPosition(axis, direction, axisSize);
}
return -1 * style_.computeInlineEndPosition(axis, direction, axisSize);
}
The right
style is ignored if left
is specified.
To add to the above, Node::relativePosition
will be called for both views - the one positioned relatively and the one positioned absolutely.
The difference between the old and the new architecture comes from auto
being treaded differently by them. On the old architecture when auto
is passed to left
or right
, it will be set to YGUndefined
https://github.com/facebook/react-native/blob/a4cd5994a758b5db8b29d59db332322d626ace80/packages/react-native/React/Views/RCTShadowView.m#L63-L68
On the new architecture auto
is actually converted to an empty StyleLength
with the unit of auto
https://github.com/facebook/react-native/blob/a4cd5994a758b5db8b29d59db332322d626ace80/packages/react-native/ReactCommon/react/renderer/components/view/conversions.h#L422
This causes the above function to change behavior - since the left position is no longer undefined, it enters the if
body and returns 0
there.
Obviously, changing auto to undefined in the above file fixes the issue, though I don't think this is a proper solution for that as it looks like a bug (or a missing feature?) in Yoga. I'd love to hear your opinion on that.
Obviously, changing auto to undefined in the above file fixes the issue, though I don't think this is a proper solution for that as it looks like a bug (or a missing feature?) in Yoga. I'd love to hear your opinion on that.
CC @NickGerleman here
Yes, the right fix for this is in Yoga. Really, Yoga's concept of auto
vs undefined
is pretty silly/at odds with how CSS values processing works (where an unset value becomes auto by default). In the meantime, teaching the checks in Yoga absolute layout to handle auto
instead of just undefined
would be the right way to fix this, and probably relatively straightforward (Yoga also has a lot of unit tests, easily runnable from OSS!).
teaching the checks in Yoga absolute layout to handle
auto
instead of justundefined
would be the right way to fix this, and probably relatively straightforward (Yoga also has a lot of unit tests, easily runnable from OSS!).
@j-piasecki @coado is this something you could take on?
@cortinico Yeah, I think we can take this one
Description
Setting
left: auto
andright
to a certain value has no effect on a new architecture. On the old architecture, a container withposition: absolute/relative
would change its position according to the web rules.Steps to reproduce
npm run ios
ornpm run android
React Native Version
0.74.3
Affected Platforms
Runtime - Android, Runtime - iOS
Areas
Fabric - The New Renderer
Output of
npx react-native info
Stacktrace or Logs
Reproducer
https://github.com/pklatka/css-left-repro
Screenshots and Videos