MCPcopy Create free account
hub / github.com/Snapchat/Valdi / insertChildAt

Method insertChildAt

valdi/src/valdi/runtime/Context/ViewNode.cpp:1489–1536  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1487 _parent.reset();
1488 setHasParent(false);
1489}
1490
1491void ViewNode::appendChild(ViewTransactionScope& viewTransactionScope, const Ref<ViewNode>& child) {
1492 insertChildAt(viewTransactionScope, child, getChildCount());
1493}
1494
1495void ViewNode::insertChildAt(ViewTransactionScope& viewTransactionScope, const Ref<ViewNode>& child, size_t index) {
1496 SC_ASSERT(child.get() != this);
1497
1498 [[maybe_unused]] auto childHadParent = child->hasParent();
1499 child->removeFromParent(viewTransactionScope);
1500 child->_parent = weakRef(this);
1501 child->setHasParent(true);
1502
1503 auto* yogaContainer = getYogaNodeForInsertingChildren();
1504 auto* yogaContainerNode = resolveYogaNode(yogaContainer);
1505 if (yogaContainerNode->getChildCount() < index) {
1506 VALDI_ERROR(getLogger(),
1507 "Cannot insert child at index {} into container with size {} (child had parent: {})",
1508 index,
1509 yogaContainerNode->getChildCount(),
1510 childHadParent);
1511 VALDI_ERROR(getLogger(), "Root component path: {}", getViewNodeTree()->getContext()->getPath().toString());
1512 VALDI_ERROR(getLogger(), "Parent XML: {}", toXML());
1513 VALDI_ERROR(getLogger(), "Child XML: {}", child->toXML());
1514 SC_ASSERT_FAIL("Out of bounds insertion");
1515 return;
1516 }
1517
1518 yogaContainerNode->setMeasureFunc(nullptr);
1519 YGNodeInsertChild(yogaContainer, child->_yogaNode, index);
1520
1521 child->getCSSAttributesManager().setParent(&getCSSAttributesManager());
1522
1523 if (child->getCSSAttributesManager().needUpdateCSS()) {
1524 child->setCSSNeedsUpdate();
1525 }
1526 if (child->cssNeedsUpdate()) {
1527 setCSSHasChildNeedsUpdate();
1528 }
1529 if (child->getZIndex() != 0) {
1530 setHasChildWithZIndex();
1531 }
1532 if (child->hasAccessibilityId() || child->isUserSpecifiedView()) {
1533 setHasChildWithAccessibilityId();
1534 }
1535 if (getChildCount() > kMaxChildrenBeforeIndexing && _childrenIndexer == nullptr) {
1536 _childrenIndexer = std::make_unique<ViewNodeChildrenIndexer>(this);
1537 }
1538
1539 setCalculatedViewportHasChildNeedsUpdate();

Callers 2

TESTFunction · 0.80
visitMethod · 0.80

Calls 15

weakRefFunction · 0.85
resolveYogaNodeFunction · 0.85
getViewNodeTreeFunction · 0.85
toXMLFunction · 0.85
YGNodeInsertChildFunction · 0.85
getChildCountFunction · 0.85
setHasParentMethod · 0.80
setMeasureFuncMethod · 0.80
needUpdateCSSMethod · 0.80
setCSSNeedsUpdateMethod · 0.80
cssNeedsUpdateMethod · 0.80
getZIndexMethod · 0.80

Tested by 1

TESTFunction · 0.64