Skip to content

Commit

Permalink
Clean up random absolute position setting during alignment (facebook#…
Browse files Browse the repository at this point in the history
…46984)

Summary:

X-link: facebook/yoga#1725

The legacy (wrong) absolute positioning path positions in two places, including work that is definitely always overwritten in the new absolute layout path.

This came up before for position: static, but we didn't clean this up at the time. This code is also now leading display: contents impl being more annoying.

Let's move everything in the legacy path to the same place at least, so earlier code can just deal with items in flow (as their steps should be doing), and we can reason about this code not doing anything for the modern (much less strange, and more correct).

This behavior 

Changelog: [Internal]

Reviewed By: joevilches

Differential Revision: D64244949
  • Loading branch information
NickGerleman authored and facebook-github-bot committed Oct 15, 2024
1 parent 40bcf0e commit f302779
Show file tree
Hide file tree
Showing 2 changed files with 196 additions and 233 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,39 @@ static void positionAbsoluteChildLegacy(
: ((resolveChildAlignment(parent, child) == Align::FlexEnd) ^
(parent->style().flexWrap() == Wrap::WrapReverse));

// If the child is absolutely positioned and has a
// top/left/bottom/right set, override all the previously computed
// positions to set it correctly.
const bool isChildLeadingPosDefined =
child->style().isFlexStartPositionDefined(axis, direction) &&
!child->style().isFlexStartPositionAuto(axis, direction);
if (isChildLeadingPosDefined) {
child->setLayoutPosition(
child->style().computeFlexStartPosition(
axis,
direction,
isAxisRow ? containingBlockWidth : containingBlockHeight) +
containingNode->style().computeFlexStartBorder(axis, direction) +
child->style().computeFlexStartMargin(
axis,
direction,
isAxisRow ? containingBlockWidth : containingBlockHeight),
flexStartEdge(axis));
}

// If leading position is not defined or calculations result in Nan,
// default to border + margin
if (!isChildLeadingPosDefined ||
yoga::isUndefined(child->getLayout().position(flexStartEdge(axis)))) {
child->setLayoutPosition(
containingNode->style().computeFlexStartBorder(axis, direction) +
child->style().computeFlexStartMargin(
axis,
direction,
isAxisRow ? containingBlockWidth : containingBlockHeight),
flexStartEdge(axis));
}

if (child->style().isFlexEndPositionDefined(axis, direction) &&
(!child->style().isFlexStartPositionDefined(axis, direction) ||
child->style().isFlexStartPositionAuto(axis, direction))) {
Expand Down
Loading

0 comments on commit f302779

Please sign in to comment.