Skip to content

Commit

Permalink
feat(dom): fix layout add node crash
Browse files Browse the repository at this point in the history
  • Loading branch information
luicolong authored and churchill-zhang committed Dec 17, 2021
1 parent d25dc71 commit 379679c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 13 deletions.
4 changes: 3 additions & 1 deletion dom/src/dom/dom_node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,21 @@ std::shared_ptr<DomNode> DomNode::GetChildAt(int32_t index) {

void DomNode::AddChildAt(const std::shared_ptr<DomNode>& dom_node, int32_t index) {
auto it = children_.begin();
auto insertIndex = 0;
while (it != children_.end()) {
if (index < it->get()->GetIndex()) {
break;
}
it++;
insertIndex++;
}
if (it == children_.end()) {
children_.push_back(dom_node);
} else {
children_.insert(it, dom_node);
}
dom_node->SetParent(shared_from_this());
layout_node_->InsertChild(dom_node->layout_node_, index);
layout_node_->InsertChild(dom_node->layout_node_, insertIndex);
}

std::shared_ptr<DomNode> DomNode::RemoveChildAt(int32_t index) {
Expand Down
7 changes: 1 addition & 6 deletions dom/src/dom/taitank_layout_node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -327,12 +327,7 @@ void TaitankLayoutNode::InsertChild(std::shared_ptr<LayoutNode> child, uint32_t
auto node = std::static_pointer_cast<TaitankLayoutNode>(child);
assert(node->GetLayoutEngineNodeRef() != nullptr);
engine_node_->insertChild(node->GetLayoutEngineNodeRef(), index);
auto size = children_.size();
if (index >= size) {
children_.push_back(node);
} else {
children_.insert(children_.begin() + index, node);
}
children_.insert(children_.begin() + index, node);
node->parent_ = shared_from_this();
}

Expand Down
7 changes: 1 addition & 6 deletions layout/engine/HPNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,7 @@ bool HPNode::insertChild(HPNodeRef item, uint32_t index) {
return false;
}
item->setParent(this);
auto size = children.size();
if (index >= size) {
children.push_back(item);
} else {
children.insert(children.begin() + index, item);
}
children.insert(children.begin() + index, item);
markAsDirty();
return true;
}
Expand Down

0 comments on commit 379679c

Please sign in to comment.