Skip to content

Commit 228a081

Browse files
Joe Vilchesfacebook-github-bot
authored andcommitted
Allow the containing block to set trailing position of absolute descendants (facebook#41489)
Summary: X-link: facebook/yoga#1471 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
1 parent 9da279f commit 228a081

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ static void setChildTrailingPosition(
9393
flexEndEdge(axis));
9494
}
9595

96+
static bool needsTrailingPosition(const FlexDirection axis) {
97+
return axis == FlexDirection::RowReverse ||
98+
axis == FlexDirection::ColumnReverse;
99+
}
100+
96101
static void constrainMaxSizeForMode(
97102
const yoga::Node* const node,
98103
const enum FlexDirection axis,
@@ -554,6 +559,17 @@ static void layoutAbsoluteDescendants(
554559
layoutMarkerData,
555560
currentDepth,
556561
generationCount);
562+
563+
const FlexDirection mainAxis = resolveDirection(
564+
currentNode->getStyle().flexDirection(), currentNodeDirection);
565+
const FlexDirection crossAxis =
566+
resolveCrossDirection(mainAxis, currentNodeDirection);
567+
if (needsTrailingPosition(mainAxis)) {
568+
setChildTrailingPosition(currentNode, child, mainAxis);
569+
}
570+
if (needsTrailingPosition(crossAxis)) {
571+
setChildTrailingPosition(currentNode, child, crossAxis);
572+
}
557573
} else if (child->getStyle().positionType() == PositionType::Static) {
558574
const Direction childDirection =
559575
child->resolveDirection(currentNodeDirection);
@@ -2386,16 +2402,18 @@ static void calculateLayoutImpl(
23862402
}
23872403

23882404
// STEP 11: SETTING TRAILING POSITIONS FOR CHILDREN
2389-
const bool needsMainTrailingPos = mainAxis == FlexDirection::RowReverse ||
2390-
mainAxis == FlexDirection::ColumnReverse;
2391-
const bool needsCrossTrailingPos = crossAxis == FlexDirection::RowReverse ||
2392-
crossAxis == FlexDirection::ColumnReverse;
2405+
const bool needsMainTrailingPos = needsTrailingPosition(mainAxis);
2406+
const bool needsCrossTrailingPos = needsTrailingPosition(crossAxis);
23932407

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

0 commit comments

Comments
 (0)