From 55fd4229021f15b2c416fe08360a4d036ad3c3ec Mon Sep 17 00:00:00 2001 From: "DESKTOP-H8KLN8I\\lisitao" Date: Thu, 11 Sep 2025 21:37:34 +0800 Subject: [PATCH] =?UTF-8?q?[L]fix=20appbar=20setbackgroundcolor=20?= =?UTF-8?q?=E4=BF=AE=E6=94=B9Signed-off-by:lisitaolisitao3@huawei.com?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: DESKTOP-H8KLN8I\lisitao --- .../core/pipeline_ng/pipeline_context.cpp | 9 +++++ .../core/pattern/app_bar/app_bar_test_ng.cpp | 34 +++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/frameworks/core/pipeline_ng/pipeline_context.cpp b/frameworks/core/pipeline_ng/pipeline_context.cpp index c7f28f94b7f..9e27d2c9aef 100755 --- a/frameworks/core/pipeline_ng/pipeline_context.cpp +++ b/frameworks/core/pipeline_ng/pipeline_context.cpp @@ -4730,6 +4730,15 @@ void PipelineContext::SetAppBgColor(const Color& color) auto renderContext = stage->GetRenderContext(); CHECK_NULL_VOID(renderContext); renderContext->UpdateBackgroundColor(color); + auto container = Container::GetContainer(instanceId_); + CHECK_NULL_VOID(container); + auto appbar = container->GetAppBar(); + CHECK_NULL_VOID(appbar); + auto pattern = appbar->GetAtomicServicePattern(); + CHECK_NULL_VOID(pattern); + auto atomicServicePattern = AceType::DynamicCast(pattern); + CHECK_NULL_VOID(atomicServicePattern); + atomicServicePattern->AppBgColorCallBack(); } void PipelineContext::SetAppTitle(const std::string& title) diff --git a/test/unittest/core/pattern/app_bar/app_bar_test_ng.cpp b/test/unittest/core/pattern/app_bar/app_bar_test_ng.cpp index 1a1b60e9246..a791c7fcee6 100644 --- a/test/unittest/core/pattern/app_bar/app_bar_test_ng.cpp +++ b/test/unittest/core/pattern/app_bar/app_bar_test_ng.cpp @@ -1214,6 +1214,40 @@ HWTEST_F(AppBarTestNg, RectChangeListener003, TestSize.Level1) EXPECT_EQ(pattern->appBarRect_, std::nullopt); } +/** + * @tc.name: TestAppBgColorCallBack030 + * @tc.desc: Test AppBgColorCallBack + * @tc.type: FUNC + */ +HWTEST_F(AppBarTestNg, TestAppBgColorCallBack030, TestSize.Level1) +{ + auto stage = AceType::MakeRefPtr("test", 1, AceType::MakeRefPtr()); + EXPECT_NE(stage, nullptr); + auto appBar = AceType::MakeRefPtr(); + EXPECT_NE(appBar, nullptr); + auto atom = appBar->Create(stage); + EXPECT_NE(atom, nullptr); + auto menuBar = appBar->BuildMenuBar(); + atom->AddChild(menuBar); + auto pattern = atom->GetPattern(); + + auto custom = CustomAppBarNode::CreateCustomAppBarNode(-1, ""); + ViewStackProcessor::GetInstance()->SetCustomAppBarNode(custom); + + auto pipeline = PipelineContext::GetCurrentContext(); + CHECK_NULL_VOID(pipeline); + pipeline->SetAppBgColor(Color::RED); + + bool isExecute = false; + auto callback = [&isExecute](const std::string& name, const std::string& value) mutable { + isExecute = true; + }; + + custom->SetCustomCallback(std::move(callback)); + pattern->AppBgColorCallBack(); + EXPECT_EQ(isExecute, true); +} + /** * @tc.name: TestGetAppBarRect003 * @tc.desc: Test GetAppBarRect -- Gitee