mirror of
https://github.com/Tencent/Hippy.git
synced 2026-10-29 06:06:52 +08:00
fix(dom): delay add listener operation
This commit is contained in:
committed by
churchill-zhang
parent
a7da8ecba5
commit
21cd694f45
@@ -46,7 +46,7 @@ class DomManager {
|
||||
void RemoveEventListener(uint32_t id, const std::string &name, bool use_capture);
|
||||
void CallFunction(uint32_t id, const std::string &name,
|
||||
const DomValue ¶m, const CallFunctionCallback &cb);
|
||||
|
||||
void AddListenerOperation(std::shared_ptr<DomNode> node, const std::string& name);
|
||||
std::tuple<float, float> GetRootSize();
|
||||
void SetRootSize(float width, float height);
|
||||
void AddLayoutChangedNode(const std::shared_ptr<DomNode> &node);
|
||||
@@ -72,6 +72,7 @@ class DomManager {
|
||||
|
||||
using DomOperation = std::function<void(void)>;
|
||||
std::vector<DomOperation> batched_operations_;
|
||||
std::vector<DomOperation> add_listener_operations_;
|
||||
std::vector<std::shared_ptr<DomNode>> layout_changed_nodes_;
|
||||
};
|
||||
|
||||
|
||||
@@ -105,6 +105,11 @@ void DomManager::EndBatch() {
|
||||
for (auto& batch_operation : batched_operations_) {
|
||||
batch_operation();
|
||||
}
|
||||
batched_operations_.clear();
|
||||
for (auto& batch_operation : add_listener_operations_) {
|
||||
batch_operation();
|
||||
}
|
||||
add_listener_operations_.clear();
|
||||
layout_changed_nodes_.clear();
|
||||
// 触发布局计算
|
||||
root_node_->DoLayout();
|
||||
@@ -144,6 +149,13 @@ void DomManager::CallFunction(uint32_t id, const std::string &name,
|
||||
node->CallFunction(name, param, cb);
|
||||
}
|
||||
|
||||
void DomManager::AddListenerOperation(std::shared_ptr<DomNode> node, const std::string& name) {
|
||||
add_listener_operations_.emplace_back([this, node, name]() {
|
||||
TDF_BASE_DCHECK(render_manager_);
|
||||
render_manager_->AddEventListener(node, name);
|
||||
});
|
||||
}
|
||||
|
||||
std::tuple<float, float> DomManager::GetRootSize() {
|
||||
TDF_BASE_DCHECK(root_node_);
|
||||
return root_node_->GetLayoutSize();
|
||||
|
||||
@@ -116,9 +116,7 @@ uint32_t DomNode::AddEventListener(const std::string &name, bool use_capture,
|
||||
auto dom_manager = dom_manager_.lock();
|
||||
TDF_BASE_DCHECK(dom_manager);
|
||||
if (dom_manager) {
|
||||
auto render_manager = dom_manager->GetRenderManager();
|
||||
TDF_BASE_DCHECK(render_manager);
|
||||
render_manager->AddEventListener(shared_from_this(), name);
|
||||
dom_manager->AddListenerOperation(shared_from_this(), name);
|
||||
}
|
||||
}
|
||||
if (use_capture) {
|
||||
|
||||
Reference in New Issue
Block a user