diff --git a/frameworks/bridge/declarative_frontend/ark_theme/theme_apply/js_scroll_theme.h b/frameworks/bridge/declarative_frontend/ark_theme/theme_apply/js_scroll_theme.h index a671c686be6a4cd4ff2ed201f2ee929601ff5827..7376f9f27485329516337dd6c0252ad52be72cdf 100644 --- a/frameworks/bridge/declarative_frontend/ark_theme/theme_apply/js_scroll_theme.h +++ b/frameworks/bridge/declarative_frontend/ark_theme/theme_apply/js_scroll_theme.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/frameworks/bridge/declarative_frontend/jsview/js_scroll.cpp b/frameworks/bridge/declarative_frontend/jsview/js_scroll.cpp index 86d98da43f283ce3ead0a142b71b7f43d0e4e488..0a842c5ffb8d5c4582c67c7b9274abac978c42e9 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_scroll.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_scroll.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Copyright (c) 2021-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -115,7 +115,9 @@ void JSScroll::Create(const JSCallbackInfo& info) ScrollModel::GetInstance()->SetScrollBarProxy(proxy); } } - JSScrollTheme::ApplyTheme(); + if (Container::LessThanAPIVersion(PlatformVersion::VERSION_TWENTY)) { + JSScrollTheme::ApplyTheme(); + } } void JSScroll::SetScrollable(int32_t value) @@ -423,7 +425,11 @@ void JSScroll::SetScrollBarColor(const JSCallbackInfo& args) auto theme = pipelineContext->GetTheme(); CHECK_NULL_VOID(theme); Color color(theme->GetForegroundColor()); - JSViewAbstract::ParseJsColor(args[0], color); + if (!JSViewAbstract::ParseJsColor(args[0], color) && + Container::GreatOrEqualAPIVersion(PlatformVersion::VERSION_TWENTY)) { + ScrollModel::GetInstance()->ResetScrollBarColor(); + return; + } ScrollModel::GetInstance()->SetScrollBarColor(color); } diff --git a/frameworks/bridge/declarative_frontend/jsview/models/scroll_model_impl.h b/frameworks/bridge/declarative_frontend/jsview/models/scroll_model_impl.h index b6dc40edf0bfa376ea66b539e335a1573d5cca46..76d9e4a3618e32ad1b17b2a862eebb4bda2e8448 100644 --- a/frameworks/bridge/declarative_frontend/jsview/models/scroll_model_impl.h +++ b/frameworks/bridge/declarative_frontend/jsview/models/scroll_model_impl.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -44,6 +44,7 @@ public: void SetDisplayMode(int displayMode) override; void SetScrollBarWidth(const Dimension& dimension) override; void SetScrollBarColor(const Color& color) override; + void ResetScrollBarColor() override {}; void SetEdgeEffect(EdgeEffect edgeEffect, bool alwaysEnabled, EffectEdge effectEdge) override; void SetHasWidth(bool hasWidth) override; void SetHasHeight(bool hasHeight) override; diff --git a/frameworks/core/components/scroll/scroll_bar_theme.h b/frameworks/core/components/scroll/scroll_bar_theme.h index 6cb7783be1540f4a5c9b7979e7ad6aad015cd1a2..30693ec450b0aee326fd8f02b18298635c007a70 100644 --- a/frameworks/core/components/scroll/scroll_bar_theme.h +++ b/frameworks/core/components/scroll/scroll_bar_theme.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -16,6 +16,7 @@ #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SCROLL_SCROLL_BAR_THEME_H #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SCROLL_SCROLL_BAR_THEME_H +#include "core/common/container.h" #include "core/components/common/properties/scroll_bar.h" #include "core/components/theme/theme.h" #include "core/components/theme/theme_constants.h" @@ -42,7 +43,7 @@ public: class Builder { public: Builder() = default; - ~Builder() = default; + virtual ~Builder() = default; RefPtr Build(const RefPtr& themeConstants) const { @@ -54,7 +55,6 @@ public: return theme; } - private: void ParsePattern(const RefPtr& themeConstants, const RefPtr& theme) const { RefPtr pattern = themeConstants->GetPatternByName(THEME_PATTERN_SCROLL_BAR); @@ -230,6 +230,7 @@ public: protected: ScrollBarTheme() = default; + Color foregroundColor_; private: ShapeMode shapeMode_ = ShapeMode::DEFAULT; @@ -243,7 +244,6 @@ private: Dimension defaultWidth_; Dimension defaultHeight_; Color backgroundColor_; - Color foregroundColor_; Color foregroundHoverBlendColor_; Color foregroundPressedBlendColor_; Edge padding_; diff --git a/frameworks/core/components/theme/theme_manager_impl.cpp b/frameworks/core/components/theme/theme_manager_impl.cpp index 5e7ca39cf80737246b4398280eb924f7be947c7c..eb9b0a8554211c129d1fc96b76666b5f3712baf4 100644 --- a/frameworks/core/components/theme/theme_manager_impl.cpp +++ b/frameworks/core/components/theme/theme_manager_impl.cpp @@ -98,6 +98,7 @@ #include "core/components_ng/pattern/picker/picker_theme_wrapper.h" #include "core/components_ng/pattern/navigation/navigation_bar_theme_wrapper.h" #include "core/common/agingadapation/aging_adapation_dialog_theme_wrapper.h" +#include "core/components_ng/pattern/scroll/scroll_theme_wrapper.h" #include "core/components_ng/pattern/side_bar/side_bar_theme_wrapper.h" namespace OHOS::Ace { @@ -206,7 +207,8 @@ const std::unordered_map(*)(const RefPtr }, { NG::SideBarTheme::TypeId(), &ThemeWrapperBuildFunc }, - { TextOverlayTheme::TypeId(), &ThemeWrapperBuildFunc } + { TextOverlayTheme::TypeId(), &ThemeWrapperBuildFunc }, + { ScrollBarTheme::TypeId(), &ThemeWrapperBuildFunc } }; std::unordered_map THEME_BUILDERS_KIT; diff --git a/frameworks/core/components_ng/pattern/scroll/scroll_model.h b/frameworks/core/components_ng/pattern/scroll/scroll_model.h index 4be0d2e43d02b546cdabc591fad2d3d956a659b3..b792e8c33cfdb10140c58071469f46ba336e9876 100644 --- a/frameworks/core/components_ng/pattern/scroll/scroll_model.h +++ b/frameworks/core/components_ng/pattern/scroll/scroll_model.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -55,6 +55,7 @@ public: virtual void SetDisplayMode(int displayMode) = 0; virtual void SetScrollBarWidth(const Dimension& dimension) = 0; virtual void SetScrollBarColor(const Color& color) = 0; + virtual void ResetScrollBarColor() = 0; virtual void SetEdgeEffect(EdgeEffect edgeEffect, bool alwaysEnabled, EffectEdge effectEdge = EffectEdge::ALL) = 0; virtual void SetHasWidth(bool hasWidth) = 0; virtual void SetHasHeight(bool hasHeight) = 0; diff --git a/frameworks/core/components_ng/pattern/scroll/scroll_model_ng.cpp b/frameworks/core/components_ng/pattern/scroll/scroll_model_ng.cpp index 2cad9955adbfe006569ad30f6cf40c9aa4fa9531..9763f6dfcd32b47fe4dd3a5082d07d0786afa078 100644 --- a/frameworks/core/components_ng/pattern/scroll/scroll_model_ng.cpp +++ b/frameworks/core/components_ng/pattern/scroll/scroll_model_ng.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -426,6 +426,11 @@ void ScrollModelNG::SetScrollBarColor(const Color& color) scrollBar->SetForegroundColor(color); } +void ScrollModelNG::ResetScrollBarColor() +{ + ACE_RESET_PAINT_PROPERTY_WITH_FLAG(ScrollablePaintProperty, ScrollBarColor, PROPERTY_UPDATE_RENDER); +} + int32_t ScrollModelNG::GetEdgeEffect(FrameNode* frameNode) { CHECK_NULL_RETURN(frameNode, 0); @@ -507,6 +512,11 @@ void ScrollModelNG::SetScrollBarColor(FrameNode* frameNode, const Color& color) scrollBar->SetForegroundColor(color); } +void ScrollModelNG::ResetScrollBarColor(FrameNode* frameNode) +{ + ACE_RESET_NODE_PAINT_PROPERTY_WITH_FLAG(ScrollablePaintProperty, ScrollBarColor, PROPERTY_UPDATE_RENDER, frameNode); +} + void ScrollModelNG::SetScrollBarWidth(FrameNode* frameNode, const Dimension& dimension) { ACE_UPDATE_NODE_PAINT_PROPERTY(ScrollablePaintProperty, ScrollBarWidth, dimension, frameNode); diff --git a/frameworks/core/components_ng/pattern/scroll/scroll_model_ng.h b/frameworks/core/components_ng/pattern/scroll/scroll_model_ng.h index 5a33216136c3400f45fbb578195063efd9cc5462..646af7a488d21386ab14e506cc7c9f474cfc7c47 100644 --- a/frameworks/core/components_ng/pattern/scroll/scroll_model_ng.h +++ b/frameworks/core/components_ng/pattern/scroll/scroll_model_ng.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -47,6 +47,7 @@ public: void SetDisplayMode(int displayMode) override; void SetScrollBarWidth(const Dimension& dimension) override; void SetScrollBarColor(const Color& color) override; + void ResetScrollBarColor() override; void SetEdgeEffect(EdgeEffect edgeEffect, bool alwaysEnabled, EffectEdge edge = EffectEdge::ALL) override; void SetHasWidth(bool hasWidth) override {} void SetHasHeight(bool hasHeight) override {} @@ -88,6 +89,7 @@ public: static void SetAxis(FrameNode* frameNode, Axis axis); static uint32_t GetScrollBarColor(FrameNode* frameNode); static void SetScrollBarColor(FrameNode* frameNode, const Color& color); + static void ResetScrollBarColor(FrameNode* frameNode); static float GetScrollBarWidth(FrameNode* frameNode); static void SetScrollBarWidth(FrameNode* frameNode, const Dimension& dimension); static int32_t GetEdgeEffect(FrameNode* frameNode); diff --git a/frameworks/core/components_ng/pattern/scroll/scroll_pattern.cpp b/frameworks/core/components_ng/pattern/scroll/scroll_pattern.cpp index 113ea8c5bdaad5194c96455b2c65555d69db2e53..a6af689c2381e6afcbd05a7b2ae4dd78fe272f9c 100644 --- a/frameworks/core/components_ng/pattern/scroll/scroll_pattern.cpp +++ b/frameworks/core/components_ng/pattern/scroll/scroll_pattern.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -1816,4 +1816,27 @@ void ScrollPattern::FreeScrollTo(const ScrollControllerBase::ScrollToParam& para freeScroll_->SetOffset(pos, param.canOverScroll); } } + +bool ScrollPattern::OnThemeScopeUpdate(int32_t themeScopeId) +{ + bool result = false; + if (Container::LessThanAPIVersion(PlatformVersion::VERSION_TWENTY)) { + return result; + } + auto host = GetHost(); + CHECK_NULL_RETURN(host, result); + auto paintProperty = host->GetPaintProperty(); + CHECK_NULL_RETURN(paintProperty, result); + result = !paintProperty->HasScrollBarColor(); + if (result) { + auto pipelineContext = GetContext(); + CHECK_NULL_RETURN(pipelineContext, result); + auto theme = pipelineContext->GetTheme(themeScopeId); + CHECK_NULL_RETURN(theme, result); + auto scrollBar = GetScrollBar(); + CHECK_NULL_RETURN(scrollBar, result); + scrollBar->SetForegroundColor(theme->GetForegroundColor()); + } + return result; +} } // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/scroll/scroll_pattern.h b/frameworks/core/components_ng/pattern/scroll/scroll_pattern.h index 6e14fbafe5fffcce186ac81b3925f3b1c05457af..826ebece4eadcf577fc565f33b8f9761e1f3fcdd 100644 --- a/frameworks/core/components_ng/pattern/scroll/scroll_pattern.h +++ b/frameworks/core/components_ng/pattern/scroll/scroll_pattern.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -160,6 +160,7 @@ public: void OnAnimateStop() override; bool UpdateCurrentOffset(float offset, int32_t source) override; + bool OnThemeScopeUpdate(int32_t themeScopeId) override; void ScrollToEdge(ScrollEdgeType scrollEdgeType, bool smooth) override; void CheckScrollToEdge(); diff --git a/frameworks/core/components_ng/pattern/scroll/scroll_theme_wrapper.h b/frameworks/core/components_ng/pattern/scroll/scroll_theme_wrapper.h new file mode 100644 index 0000000000000000000000000000000000000000..81afd9031777df10fcb6c1166d4bbe048aff0150 --- /dev/null +++ b/frameworks/core/components_ng/pattern/scroll/scroll_theme_wrapper.h @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SCROLL_SCROLL_THEME_WRAPPER_H +#define FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SCROLL_SCROLL_THEME_WRAPPER_H + +#include + +#include "base/memory/ace_type.h" +#include "core/components/scroll/scroll_bar_theme.h" +#include "core/components_ng/token_theme/token_theme_wrapper.h" + +namespace OHOS::Ace::NG { + +/** + * ScrollThemeWrapper defines colors and styles for Scroll component + * basing on TokenTheme's data. + * ScrollThemeWrapper should be built using ScrollThemeWrapper::WrapperBuilder. + */ +class ScrollThemeWrapper : public ScrollBarTheme, public TokenThemeWrapper { + DECLARE_ACE_TYPE(ScrollThemeWrapper, ScrollBarTheme); + +public: + class WrapperBuilder : public Builder { + public: + WrapperBuilder() = default; + ~WrapperBuilder() override = default; + + RefPtr BuildWrapper(const RefPtr& themeConstants) const + { + auto wrapper = AceType::Claim(new ScrollThemeWrapper()); + if (!themeConstants) { + return wrapper; + } + ParsePattern(themeConstants, AceType::DynamicCast(wrapper)); + return wrapper; + } + }; + + ~ScrollThemeWrapper() override = default; + + void ApplyTokenTheme(const TokenTheme& theme) override + { + if (Container::LessThanAPIVersion(PlatformVersion::VERSION_TWENTY)) { + return; + } + if (auto themeColors = theme.Colors(); themeColors) { + foregroundColor_ = themeColors->CompFocusedTertiary(); + } + } + +protected: + ScrollThemeWrapper() = default; +}; + +} // namespace OHOS::Ace::NG +#endif diff --git a/frameworks/core/components_ng/pattern/scrollable/scrollable_paint_property.cpp b/frameworks/core/components_ng/pattern/scrollable/scrollable_paint_property.cpp index 4f49a5bfe2fa7c9a13e21e13a80b2729aa28c2eb..8b561180243ad9ce14100e63920e4c5815f3c45d 100644 --- a/frameworks/core/components_ng/pattern/scrollable/scrollable_paint_property.cpp +++ b/frameworks/core/components_ng/pattern/scrollable/scrollable_paint_property.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -70,11 +70,15 @@ void ScrollablePaintProperty::ToJsonValue(std::unique_ptr& json, cons Color ScrollablePaintProperty::GetBarColor() const { + auto host = GetHost(); + CHECK_NULL_RETURN(host, Color::TRANSPARENT); auto context = PipelineContext::GetCurrentContextSafelyWithCheck(); CHECK_NULL_RETURN(context, Color::TRANSPARENT); auto themeManager = context->GetThemeManager(); CHECK_NULL_RETURN(themeManager, Color::TRANSPARENT); - auto scrollBarTheme = themeManager->GetTheme(); + auto scrollBarTheme = Container::GreatOrEqualAPIVersion(PlatformVersion::VERSION_TWENTY) + ? themeManager->GetTheme(host->GetThemeScopeId()) + : themeManager->GetTheme(); CHECK_NULL_RETURN(scrollBarTheme, Color::TRANSPARENT); auto defaultScrollBarColor = scrollBarTheme->GetForegroundColor(); return propScrollBarProperty_ ? propScrollBarProperty_->propScrollBarColor.value_or(defaultScrollBarColor) @@ -83,11 +87,15 @@ Color ScrollablePaintProperty::GetBarColor() const Dimension ScrollablePaintProperty::GetBarWidth() const { + auto host = GetHost(); + CHECK_NULL_RETURN(host, Dimension()); auto context = PipelineContext::GetCurrentContextSafelyWithCheck(); CHECK_NULL_RETURN(context, Dimension()); auto themeManager = context->GetThemeManager(); CHECK_NULL_RETURN(themeManager, Dimension()); - auto scrollBarTheme = themeManager->GetTheme(); + auto scrollBarTheme = Container::GreatOrEqualAPIVersion(PlatformVersion::VERSION_TWENTY) + ? themeManager->GetTheme(host->GetThemeScopeId()) + : themeManager->GetTheme(); CHECK_NULL_RETURN(scrollBarTheme, Dimension()); auto defaultScrollBarWidth = scrollBarTheme->GetNormalWidth(); return propScrollBarProperty_ ? propScrollBarProperty_->propScrollBarWidth.value_or(defaultScrollBarWidth) diff --git a/frameworks/core/components_ng/pattern/scrollable/scrollable_pattern.cpp b/frameworks/core/components_ng/pattern/scrollable/scrollable_pattern.cpp index 1123e566a6c5bb13eaefebed23932d7d8c842c22..6698e406bb8c97892a1c9b07a1ce739d06ef0fb6 100644 --- a/frameworks/core/components_ng/pattern/scrollable/scrollable_pattern.cpp +++ b/frameworks/core/components_ng/pattern/scrollable/scrollable_pattern.cpp @@ -1242,6 +1242,12 @@ void ScrollablePattern::SetScrollBar(const std::unique_ptr& p auto barColor = property->GetScrollBarColor(); if (barColor) { scrollBar_->SetForegroundColor(barColor.value(), isRoundScroll_); + } else if (Container::GreatOrEqualAPIVersion(PlatformVersion::VERSION_TWENTY)) { + auto pipelineContext = GetContext(); + CHECK_NULL_VOID(pipelineContext); + auto theme = pipelineContext->GetTheme(GetThemeScopeId()); + CHECK_NULL_VOID(theme); + scrollBar_->SetForegroundColor(theme->GetForegroundColor()); } auto scrollableBarMargin = property->GetScrollBarMargin(); if (scrollableBarMargin) { @@ -4437,7 +4443,9 @@ void ScrollablePattern::OnColorConfigurationUpdate() } auto pipelineContext = GetContext(); CHECK_NULL_VOID(pipelineContext); - auto theme = pipelineContext->GetTheme(); + auto theme = Container::GreatOrEqualAPIVersion(PlatformVersion::VERSION_TWENTY) + ? pipelineContext->GetTheme(GetThemeScopeId()) + : pipelineContext->GetTheme(); CHECK_NULL_VOID(theme); scrollBar_->SetForegroundColor(theme->GetForegroundColor(), isRoundScroll_); scrollBar_->SetBackgroundColor(theme->GetBackgroundColor(), isRoundScroll_); diff --git a/frameworks/core/interfaces/native/node/node_scroll_modifier.cpp b/frameworks/core/interfaces/native/node/node_scroll_modifier.cpp index ea062427c95c0b86647fc2e3d040e5ceeee6dfca..2c40dae90253b1c12bb68344ed59399f5ca66aa5 100644 --- a/frameworks/core/interfaces/native/node/node_scroll_modifier.cpp +++ b/frameworks/core/interfaces/native/node/node_scroll_modifier.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2023-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -265,12 +265,16 @@ void ResetScrollScrollBarColor(ArkUINodeHandle node) { auto* frameNode = reinterpret_cast(node); CHECK_NULL_VOID(frameNode); - auto pipeline = frameNode->GetContext(); - CHECK_NULL_VOID(pipeline); - auto scrollBarTheme = pipeline->GetTheme(); - CHECK_NULL_VOID(scrollBarTheme); - Color foregroundColor = scrollBarTheme->GetForegroundColor(); - ScrollModelNG::SetScrollBarColor(frameNode, foregroundColor); + if (Container::GreatOrEqualAPIVersion(PlatformVersion::VERSION_TWENTY)) { + ScrollModelNG::ResetScrollBarColor(frameNode); + } else { + auto pipeline = frameNode->GetContext(); + CHECK_NULL_VOID(pipeline); + auto scrollBarTheme = pipeline->GetTheme(); + CHECK_NULL_VOID(scrollBarTheme); + Color foregroundColor = scrollBarTheme->GetForegroundColor(); + ScrollModelNG::SetScrollBarColor(frameNode, foregroundColor); + } } ArkUI_Float32 GetScrollScrollBarWidth(ArkUINodeHandle node) diff --git a/test/unittest/core/pattern/scroll/scroll_layout_test_ng.cpp b/test/unittest/core/pattern/scroll/scroll_layout_test_ng.cpp index 1de70435fbf0a6abb9b15317fffb140b2f319432..95ecd66daaab8e7c0e5c41413d891d950c93d477 100644 --- a/test/unittest/core/pattern/scroll/scroll_layout_test_ng.cpp +++ b/test/unittest/core/pattern/scroll/scroll_layout_test_ng.cpp @@ -1296,4 +1296,65 @@ HWTEST_F(ScrollLayoutTestNg, UseInitialOffset_004, TestSize.Level1) scrollLayoutAlgorithm->UseInitialOffset(axis, selfSize, AceType::RawPtr(layoutWrapper)); EXPECT_EQ(scrollLayoutAlgorithm->GetCurrentOffset(), 4.0f); } + +/** + * @tc.name: OnThemeScopeUpdate001 + * @tc.desc: Test Pattern OnThemeScopeUpdate function of Scroll. + * @tc.type: FUNC + */ +HWTEST_F(ScrollLayoutTestNg, OnThemeScopeUpdate001, TestSize.Level1) +{ + int32_t apiTargetVersion = Container::Current()->GetApiTargetVersion(); + Container::Current()->SetApiTargetVersion(static_cast(PlatformVersion::VERSION_TWENTY)); + + ScrollModelNG model = CreateScroll(); + model.SetScrollBarColor(Color::GREEN); + CreateScrollDone(); + + ASSERT_NE(frameNode_, nullptr); + ASSERT_NE(pattern_, nullptr); + EXPECT_FALSE(pattern_->OnThemeScopeUpdate(frameNode_->GetThemeScopeId())); + paintProperty_->ResetScrollBarColor(); + EXPECT_TRUE(pattern_->OnThemeScopeUpdate(frameNode_->GetThemeScopeId())); + + Container::Current()->SetApiTargetVersion(apiTargetVersion); +} + +/** + * @tc.name: ScrollThemeWrapperTest001 + * @tc.desc: Test Builder fuction of ScrollThemeWrapper. + * @tc.type: FUNC + */ +HWTEST_F(ScrollLayoutTestNg, ScrollThemeWrapperTest001, TestSize.Level1) +{ + int32_t apiTargetVersion = Container::Current()->GetApiTargetVersion(); + Container::Current()->SetApiTargetVersion(static_cast(PlatformVersion::VERSION_TWENTY)); + + auto themeConstants = CreateThemeConstants(THEME_PATTERN_SCROLL_BAR); + ASSERT_NE(themeConstants, nullptr); + auto scrollThemeWrapper = ScrollThemeWrapper::WrapperBuilder().BuildWrapper(themeConstants); + EXPECT_NE(scrollThemeWrapper, nullptr); + auto scrollTheme = AceType::DynamicCast(scrollThemeWrapper); + ASSERT_NE(scrollTheme, nullptr); + + std::vector colors; + TestProperty testProperty; + colors.reserve(TokenColors::TOTAL_NUMBER); + for (int i = 0; i < TokenColors::TOTAL_NUMBER; i++) { + colors.push_back(Color(testProperty.colors_[i])); + } + auto themeColors = AceType::MakeRefPtr(); + themeColors->SetColors(std::move(colors)); + testProperty.tokenColors_ = themeColors; + auto tokenTheme = AceType::MakeRefPtr(TOKEN_THEME_ID); + + EXPECT_NE(scrollTheme->GetForegroundColor(), colors[TokenColors::COMP_FOCUSED_TERTIARY]); + + tokenTheme->SetColors(testProperty.tokenColors_); + ASSERT_NE(tokenTheme, nullptr); + scrollThemeWrapper->ApplyTokenTheme(*tokenTheme); + EXPECT_EQ(scrollTheme->GetForegroundColor(), colors[TokenColors::COMP_FOCUSED_TERTIARY]); + + Container::Current()->SetApiTargetVersion(apiTargetVersion); +} } // namespace OHOS::Ace::NG diff --git a/test/unittest/core/pattern/scroll/scroll_test_ng.h b/test/unittest/core/pattern/scroll/scroll_test_ng.h index 529fba3894516501756394bde3292d1eed7de350..8f71d018ac6e7d58c9db4acd432f3d186268071d 100644 --- a/test/unittest/core/pattern/scroll/scroll_test_ng.h +++ b/test/unittest/core/pattern/scroll/scroll_test_ng.h @@ -24,6 +24,9 @@ #include "core/components_ng/pattern/scroll/scroll_model_ng.h" #include "core/components_ng/pattern/scroll/scroll_pattern.h" +#include "core/components_ng/pattern/scroll/scroll_theme_wrapper.h" +#include "core/components_ng/token_theme/token_theme_storage.h" +#include "core/interfaces/arkoala/arkoala_api.h" namespace OHOS::Ace::NG { constexpr float DEFAULT_ACTIVE_WIDTH = 8.0f; @@ -35,6 +38,65 @@ constexpr float NORMAL_WIDTH = 4.f; constexpr float SCROLL_PAGING_SPEED_THRESHOLD = 1200.0f; constexpr float BAR_WIDTH = 10.f; constexpr char SCROLL_BAR_COLOR[] = "#66182431"; +constexpr uint32_t TOKEN_THEME_ID = 10001; + +struct TestProperty { + const ArkUI_Uint32 colors_[TokenColors::TOTAL_NUMBER] = { + // id for color value for test + 125830976, /* BRAND = 0 */ + 125830979, /* WARNING = 1; */ + 125830980, /* ALERT = 2 */ + 125830981, /* CONFIRM = 3 */ + 125830982, /* FONT_PRIMARY = 4 */ + 125830983, /* FONT_SECONDARY = 5 */ + 125830984, /* FONT_TERTIARY = 6 */ + 125830985, /* FONT_FOURTH = 7 */ + 125830986, /* FONT_EMPHASIZE = 8 */ + 125830987, /* FONT_ON_PRIMARY = 9 */ + 125830988, /* FONT_ON_SECONDARY = 10 */ + 125830989, /* FONT_ON_TERTIARY = 11 */ + 125830990, /* FONT_ON_FOURTH = 12 */ + 125830991, /* ICON_PRIMARY = 13 */ + 125830992, /* ICON_SECONDARY = 14 */ + 125830993, /* ICON_TERTIARY = 15 */ + 125830994, /* ICON_FOURTH = 16 */ + 125830995, /* ICON_EMPHASIZE = 17 */ + 125830996, /* ICON_SUB_EMPHASIZE = 18 */ + 125831057, /* ICON_ON_PRIMARY = 19 */ + 125831058, /* ICON_ON_SECONDARY = 20 */ + 125831059, /* ICON_ON_TERTIARY = 21 */ + 125831060, /* ICON_ON_FOURTH = 22 */ + 125831061, /* BACKGROUND_PRIMARY = 23 */ + 125831062, /* BACKGROUND_SECONDARY = 24 */ + 125831063, /* BACKGROUND_TERTIARY = 25 */ + 125831064, /* BACKGROUND_FOURTH = 26 */ + 125831065, /* BACKGROUND_EMPHASIZE = 27 */ + 125831003, /* COMP_FOREGROUND_PRIMARY = 28 */ + 125831004, /* COMP_BACKGROUND_PRIMARY = 29 */ + -1, /* COMP_BACKGROUND_PRIMARY_TRAN = 30 */ + 125831005, /* COMP_BACKGROUND_PRIMARY_CONTRARY = 31 */ + 125831006, /* COMP_BACKGROUND_GRAY = 32 */ + 125831007, /* COMP_BACKGROUND_SECONDARY = 33 */ + 125831008, /* COMP_BACKGROUND_TERTIARY = 34 */ + 125831009, /* COMP_BACKGROUND_EMPHASIZE = 35 */ + 125831066, /* COMP_BACKGROUND_NEUTRAL = 36 */ + 125831011, /* COMP_EMPHASIZE_SECONDARY = 37 */ + 125831012, /* COMP_EMPHASIZE_TERTIARY = 38 */ + 125831013, /* COMP_DIVIDER = 39 */ + 125831014, /* COMP_COMMON_CONTRARY = 40 */ + 125831015, /* COMP_BACKGROUND_FOCUS = 41 */ + 125831016, /* COMP_FOCUSED_PRIMARY = 42 */ + 125831017, /* COMP_FOCUSED_SECONDARY = 43 */ + 125831018, /* COMP_FOCUSED_TERTIARY = 44 */ + 125831019, /* INTERACTIVE_HOVER = 45 */ + 125831020, /* INTERACTIVE_PRESSED = 46 */ + 125831021, /* INTERACTIVE_FOCUS = 47 */ + 125831022, /* INTERACTIVE_ACTIVE = 48 */ + 125831023, /* INTERACTIVE_SELECT = 49 */ + 125831024, /* INTERACTIVE_CLICK = 50 */ + }; + RefPtr tokenColors_; +}; class ScrollTestNg : public ScrollableUtilsTestNG { public: