mirror of
https://gitee.com/openharmony/arkui_ace_engine
synced 2024-11-23 07:01:24 +00:00
回退 'Pull Request !42038 : 修复rebuild的时候上下文不明确导致的挂载失败'
This commit is contained in:
parent
a420d53b25
commit
e4d76d20d9
@ -163,9 +163,10 @@ void JSNodeContainer::SetNodeController(const JSRef<JSObject>& object, JsiExecut
|
|||||||
CHECK_NULL_VOID(nodeContainerModelInstance);
|
CHECK_NULL_VOID(nodeContainerModelInstance);
|
||||||
|
|
||||||
auto jsFunc = JSRef<JSFunc>::Cast(jsMakeNodeFunc);
|
auto jsFunc = JSRef<JSFunc>::Cast(jsMakeNodeFunc);
|
||||||
|
auto containerId = Container::CurrentId();
|
||||||
RefPtr<JsFunction> jsMake = AceType::MakeRefPtr<JsFunction>(JSRef<JSObject>(object), jsFunc);
|
RefPtr<JsFunction> jsMake = AceType::MakeRefPtr<JsFunction>(JSRef<JSObject>(object), jsFunc);
|
||||||
nodeContainerModelInstance->SetMakeFunction(
|
nodeContainerModelInstance->SetMakeFunction(
|
||||||
[func = std::move(jsMake), execCtx](int32_t containerId) -> RefPtr<NG::UINode> {
|
[func = std::move(jsMake), containerId, execCtx]() -> RefPtr<NG::UINode> {
|
||||||
JAVASCRIPT_EXECUTION_SCOPE(execCtx);
|
JAVASCRIPT_EXECUTION_SCOPE(execCtx);
|
||||||
ContainerScope scope(containerId);
|
ContainerScope scope(containerId);
|
||||||
panda::Local<panda::JSValueRef> uiContext = NG::UIContextHelper::GetUIContext(execCtx.vm_, containerId);
|
panda::Local<panda::JSValueRef> uiContext = NG::UIContextHelper::GetUIContext(execCtx.vm_, containerId);
|
||||||
|
@ -26,7 +26,7 @@ public:
|
|||||||
virtual ~NodeContainerModel() = default;
|
virtual ~NodeContainerModel() = default;
|
||||||
|
|
||||||
virtual void Create() = 0;
|
virtual void Create() = 0;
|
||||||
virtual void SetMakeFunction(std::function<RefPtr<NG::UINode>(int32_t)>&& makeFunc) = 0;
|
virtual void SetMakeFunction(std::function<RefPtr<NG::UINode>()>&& makeFunc) = 0;
|
||||||
virtual void SetOnResize(std::function<void(const NG::SizeF& size)>&& resizeFunc) = 0;
|
virtual void SetOnResize(std::function<void(const NG::SizeF& size)>&& resizeFunc) = 0;
|
||||||
virtual void SetOnAppear(std::function<void()>&& onAppearCallback) = 0;
|
virtual void SetOnAppear(std::function<void()>&& onAppearCallback) = 0;
|
||||||
virtual void SetOnDisAppear(std::function<void()>&& onDisAppearCallback) = 0;
|
virtual void SetOnDisAppear(std::function<void()>&& onDisAppearCallback) = 0;
|
||||||
|
@ -28,7 +28,7 @@ void NodeContainerModelNG::Create()
|
|||||||
ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, Alignment, Alignment::TOP_LEFT);
|
ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, Alignment, Alignment::TOP_LEFT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NodeContainerModelNG::SetMakeFunction(std::function<RefPtr<UINode>(int32_t)>&& makeFunc)
|
void NodeContainerModelNG::SetMakeFunction(std::function<RefPtr<UINode>()>&& makeFunc)
|
||||||
{
|
{
|
||||||
auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
|
auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
|
||||||
CHECK_NULL_VOID(frameNode);
|
CHECK_NULL_VOID(frameNode);
|
||||||
|
@ -22,7 +22,7 @@ namespace OHOS::Ace::NG {
|
|||||||
class ACE_EXPORT NodeContainerModelNG : public NodeContainerModel {
|
class ACE_EXPORT NodeContainerModelNG : public NodeContainerModel {
|
||||||
public:
|
public:
|
||||||
void Create() override;
|
void Create() override;
|
||||||
void SetMakeFunction(std::function<RefPtr<UINode>(int32_t)>&& makeFunc) override;
|
void SetMakeFunction(std::function<RefPtr<UINode>()>&& makeFunc) override;
|
||||||
void SetOnResize(std::function<void(const SizeF& size)>&& resizeFunc) override;
|
void SetOnResize(std::function<void(const SizeF& size)>&& resizeFunc) override;
|
||||||
void SetOnAppear(std::function<void()>&& onAppearCallback) override;
|
void SetOnAppear(std::function<void()>&& onAppearCallback) override;
|
||||||
void SetOnDisAppear(std::function<void()>&& onDisAppearCallback) override;
|
void SetOnDisAppear(std::function<void()>&& onDisAppearCallback) override;
|
||||||
|
@ -43,11 +43,7 @@ void NodeContainerPattern::RemakeNode()
|
|||||||
{
|
{
|
||||||
auto host = GetHost();
|
auto host = GetHost();
|
||||||
CHECK_NULL_VOID(host);
|
CHECK_NULL_VOID(host);
|
||||||
auto context = host->GetContext();
|
auto newNode = FireMakeFunction();
|
||||||
CHECK_NULL_VOID(context);
|
|
||||||
auto instanceId = context->GetInstanceId();
|
|
||||||
ContainerScope scope(instanceId);
|
|
||||||
auto newNode = FireMakeFunction(instanceId);
|
|
||||||
auto oldChild = host->GetChildAtIndex(0);
|
auto oldChild = host->GetChildAtIndex(0);
|
||||||
if ((!oldChild && !newNode) || (oldChild && oldChild == newNode)) {
|
if ((!oldChild && !newNode) || (oldChild && oldChild == newNode)) {
|
||||||
return;
|
return;
|
||||||
|
@ -62,15 +62,15 @@ public:
|
|||||||
resetFunc_();
|
resetFunc_();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetMakeFunction(std::function<RefPtr<UINode>(int32_t)>&& makeFunc)
|
void SetMakeFunction(std::function<RefPtr<UINode>()>&& makeFunc)
|
||||||
{
|
{
|
||||||
makeFunc_ = std::move(makeFunc);
|
makeFunc_ = std::move(makeFunc);
|
||||||
}
|
}
|
||||||
|
|
||||||
RefPtr<UINode> FireMakeFunction(int32_t instanceId) const
|
RefPtr<UINode> FireMakeFunction() const
|
||||||
{
|
{
|
||||||
CHECK_NULL_RETURN(makeFunc_, nullptr);
|
CHECK_NULL_RETURN(makeFunc_, nullptr);
|
||||||
return makeFunc_(instanceId);
|
return makeFunc_();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetOnResize(std::function<void(const SizeF& size)>&& resizeFunc)
|
void SetOnResize(std::function<void(const SizeF& size)>&& resizeFunc)
|
||||||
@ -113,7 +113,7 @@ private:
|
|||||||
void SetExportTextureInfoIfNeeded();
|
void SetExportTextureInfoIfNeeded();
|
||||||
bool HandleTextureExport(bool isStop);
|
bool HandleTextureExport(bool isStop);
|
||||||
std::function<void()> resetFunc_;
|
std::function<void()> resetFunc_;
|
||||||
std::function<RefPtr<UINode>(int32_t)> makeFunc_;
|
std::function<RefPtr<UINode>()> makeFunc_;
|
||||||
std::function<void(const SizeF& size)> resizeFunc_;
|
std::function<void(const SizeF& size)> resizeFunc_;
|
||||||
WeakPtr<UINode> exportTextureNode_;
|
WeakPtr<UINode> exportTextureNode_;
|
||||||
uint64_t surfaceId_ = 0U;
|
uint64_t surfaceId_ = 0U;
|
||||||
|
@ -41,7 +41,6 @@ using namespace testing::ext;
|
|||||||
namespace OHOS::Ace::NG {
|
namespace OHOS::Ace::NG {
|
||||||
namespace {
|
namespace {
|
||||||
const std::string CHILD_NODE = "ChildNode";
|
const std::string CHILD_NODE = "ChildNode";
|
||||||
constexpr int32_t DEFAULT_INSTANCE_ID = 1000000;
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
class NodeContainerTestNg : public testing::Test {
|
class NodeContainerTestNg : public testing::Test {
|
||||||
@ -56,9 +55,6 @@ protected:
|
|||||||
void NodeContainerTestNg::SetUpTestSuite()
|
void NodeContainerTestNg::SetUpTestSuite()
|
||||||
{
|
{
|
||||||
MockPipelineContext::SetUp();
|
MockPipelineContext::SetUp();
|
||||||
auto context = MockPipelineContext::GetCurrent();
|
|
||||||
EXPECT_NE(context, nullptr);
|
|
||||||
context->instanceId_ = DEFAULT_INSTANCE_ID;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NodeContainerTestNg::TearDownTestSuite()
|
void NodeContainerTestNg::TearDownTestSuite()
|
||||||
@ -109,10 +105,7 @@ HWTEST_F(NodeContainerTestNg, NodeContainerRemakeNode001, TestSize.Level1)
|
|||||||
* @tc.steps: step2.Fire RemakeNode return with a normal node.
|
* @tc.steps: step2.Fire RemakeNode return with a normal node.
|
||||||
* @tc.expected: process success without crash, and does not change the child of NodeContainer.
|
* @tc.expected: process success without crash, and does not change the child of NodeContainer.
|
||||||
*/
|
*/
|
||||||
pattern->SetMakeFunction([childNode](int32_t instanceId) -> RefPtr<UINode> {
|
pattern->SetMakeFunction([childNode]() -> RefPtr<UINode> { return childNode; });
|
||||||
EXPECT_EQ(instanceId, DEFAULT_INSTANCE_ID);
|
|
||||||
return childNode;
|
|
||||||
});
|
|
||||||
pattern->RemakeNode();
|
pattern->RemakeNode();
|
||||||
ASSERT_EQ(nodeContainerNode->GetChildAtIndex(0), nullptr);
|
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<Pattern>());
|
auto childNode_one = FrameNode::CreateFrameNode(CHILD_NODE, 1, AceType::MakeRefPtr<Pattern>());
|
||||||
childNode_one->SetIsRootBuilderNode(false);
|
childNode_one->SetIsRootBuilderNode(false);
|
||||||
childNode_one->SetIsArkTsFrameNode(true);
|
childNode_one->SetIsArkTsFrameNode(true);
|
||||||
pattern->SetMakeFunction([childNode_one](int32_t instanceId) -> RefPtr<UINode> {
|
pattern->SetMakeFunction([childNode_one]() -> RefPtr<UINode> { return childNode_one; });
|
||||||
EXPECT_EQ(instanceId, DEFAULT_INSTANCE_ID);
|
|
||||||
return childNode_one;
|
|
||||||
});
|
|
||||||
pattern->RemakeNode();
|
pattern->RemakeNode();
|
||||||
ASSERT_EQ(nodeContainerNode->GetChildAtIndex(0)->GetId(), childNode_one->GetId());
|
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<Pattern>());
|
auto childNode_two = FrameNode::CreateFrameNode(V2::CUSTOM_FRAME_NODE_ETS_TAG, 2, AceType::MakeRefPtr<Pattern>());
|
||||||
childNode_two->SetIsRootBuilderNode(false);
|
childNode_two->SetIsRootBuilderNode(false);
|
||||||
childNode_two->SetIsArkTsFrameNode(true);
|
childNode_two->SetIsArkTsFrameNode(true);
|
||||||
pattern->SetMakeFunction([childNode_two](int32_t instanceId) -> RefPtr<UINode> {
|
pattern->SetMakeFunction([childNode_two]() -> RefPtr<UINode> { return childNode_two; });
|
||||||
EXPECT_EQ(instanceId, DEFAULT_INSTANCE_ID);
|
|
||||||
return childNode_two;
|
|
||||||
});
|
|
||||||
pattern->RemakeNode();
|
pattern->RemakeNode();
|
||||||
ASSERT_EQ(nodeContainerNode->GetChildAtIndex(0)->GetId(), childNode_two->GetId());
|
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<FrameNode> nodeContainerNode = CreateNode();
|
|
||||||
ASSERT_NE(nodeContainerNode, nullptr);
|
|
||||||
RefPtr<FrameNode> childNode = FrameNode::CreateFrameNode(CHILD_NODE, 0, AceType::MakeRefPtr<Pattern>());
|
|
||||||
auto pattern = nodeContainerNode->GetPattern<NodeContainerPattern>();
|
|
||||||
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.
|
* @tc.expected: process success without crash.
|
||||||
*/
|
*/
|
||||||
auto childNode_three = FrameNode::CreateFrameNode(CHILD_NODE, 3, AceType::MakeRefPtr<Pattern>());
|
auto childNode_three = FrameNode::CreateFrameNode(CHILD_NODE, 3, AceType::MakeRefPtr<Pattern>());
|
||||||
childNode_three->SetIsRootBuilderNode(false);
|
childNode_three->SetIsRootBuilderNode(false);
|
||||||
childNode_three->SetIsArkTsFrameNode(true);
|
childNode_three->SetIsArkTsFrameNode(true);
|
||||||
pattern->SetMakeFunction([childNode_three](int32_t instanceId) -> RefPtr<UINode> {
|
pattern->SetMakeFunction([childNode_three]() -> RefPtr<UINode> { return childNode_three; });
|
||||||
EXPECT_EQ(instanceId, DEFAULT_INSTANCE_ID);
|
|
||||||
return childNode_three;
|
|
||||||
});
|
|
||||||
pattern->RemakeNode();
|
pattern->RemakeNode();
|
||||||
ASSERT_EQ(nodeContainerNode->GetChildAtIndex(0)->GetId(), childNode_three->GetId());
|
ASSERT_EQ(nodeContainerNode->GetChildAtIndex(0)->GetId(), childNode_three->GetId());
|
||||||
pattern->SetMakeFunction([childNode](int32_t instanceId) -> RefPtr<UINode> {
|
pattern->SetMakeFunction([childNode]() -> RefPtr<UINode> { return nullptr; });
|
||||||
EXPECT_EQ(instanceId, DEFAULT_INSTANCE_ID);
|
|
||||||
return nullptr;
|
|
||||||
});
|
|
||||||
pattern->RemakeNode();
|
pattern->RemakeNode();
|
||||||
ASSERT_EQ(nodeContainerNode->GetChildAtIndex(0), nullptr);
|
ASSERT_EQ(nodeContainerNode->GetChildAtIndex(0), nullptr);
|
||||||
}
|
}
|
||||||
@ -248,8 +215,7 @@ HWTEST_F(NodeContainerTestNg, NodeContainerModelNGSetMakeFunction001, TestSize.L
|
|||||||
*/
|
*/
|
||||||
NodeContainerModelNG modelNg;
|
NodeContainerModelNG modelNg;
|
||||||
modelNg.Create();
|
modelNg.Create();
|
||||||
auto builderFunc = [](int32_t instanceId) -> RefPtr<UINode> {
|
auto builderFunc = []() -> RefPtr<UINode> {
|
||||||
EXPECT_EQ(instanceId, DEFAULT_INSTANCE_ID);
|
|
||||||
auto node = FrameNode::CreateFrameNode("node", 0, AceType::MakeRefPtr<Pattern>(), true);
|
auto node = FrameNode::CreateFrameNode("node", 0, AceType::MakeRefPtr<Pattern>(), true);
|
||||||
auto childNode = FrameNode::CreateFrameNode("child", 1, AceType::MakeRefPtr<Pattern>(), true);
|
auto childNode = FrameNode::CreateFrameNode("child", 1, AceType::MakeRefPtr<Pattern>(), true);
|
||||||
node->AddChild(childNode);
|
node->AddChild(childNode);
|
||||||
@ -264,7 +230,7 @@ HWTEST_F(NodeContainerTestNg, NodeContainerModelNGSetMakeFunction001, TestSize.L
|
|||||||
CHECK_NULL_VOID(frameNode);
|
CHECK_NULL_VOID(frameNode);
|
||||||
auto pattern = AceType::DynamicCast<NodeContainerPattern>(frameNode->GetPattern());
|
auto pattern = AceType::DynamicCast<NodeContainerPattern>(frameNode->GetPattern());
|
||||||
CHECK_NULL_VOID(pattern);
|
CHECK_NULL_VOID(pattern);
|
||||||
auto node = pattern->FireMakeFunction(DEFAULT_INSTANCE_ID);
|
auto node = pattern->FireMakeFunction();
|
||||||
EXPECT_EQ(node->GetChildren().size(), 1);
|
EXPECT_EQ(node->GetChildren().size(), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user