| 1487 | _parent.reset(); |
| 1488 | setHasParent(false); |
| 1489 | } |
| 1490 | |
| 1491 | void ViewNode::appendChild(ViewTransactionScope& viewTransactionScope, const Ref<ViewNode>& child) { |
| 1492 | insertChildAt(viewTransactionScope, child, getChildCount()); |
| 1493 | } |
| 1494 | |
| 1495 | void 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(); |