From 7c6cebd0f7e19de135a403396b898c2038cc9225 Mon Sep 17 00:00:00 2001 From: mayaolll Date: Fri, 19 Jul 2024 20:46:36 +0800 Subject: [PATCH] fix bug in get navdestination customNode Signed-off-by: mayaolll --- .../jsview/js_navigation_stack.cpp | 8 ++++++-- .../jsview/js_navigation_stack.h | 2 +- .../navrouter/navdestination_group_node.cpp | 20 ++++--------------- 3 files changed, 11 insertions(+), 19 deletions(-) diff --git a/frameworks/bridge/declarative_frontend/jsview/js_navigation_stack.cpp b/frameworks/bridge/declarative_frontend/jsview/js_navigation_stack.cpp index eee63e987bb..f2d9ff0df8b 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_navigation_stack.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_navigation_stack.cpp @@ -412,11 +412,12 @@ JSRef JSNavigationStack::GetOnPopByIndex(int32_t index) const } bool JSNavigationStack::GetNavDestinationNodeInUINode( - RefPtr node, RefPtr& desNode) + RefPtr& node, RefPtr& desNode) { + RefPtr customNode; while (node) { if (node->GetTag() == V2::JS_VIEW_ETS_TAG) { - auto customNode = AceType::DynamicCast(node); + customNode = AceType::DynamicCast(node); TAG_LOGI(AceLogTag::ACE_NAVIGATION, "render current custom node: %{public}s", customNode->GetCustomTag().c_str()); // record parent navigationNode before customNode is rendered in case of navDestinationNode @@ -426,6 +427,9 @@ bool JSNavigationStack::GetNavDestinationNodeInUINode( customNode->Render(); } else if (node->GetTag() == V2::NAVDESTINATION_VIEW_ETS_TAG) { desNode = AceType::DynamicCast(node); + if (customNode) { + node = customNode; + } return true; } auto children = node->GetChildren(); diff --git a/frameworks/bridge/declarative_frontend/jsview/js_navigation_stack.h b/frameworks/bridge/declarative_frontend/jsview/js_navigation_stack.h index 48a683c8518..3fbd9769490 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_navigation_stack.h +++ b/frameworks/bridge/declarative_frontend/jsview/js_navigation_stack.h @@ -125,7 +125,7 @@ private: JSRef GetJsPathInfo(int32_t index); std::string GetNameByIndex(int32_t index); JSRef GetOnPopByIndex(int32_t index) const; - bool GetNavDestinationNodeInUINode(RefPtr node, RefPtr& desNode); + bool GetNavDestinationNodeInUINode(RefPtr& node, RefPtr& desNode); int32_t GetSize() const; void SetJSParentStack(JSRef parent); static std::string ConvertParamToString(const JSRef& param); diff --git a/frameworks/core/components_ng/pattern/navrouter/navdestination_group_node.cpp b/frameworks/core/components_ng/pattern/navrouter/navdestination_group_node.cpp index 606d3f061b3..a98ede176d9 100644 --- a/frameworks/core/components_ng/pattern/navrouter/navdestination_group_node.cpp +++ b/frameworks/core/components_ng/pattern/navrouter/navdestination_group_node.cpp @@ -111,26 +111,14 @@ void NavDestinationGroupNode::ProcessShallowBuilder() } } +/** + * @brief Find and return the nearest custom node, which is of type 'JsView' + */ RefPtr NavDestinationGroupNode::GetNavDestinationCustomNode() { auto pattern = GetPattern(); CHECK_NULL_RETURN(pattern, nullptr); - auto navDestinationNode = pattern->GetCustomNode(); - CHECK_NULL_RETURN(navDestinationNode, nullptr); - - auto child = navDestinationNode->GetFirstChild(); - while (child) { - if (AceType::InstanceOf(child)) { - break; - } - - if (AceType::InstanceOf(child)) { - auto customNode = DynamicCast(child); - return customNode; - } - child = child->GetFirstChild(); - } - return nullptr; + return DynamicCast(pattern->GetCustomNode()); } void NavDestinationGroupNode::SetNavDestinationMode(NavDestinationMode mode)