Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,8 @@ bool layoutAbsoluteDescendants(
containingNodeAvailableInnerHeight) ||
hasNewLayout;

cleanupContentsNodesRecursively(
child, /* didPerformLayout */ hasNewLayout);
if (hasNewLayout) {
child->setHasNewLayout(hasNewLayout);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,19 +480,23 @@ static void zeroOutLayoutRecursively(yoga::Node* const node) {
}
}

static void cleanupContentsNodesRecursively(yoga::Node* const node) {
void cleanupContentsNodesRecursively(
yoga::Node* const node,
bool didPerformLayout) {
if (node->hasContentsChildren()) [[unlikely]] {
node->cloneContentsChildrenIfNeeded();
for (auto child : node->getChildren()) {
if (child->style().display() == Display::Contents) {
child->getLayout() = {};
child->setLayoutDimension(0, Dimension::Width);
child->setLayoutDimension(0, Dimension::Height);
child->setHasNewLayout(true);
if (didPerformLayout) {
child->setHasNewLayout(true);
}
child->setDirty(false);
child->cloneChildrenIfNeeded();

cleanupContentsNodesRecursively(child);
cleanupContentsNodesRecursively(child, didPerformLayout);
}
}
}
Expand Down Expand Up @@ -1317,7 +1321,7 @@ static void calculateLayoutImpl(

// Clean and update all display: contents nodes with a direct path to the
// current node as they will not be traversed
cleanupContentsNodesRecursively(node);
cleanupContentsNodesRecursively(node, performLayout);
return;
}

Expand All @@ -1335,7 +1339,7 @@ static void calculateLayoutImpl(

// Clean and update all display: contents nodes with a direct path to the
// current node as they will not be traversed
cleanupContentsNodesRecursively(node);
cleanupContentsNodesRecursively(node, performLayout);
return;
}

Expand All @@ -1353,7 +1357,7 @@ static void calculateLayoutImpl(
ownerHeight)) {
// Clean and update all display: contents nodes with a direct path to the
// current node as they will not be traversed
cleanupContentsNodesRecursively(node);
cleanupContentsNodesRecursively(node, /* didPerformLayout */ false);
return;
}

Expand All @@ -1365,7 +1369,7 @@ static void calculateLayoutImpl(

// Clean and update all display: contents nodes with a direct path to the
// current node as they will not be traversed
cleanupContentsNodesRecursively(node);
cleanupContentsNodesRecursively(node, performLayout);

// STEP 1: CALCULATE VALUES FOR REMAINDER OF ALGORITHM
const FlexDirection mainAxis =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ bool calculateLayoutInternal(
uint32_t depth,
uint32_t generationCount);

void cleanupContentsNodesRecursively(yoga::Node* node, bool didPerformLayout);

} // namespace facebook::yoga
7 changes: 6 additions & 1 deletion packages/react-native/ReactCommon/yoga/yoga/node/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,12 @@ void Node::cloneChildrenIfNeeded() {
child = resolveRef(config_->cloneNode(child, this, i));
child->setOwner(this);

if (child->hasContentsChildren()) [[unlikely]] {
if (child->style().display() == Display::Contents) [[unlikely]] {
// The contents node's children are treated as children of the
// contents node's parent for layout purposes, so they need
// to be cloned as well.
child->cloneChildrenIfNeeded();
} else if (child->hasContentsChildren()) [[unlikely]] {
child->cloneContentsChildrenIfNeeded();
}
}
Expand Down
Loading