diff --git a/frameworks/bridge/declarative_frontend/jsview/js_node_container.cpp b/frameworks/bridge/declarative_frontend/jsview/js_node_container.cpp index 00e609055a9..bd446c62393 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_node_container.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_node_container.cpp @@ -163,9 +163,10 @@ void JSNodeContainer::SetNodeController(const JSRef& object, JsiExecut CHECK_NULL_VOID(nodeContainerModelInstance); auto jsFunc = JSRef::Cast(jsMakeNodeFunc); + auto containerId = Container::CurrentId(); RefPtr jsMake = AceType::MakeRefPtr(JSRef(object), jsFunc); nodeContainerModelInstance->SetMakeFunction( - [func = std::move(jsMake), execCtx](int32_t containerId) -> RefPtr { + [func = std::move(jsMake), containerId, execCtx]() -> RefPtr { JAVASCRIPT_EXECUTION_SCOPE(execCtx); ContainerScope scope(containerId); panda::Local uiContext = NG::UIContextHelper::GetUIContext(execCtx.vm_, containerId); diff --git a/frameworks/core/components_ng/pattern/node_container/node_container_model.h b/frameworks/core/components_ng/pattern/node_container/node_container_model.h index ab422bdc624..4a9e4fbc0f6 100644 --- a/frameworks/core/components_ng/pattern/node_container/node_container_model.h +++ b/frameworks/core/components_ng/pattern/node_container/node_container_model.h @@ -26,7 +26,7 @@ public: virtual ~NodeContainerModel() = default; virtual void Create() = 0; - virtual void SetMakeFunction(std::function(int32_t)>&& makeFunc) = 0; + virtual void SetMakeFunction(std::function()>&& makeFunc) = 0; virtual void SetOnResize(std::function&& resizeFunc) = 0; virtual void SetOnAppear(std::function&& onAppearCallback) = 0; virtual void SetOnDisAppear(std::function&& onDisAppearCallback) = 0; diff --git a/frameworks/core/components_ng/pattern/node_container/node_container_model_ng.cpp b/frameworks/core/components_ng/pattern/node_container/node_container_model_ng.cpp index 6bc65798cf9..2292dfd7302 100644 --- a/frameworks/core/components_ng/pattern/node_container/node_container_model_ng.cpp +++ b/frameworks/core/components_ng/pattern/node_container/node_container_model_ng.cpp @@ -28,7 +28,7 @@ void NodeContainerModelNG::Create() ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, Alignment, Alignment::TOP_LEFT); } -void NodeContainerModelNG::SetMakeFunction(std::function(int32_t)>&& makeFunc) +void NodeContainerModelNG::SetMakeFunction(std::function()>&& makeFunc) { auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); CHECK_NULL_VOID(frameNode); diff --git a/frameworks/core/components_ng/pattern/node_container/node_container_model_ng.h b/frameworks/core/components_ng/pattern/node_container/node_container_model_ng.h index f60fa677740..742a4217b47 100644 --- a/frameworks/core/components_ng/pattern/node_container/node_container_model_ng.h +++ b/frameworks/core/components_ng/pattern/node_container/node_container_model_ng.h @@ -22,7 +22,7 @@ namespace OHOS::Ace::NG { class ACE_EXPORT NodeContainerModelNG : public NodeContainerModel { public: void Create() override; - void SetMakeFunction(std::function(int32_t)>&& makeFunc) override; + void SetMakeFunction(std::function()>&& makeFunc) override; void SetOnResize(std::function&& resizeFunc) override; void SetOnAppear(std::function&& onAppearCallback) override; void SetOnDisAppear(std::function&& onDisAppearCallback) override; diff --git a/frameworks/core/components_ng/pattern/node_container/node_container_pattern.cpp b/frameworks/core/components_ng/pattern/node_container/node_container_pattern.cpp index 27f4b260afa..03485aaff7b 100644 --- a/frameworks/core/components_ng/pattern/node_container/node_container_pattern.cpp +++ b/frameworks/core/components_ng/pattern/node_container/node_container_pattern.cpp @@ -43,11 +43,7 @@ void NodeContainerPattern::RemakeNode() { auto host = GetHost(); CHECK_NULL_VOID(host); - auto context = host->GetContext(); - CHECK_NULL_VOID(context); - auto instanceId = context->GetInstanceId(); - ContainerScope scope(instanceId); - auto newNode = FireMakeFunction(instanceId); + auto newNode = FireMakeFunction(); auto oldChild = host->GetChildAtIndex(0); if ((!oldChild && !newNode) || (oldChild && oldChild == newNode)) { return; diff --git a/frameworks/core/components_ng/pattern/node_container/node_container_pattern.h b/frameworks/core/components_ng/pattern/node_container/node_container_pattern.h index cbeee29bdef..6b3a7bdf54d 100644 --- a/frameworks/core/components_ng/pattern/node_container/node_container_pattern.h +++ b/frameworks/core/components_ng/pattern/node_container/node_container_pattern.h @@ -62,15 +62,15 @@ public: resetFunc_(); } - void SetMakeFunction(std::function(int32_t)>&& makeFunc) + void SetMakeFunction(std::function()>&& makeFunc) { makeFunc_ = std::move(makeFunc); } - RefPtr FireMakeFunction(int32_t instanceId) const + RefPtr FireMakeFunction() const { CHECK_NULL_RETURN(makeFunc_, nullptr); - return makeFunc_(instanceId); + return makeFunc_(); } void SetOnResize(std::function&& resizeFunc) @@ -113,7 +113,7 @@ private: void SetExportTextureInfoIfNeeded(); bool HandleTextureExport(bool isStop); std::function resetFunc_; - std::function(int32_t)> makeFunc_; + std::function()> makeFunc_; std::function resizeFunc_; WeakPtr exportTextureNode_; uint64_t surfaceId_ = 0U; diff --git a/test/unittest/core/pattern/node_container/node_container_test_ng.cpp b/test/unittest/core/pattern/node_container/node_container_test_ng.cpp index a3910d082e8..98827c191cc 100644 --- a/test/unittest/core/pattern/node_container/node_container_test_ng.cpp +++ b/test/unittest/core/pattern/node_container/node_container_test_ng.cpp @@ -41,7 +41,6 @@ using namespace testing::ext; namespace OHOS::Ace::NG { namespace { const std::string CHILD_NODE = "ChildNode"; -constexpr int32_t DEFAULT_INSTANCE_ID = 1000000; } // namespace class NodeContainerTestNg : public testing::Test { @@ -56,9 +55,6 @@ protected: void NodeContainerTestNg::SetUpTestSuite() { MockPipelineContext::SetUp(); - auto context = MockPipelineContext::GetCurrent(); - EXPECT_NE(context, nullptr); - context->instanceId_ = DEFAULT_INSTANCE_ID; } void NodeContainerTestNg::TearDownTestSuite() @@ -109,10 +105,7 @@ HWTEST_F(NodeContainerTestNg, NodeContainerRemakeNode001, TestSize.Level1) * @tc.steps: step2.Fire RemakeNode return with a normal node. * @tc.expected: process success without crash, and does not change the child of NodeContainer. */ - pattern->SetMakeFunction([childNode](int32_t instanceId) -> RefPtr { - EXPECT_EQ(instanceId, DEFAULT_INSTANCE_ID); - return childNode; - }); + pattern->SetMakeFunction([childNode]() -> RefPtr { return childNode; }); pattern->RemakeNode(); ASSERT_EQ(nodeContainerNode->GetChildAtIndex(0), nullptr); @@ -139,10 +132,7 @@ HWTEST_F(NodeContainerTestNg, NodeContainerRemakeNode001, TestSize.Level1) auto childNode_one = FrameNode::CreateFrameNode(CHILD_NODE, 1, AceType::MakeRefPtr()); childNode_one->SetIsRootBuilderNode(false); childNode_one->SetIsArkTsFrameNode(true); - pattern->SetMakeFunction([childNode_one](int32_t instanceId) -> RefPtr { - EXPECT_EQ(instanceId, DEFAULT_INSTANCE_ID); - return childNode_one; - }); + pattern->SetMakeFunction([childNode_one]() -> RefPtr { return childNode_one; }); pattern->RemakeNode(); ASSERT_EQ(nodeContainerNode->GetChildAtIndex(0)->GetId(), childNode_one->GetId()); @@ -153,44 +143,21 @@ HWTEST_F(NodeContainerTestNg, NodeContainerRemakeNode001, TestSize.Level1) auto childNode_two = FrameNode::CreateFrameNode(V2::CUSTOM_FRAME_NODE_ETS_TAG, 2, AceType::MakeRefPtr()); childNode_two->SetIsRootBuilderNode(false); childNode_two->SetIsArkTsFrameNode(true); - pattern->SetMakeFunction([childNode_two](int32_t instanceId) -> RefPtr { - EXPECT_EQ(instanceId, DEFAULT_INSTANCE_ID); - return childNode_two; - }); + pattern->SetMakeFunction([childNode_two]() -> RefPtr { return childNode_two; }); pattern->RemakeNode(); ASSERT_EQ(nodeContainerNode->GetChildAtIndex(0)->GetId(), childNode_two->GetId()); -} - -/** - * @tc.name: NodeContainerRemakeNode002 - * @tc.desc: Test the RemakeNode function of NodeContainer. - * @tc.type: FUNC - */ -HWTEST_F(NodeContainerTestNg, NodeContainerRemakeNode002, TestSize.Level1) -{ - RefPtr nodeContainerNode = CreateNode(); - ASSERT_NE(nodeContainerNode, nullptr); - RefPtr childNode = FrameNode::CreateFrameNode(CHILD_NODE, 0, AceType::MakeRefPtr()); - auto pattern = nodeContainerNode->GetPattern(); - ASSERT_NE(pattern, nullptr); /** - * @tc.steps: step1.Fire RemakeNode return with nullptr. When oldNode is not null. + * @tc.steps: step7.Fire RemakeNode return with nullptr. When oldNode is not null. * @tc.expected: process success without crash. */ auto childNode_three = FrameNode::CreateFrameNode(CHILD_NODE, 3, AceType::MakeRefPtr()); childNode_three->SetIsRootBuilderNode(false); childNode_three->SetIsArkTsFrameNode(true); - pattern->SetMakeFunction([childNode_three](int32_t instanceId) -> RefPtr { - EXPECT_EQ(instanceId, DEFAULT_INSTANCE_ID); - return childNode_three; - }); + pattern->SetMakeFunction([childNode_three]() -> RefPtr { return childNode_three; }); pattern->RemakeNode(); ASSERT_EQ(nodeContainerNode->GetChildAtIndex(0)->GetId(), childNode_three->GetId()); - pattern->SetMakeFunction([childNode](int32_t instanceId) -> RefPtr { - EXPECT_EQ(instanceId, DEFAULT_INSTANCE_ID); - return nullptr; - }); + pattern->SetMakeFunction([childNode]() -> RefPtr { return nullptr; }); pattern->RemakeNode(); ASSERT_EQ(nodeContainerNode->GetChildAtIndex(0), nullptr); } @@ -248,8 +215,7 @@ HWTEST_F(NodeContainerTestNg, NodeContainerModelNGSetMakeFunction001, TestSize.L */ NodeContainerModelNG modelNg; modelNg.Create(); - auto builderFunc = [](int32_t instanceId) -> RefPtr { - EXPECT_EQ(instanceId, DEFAULT_INSTANCE_ID); + auto builderFunc = []() -> RefPtr { auto node = FrameNode::CreateFrameNode("node", 0, AceType::MakeRefPtr(), true); auto childNode = FrameNode::CreateFrameNode("child", 1, AceType::MakeRefPtr(), true); node->AddChild(childNode); @@ -264,7 +230,7 @@ HWTEST_F(NodeContainerTestNg, NodeContainerModelNGSetMakeFunction001, TestSize.L CHECK_NULL_VOID(frameNode); auto pattern = AceType::DynamicCast(frameNode->GetPattern()); CHECK_NULL_VOID(pattern); - auto node = pattern->FireMakeFunction(DEFAULT_INSTANCE_ID); + auto node = pattern->FireMakeFunction(); EXPECT_EQ(node->GetChildren().size(), 1); }