From 3624aa447bc66c73d497219162c039e820285f4c Mon Sep 17 00:00:00 2001 From: ilikethese Date: Thu, 7 Sep 2023 17:16:13 +0800 Subject: [PATCH] feat(dom): fix trigger error on layout event --- dom/src/dom/dom_node.cc | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/dom/src/dom/dom_node.cc b/dom/src/dom/dom_node.cc index 777e4d48a91..9db95d2d6f1 100644 --- a/dom/src/dom/dom_node.cc +++ b/dom/src/dom/dom_node.cc @@ -322,6 +322,7 @@ LayoutResult DomNode::GetLayoutInfoFromRoot() { void DomNode::TransferLayoutOutputsRecursive(std::vector>& changed_nodes) { auto not_equal = std::not_equal_to<>(); bool changed = layout_node_->IsDirty() || layout_node_->HasNewLayout(); + bool has_new_layout = layout_node_->HasNewLayout(); layout_.left = layout_node_->GetLeft(); layout_.top = layout_node_->GetTop(); @@ -364,19 +365,19 @@ void DomNode::TransferLayoutOutputsRecursive(std::vector(kLayoutEvent, - weak_from_this(), - std::make_shared(std::move(layout_obj))); - auto root = root_node_.lock(); - if (root != nullptr) { - auto manager = root->GetDomManager().lock(); - if (manager != nullptr) { - std::vector> ops = {[WEAK_THIS, event] { - DEFINE_AND_CHECK_SELF(DomNode) - self->HandleEvent(event); - }}; - manager->PostTask(Scene(std::move(ops))); + if (has_new_layout) { + auto event = std::make_shared(kLayoutEvent, weak_from_this(), + std::make_shared(std::move(layout_obj))); + auto root = root_node_.lock(); + if (root != nullptr) { + auto manager = root->GetDomManager().lock(); + if (manager != nullptr) { + std::vector> ops = {[WEAK_THIS, event] { + DEFINE_AND_CHECK_SELF(DomNode) + self->HandleEvent(event); + }}; + manager->PostTask(Scene(std::move(ops))); + } } } }