Skip to content

Commit

Permalink
Allow the containing block to set trailing position of absolute desce…
Browse files Browse the repository at this point in the history
…ndants (#1471)

Summary:
X-link: facebook/react-native#41489


If we are going to allow the containing block to layout its absolute descendants and NOT the direct parent then we need to change step 11 which is concerned with setting the trailing position in the case we are row or column reverse. This is the very last step in the function and is positioned that way because it operates on the assumption that all children have their position set by this time. That is no longer a valid assumption if CBs layout their absolute children. In that case the CB also needs to take care of setting the position here.

Because of this problem I moved some things around. It now works like:

* If errata is set, the direct parent will set trailing position for all non absolute children in step 11
* If errata is set the CB will set trailing position of absolute descendants after they are laid out inside of layoutAbsoluteDescendants

Reviewed By: NickGerleman

Differential Revision: D51217291
  • Loading branch information
Joe Vilches authored and facebook-github-bot committed Dec 4, 2023
1 parent b047db4 commit 55324d0
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions yoga/algorithm/CalculateLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ static void setChildTrailingPosition(
flexEndEdge(axis));
}

static bool needsTrailingPosition(const FlexDirection axis) {
return axis == FlexDirection::RowReverse ||
axis == FlexDirection::ColumnReverse;
}

static void constrainMaxSizeForMode(
const yoga::Node* const node,
const enum FlexDirection axis,
Expand Down Expand Up @@ -554,6 +559,17 @@ static void layoutAbsoluteDescendants(
layoutMarkerData,
currentDepth,
generationCount);

const FlexDirection mainAxis = resolveDirection(
currentNode->getStyle().flexDirection(), currentNodeDirection);
const FlexDirection crossAxis =
resolveCrossDirection(mainAxis, currentNodeDirection);
if (needsTrailingPosition(mainAxis)) {
setChildTrailingPosition(currentNode, child, mainAxis);
}
if (needsTrailingPosition(crossAxis)) {
setChildTrailingPosition(currentNode, child, crossAxis);
}
} else if (child->getStyle().positionType() == PositionType::Static) {
const Direction childDirection =
child->resolveDirection(currentNodeDirection);
Expand Down Expand Up @@ -2386,16 +2402,18 @@ static void calculateLayoutImpl(
}

// STEP 11: SETTING TRAILING POSITIONS FOR CHILDREN
const bool needsMainTrailingPos = mainAxis == FlexDirection::RowReverse ||
mainAxis == FlexDirection::ColumnReverse;
const bool needsCrossTrailingPos = crossAxis == FlexDirection::RowReverse ||
crossAxis == FlexDirection::ColumnReverse;
const bool needsMainTrailingPos = needsTrailingPosition(mainAxis);
const bool needsCrossTrailingPos = needsTrailingPosition(crossAxis);

// Set trailing position if necessary.
if (needsMainTrailingPos || needsCrossTrailingPos) {
for (size_t i = 0; i < childCount; i++) {
const auto child = node->getChild(i);
if (child->getStyle().display() == Display::None) {
// Absolute children will be handled by their containing block since we
// cannot guarantee that their positions are set when their parents are
// done with layout.
if (child->getStyle().display() == Display::None ||
(!node->hasErrata(Errata::PositionStaticBehavesLikeRelative) &&
child->getStyle().positionType() == PositionType::Absolute)) {
continue;
}
if (needsMainTrailingPos) {
Expand Down

0 comments on commit 55324d0

Please sign in to comment.