From 7d9c900c6910bb81697065401381078435e9af3a Mon Sep 17 00:00:00 2001 From: openharmony_ci <120357966@qq.com> Date: Wed, 15 Nov 2023 15:46:54 +0000 Subject: [PATCH] !21752 fix_delay_js_active --- .../pattern/custom/custom_node.cpp | 23 ++++--------------- .../pattern/custom/custom_node.h | 12 +++++++++- .../core/pipeline_ng/pipeline_context.cpp | 5 ++++ .../core/pipeline_ng/pipeline_context.h | 2 ++ .../test/mock/mock_pipeline_base.cpp | 2 ++ .../core/pipeline_ng/ui_task_scheduler.cpp | 21 ++++++++++++++++- .../core/pipeline_ng/ui_task_scheduler.h | 5 ++++ 7 files changed, 49 insertions(+), 21 deletions(-) diff --git a/frameworks/core/components_ng/pattern/custom/custom_node.cpp b/frameworks/core/components_ng/pattern/custom/custom_node.cpp index 38f5bc1000f..fac1ac1f90f 100644 --- a/frameworks/core/components_ng/pattern/custom/custom_node.cpp +++ b/frameworks/core/components_ng/pattern/custom/custom_node.cpp @@ -25,8 +25,6 @@ #include "core/pipeline_ng/ui_task_scheduler.h" namespace OHOS::Ace::NG { -std::unordered_map, bool> > delayJsActiveNodes_; - RefPtr CustomNode::CreateCustomNode(int32_t nodeId, const std::string& viewKey) { auto node = MakeRefPtr(nodeId, viewKey); @@ -81,26 +79,13 @@ void CustomNode::FlushReload() Render(); } -void CustomNode::FlushDelayJsActive() -{ - auto nodes = std::move(delayJsActiveNodes_); - for (auto node : nodes) { - auto customNode = node.second.first.Upgrade(); - if (customNode) { - customNode->FireSetActiveFunc(node.second.second); - } - } -} - void CustomNode::SetJSViewActive(bool active) { - auto iter = delayJsActiveNodes_.begin(); - iter = delayJsActiveNodes_.find(GetId()); - if (iter != delayJsActiveNodes_.end()) { - iter->second.second = active; - } else { - delayJsActiveNodes_.emplace(GetId(), std::make_pair(WeakClaim(this), active)); + auto context = PipelineContext::GetCurrentContext(); + if (!context) { + return; } + context->SetJSViewActive(active, WeakClaim(this)); } void CustomNode::AdjustLayoutWrapperTree(const RefPtr& parent, bool forceMeasure, bool forceLayout) diff --git a/frameworks/core/components_ng/pattern/custom/custom_node.h b/frameworks/core/components_ng/pattern/custom/custom_node.h index b98bd0b6de1..8182f7c9f70 100644 --- a/frameworks/core/components_ng/pattern/custom/custom_node.h +++ b/frameworks/core/components_ng/pattern/custom/custom_node.h @@ -31,7 +31,6 @@ class ACE_EXPORT CustomNode : public UINode, public CustomNodeBase { public: static RefPtr CreateCustomNode(int32_t nodeId, const std::string& viewKey); - static void FlushDelayJsActive(); CustomNode(int32_t nodeId, const std::string& viewKey); ~CustomNode() override = default; @@ -81,11 +80,22 @@ public: RefPtr GetFrameChildByIndex(uint32_t index, bool needBuild) override; void SetJSViewActive(bool active) override; + bool GetJsActive() + { + return prevJsActive_; + } + + void SetJsActive(bool active) + { + prevJsActive_ = active; + } + private: std::string viewKey_; RenderFunction renderFunction_; RenderFunction completeReloadFunc_; bool needMarkParent_ = true; + bool prevJsActive_ = true; }; } // namespace OHOS::Ace::NG diff --git a/frameworks/core/pipeline_ng/pipeline_context.cpp b/frameworks/core/pipeline_ng/pipeline_context.cpp index 4c1701dc112..25c80ac8508 100755 --- a/frameworks/core/pipeline_ng/pipeline_context.cpp +++ b/frameworks/core/pipeline_ng/pipeline_context.cpp @@ -2245,4 +2245,9 @@ void PipelineContext::RemoveIsFocusActiveUpdateEvent(const RefPtr& no isFocusActiveUpdateEvents_.erase(iter); } } + +void PipelineContext::SetJSViewActive(bool active, WeakPtr custom) +{ + taskScheduler_->SetJSViewActive(active, custom); +} } // namespace OHOS::Ace::NG diff --git a/frameworks/core/pipeline_ng/pipeline_context.h b/frameworks/core/pipeline_ng/pipeline_context.h index 1b51c5ae77f..54423d31257 100644 --- a/frameworks/core/pipeline_ng/pipeline_context.h +++ b/frameworks/core/pipeline_ng/pipeline_context.h @@ -412,6 +412,8 @@ public: dragCleanTask_ = std::move(task); } + void SetJSViewActive(bool active, WeakPtr custom); + protected: void StartWindowSizeChangeAnimate(int32_t width, int32_t height, WindowSizeChangeReason type, const std::shared_ptr& rsTransaction = nullptr); diff --git a/frameworks/core/pipeline_ng/test/mock/mock_pipeline_base.cpp b/frameworks/core/pipeline_ng/test/mock/mock_pipeline_base.cpp index 3b18bbd9767..93bbf04803b 100644 --- a/frameworks/core/pipeline_ng/test/mock/mock_pipeline_base.cpp +++ b/frameworks/core/pipeline_ng/test/mock/mock_pipeline_base.cpp @@ -471,6 +471,8 @@ void PipelineBase::SetTextFieldManager(const RefPtr& manager) textFieldManager_ = manager; } +void NG::PipelineContext::SetJSViewActive(bool active, WeakPtr custom) {} + RefPtr NG::PipelineContext::FindNavigationNodeToHandleBack(const RefPtr& node) { return nullptr; diff --git a/frameworks/core/pipeline_ng/ui_task_scheduler.cpp b/frameworks/core/pipeline_ng/ui_task_scheduler.cpp index 7ff6a252978..ca2252da16d 100644 --- a/frameworks/core/pipeline_ng/ui_task_scheduler.cpp +++ b/frameworks/core/pipeline_ng/ui_task_scheduler.cpp @@ -146,9 +146,28 @@ void UITaskScheduler::FlushTask() FlushRenderTask(); } +void UITaskScheduler::SetJSViewActive(bool active, WeakPtr custom) +{ + auto iter = delayJsActiveNodes_.find(custom); + if (iter != delayJsActiveNodes_.end()) { + iter->second = active; + } else { + delayJsActiveNodes_.emplace(custom, active); + } +} + void UITaskScheduler::FlushDelayJsActive() { - CustomNode::FlushDelayJsActive(); + auto nodes = std::move(delayJsActiveNodes_); + for (auto [node, active] : nodes) { + auto customNode = node.Upgrade(); + if (customNode) { + if (customNode->GetJsActive() != active) { + customNode->SetJsActive(active); + customNode->FireSetActiveFunc(active); + } + } + } } void UITaskScheduler::AddPredictTask(PredictTask&& task) diff --git a/frameworks/core/pipeline_ng/ui_task_scheduler.h b/frameworks/core/pipeline_ng/ui_task_scheduler.h index 47b24f9483f..6fd73a70070 100755 --- a/frameworks/core/pipeline_ng/ui_task_scheduler.h +++ b/frameworks/core/pipeline_ng/ui_task_scheduler.h @@ -28,6 +28,7 @@ namespace OHOS::Ace::NG { +class CustomNode; class FrameNode; using TaskThread = uint32_t; @@ -117,6 +118,8 @@ public: return isLayouting_; } + void SetJSViewActive(bool active, WeakPtr custom); + private: bool NeedAdditionalLayout(); @@ -154,6 +157,8 @@ private: FrameInfo* frameInfo_ = nullptr; + std::map, bool> delayJsActiveNodes_; + static uint64_t frameId_; ACE_DISALLOW_COPY_AND_MOVE(UITaskScheduler); -- Gitee