From baaaf94595784bc7dd7b5fff9a67241d8e063938 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E9=A3=9E?= Date: Sun, 15 Sep 2024 17:34:37 +0800 Subject: [PATCH 1/2] Create ArkThemeWrapper for scroll MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡飞 --- .../ark_theme/theme_apply/js_scroll_theme.h | 37 ---------- .../src/theme/ArkThemeWhiteList.ts | 1 - .../declarative_frontend/engine/arkTheme.js | 1 - .../declarative_frontend/jsview/js_scroll.cpp | 7 +- .../jsview/models/scroll_model_impl.h | 1 + .../core/components/scroll/scroll_bar_theme.h | 3 +- .../components/theme/theme_manager_impl.cpp | 2 + .../pattern/scroll/scroll_model.h | 1 + .../pattern/scroll/scroll_model_ng.cpp | 5 ++ .../pattern/scroll/scroll_model_ng.h | 1 + .../pattern/scroll/scroll_pattern.cpp | 19 +++++ .../pattern/scroll/scroll_pattern.h | 1 + .../pattern/scroll/scroll_theme_wrapper.h | 74 +++++++++++++++++++ .../scrollable/scrollable_paint_property.cpp | 8 +- .../pattern/scrollable/scrollable_pattern.cpp | 2 +- 15 files changed, 116 insertions(+), 47 deletions(-) delete mode 100644 frameworks/bridge/declarative_frontend/ark_theme/theme_apply/js_scroll_theme.h create mode 100644 frameworks/core/components_ng/pattern/scroll/scroll_theme_wrapper.h 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 deleted file mode 100644 index a671c686be6a..000000000000 --- a/frameworks/bridge/declarative_frontend/ark_theme/theme_apply/js_scroll_theme.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2024 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_BRIDGE_DECLARATIVE_FRONTEND_THEME_JS_INDEXER_THEME_H -#define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_THEME_JS_INDEXER_THEME_H - -#include "bridge/declarative_frontend/ark_theme/theme_apply/js_theme_utils.h" -#include "core/components_ng/pattern/scroll/scroll_model.h" - -namespace OHOS::Ace::Framework { -class JSScrollTheme { -public: - static void ApplyTheme() - { - auto themeColors = JSThemeUtils::GetThemeColors(); - if (!themeColors) { - // no need to apply custom theme colors - return; - } - - ScrollModel::GetInstance()->SetScrollBarColor(themeColors->CompFocusedTertiary()); - } -}; -} // namespace OHOS::Ace::Framework -#endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_THEME_JS_INDEXER_THEME_H \ No newline at end of file diff --git a/frameworks/bridge/declarative_frontend/ark_theme/theme_manager/src/theme/ArkThemeWhiteList.ts b/frameworks/bridge/declarative_frontend/ark_theme/theme_manager/src/theme/ArkThemeWhiteList.ts index 89f4eef4ec04..7a6c9c8a1fac 100644 --- a/frameworks/bridge/declarative_frontend/ark_theme/theme_manager/src/theme/ArkThemeWhiteList.ts +++ b/frameworks/bridge/declarative_frontend/ark_theme/theme_manager/src/theme/ArkThemeWhiteList.ts @@ -28,7 +28,6 @@ class ArkThemeWhiteList { 'Divider', 'Menu', 'MenuItem', - 'Scroll', 'Search', 'Select', 'Slider', diff --git a/frameworks/bridge/declarative_frontend/engine/arkTheme.js b/frameworks/bridge/declarative_frontend/engine/arkTheme.js index 8e792324e8a9..c7120003b362 100644 --- a/frameworks/bridge/declarative_frontend/engine/arkTheme.js +++ b/frameworks/bridge/declarative_frontend/engine/arkTheme.js @@ -1082,7 +1082,6 @@ ArkThemeWhiteList.whiteList = [ 'Divider', 'Menu', 'MenuItem', - 'Scroll', 'Search', 'Select', 'Slider', diff --git a/frameworks/bridge/declarative_frontend/jsview/js_scroll.cpp b/frameworks/bridge/declarative_frontend/jsview/js_scroll.cpp index dd2d8372993c..71edefb5f210 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_scroll.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_scroll.cpp @@ -28,7 +28,6 @@ #include "core/components/scroll/scrollable.h" #include "core/components_ng/pattern/scroll/inner/scroll_bar.h" #include "core/components_ng/pattern/scroll/scroll_model_ng.h" -#include "bridge/declarative_frontend/ark_theme/theme_apply/js_scroll_theme.h" namespace OHOS::Ace { @@ -118,7 +117,6 @@ void JSScroll::Create(const JSCallbackInfo& info) std::pair barWidth; barWidth.first = false; ScrollModel::GetInstance()->InitScrollBar(GetTheme(), barColor, barWidth, EdgeEffect::NONE); - JSScrollTheme::ApplyTheme(); } void JSScroll::SetScrollable(int32_t value) @@ -425,7 +423,10 @@ 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)) { + 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 e6203002f023..30255da51f12 100644 --- a/frameworks/bridge/declarative_frontend/jsview/models/scroll_model_impl.h +++ b/frameworks/bridge/declarative_frontend/jsview/models/scroll_model_impl.h @@ -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) 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 19eeee947690..3801ae1daa97 100644 --- a/frameworks/core/components/scroll/scroll_bar_theme.h +++ b/frameworks/core/components/scroll/scroll_bar_theme.h @@ -46,7 +46,6 @@ public: return theme; } - private: void ParsePattern(const RefPtr& themeConstants, const RefPtr& theme) const { RefPtr pattern = themeConstants->GetPatternByName(THEME_PATTERN_SCROLL_BAR); @@ -142,6 +141,7 @@ public: protected: ScrollBarTheme() = default; + Color foregroundColor_; private: ShapeMode shapeMode_ = ShapeMode::DEFAULT; @@ -155,7 +155,6 @@ private: Dimension defaultWidth_; Dimension defaultHeight_; Color backgroundColor_; - Color foregroundColor_; Edge padding_; }; diff --git a/frameworks/core/components/theme/theme_manager_impl.cpp b/frameworks/core/components/theme/theme_manager_impl.cpp index bba59713a461..e8d3fffc3bfb 100644 --- a/frameworks/core/components/theme/theme_manager_impl.cpp +++ b/frameworks/core/components/theme/theme_manager_impl.cpp @@ -80,6 +80,7 @@ #include "core/components_ng/pattern/progress/progress_theme_wrapper.h" #include "core/components_ng/pattern/qrcode/qrcode_theme_wrapper.h" #include "core/components_ng/pattern/radio/radio_theme_wrapper.h" +#include "core/components_ng/pattern/scroll/scroll_theme_wrapper.h" #include "core/components_ng/pattern/swiper/swiper_theme_wrapper.h" #include "core/components_ng/pattern/text/text_theme_wrapper.h" #include "core/components_ng/token_theme/token_theme_storage.h" @@ -172,6 +173,7 @@ const std::unordered_map(*)(const RefPt { ProgressTheme::TypeId(), &ThemeWrapperBuildFunc }, { QrcodeTheme::TypeId(), &ThemeWrapperBuildFunc }, { RadioTheme::TypeId(), &ThemeWrapperBuildFunc }, + { ScrollBarTheme::TypeId(), &ThemeWrapperBuildFunc }, { SwiperIndicatorTheme::TypeId(), &ThemeWrapperBuildFunc }, { TextTheme::TypeId(), &ThemeWrapperBuildFunc } }; diff --git a/frameworks/core/components_ng/pattern/scroll/scroll_model.h b/frameworks/core/components_ng/pattern/scroll/scroll_model.h index 865182d79341..b2afcb671ec3 100644 --- a/frameworks/core/components_ng/pattern/scroll/scroll_model.h +++ b/frameworks/core/components_ng/pattern/scroll/scroll_model.h @@ -54,6 +54,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() {}; virtual void SetEdgeEffect(EdgeEffect edgeEffect, bool alwaysEnabled) = 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 683aafa5a2a9..529a33437080 100644 --- a/frameworks/core/components_ng/pattern/scroll/scroll_model_ng.cpp +++ b/frameworks/core/components_ng/pattern/scroll/scroll_model_ng.cpp @@ -395,6 +395,11 @@ void ScrollModelNG::SetScrollBarColor(const Color& color) ACE_UPDATE_PAINT_PROPERTY(ScrollablePaintProperty, ScrollBarColor, 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); 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 d4b15d58d9f2..b0c7b7c1c60c 100644 --- a/frameworks/core/components_ng/pattern/scroll/scroll_model_ng.h +++ b/frameworks/core/components_ng/pattern/scroll/scroll_model_ng.h @@ -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) override; void SetHasWidth(bool hasWidth) override {} void SetHasHeight(bool hasHeight) override {} diff --git a/frameworks/core/components_ng/pattern/scroll/scroll_pattern.cpp b/frameworks/core/components_ng/pattern/scroll/scroll_pattern.cpp index d4a2ff8054d1..0b704216f4e7 100644 --- a/frameworks/core/components_ng/pattern/scroll/scroll_pattern.cpp +++ b/frameworks/core/components_ng/pattern/scroll/scroll_pattern.cpp @@ -1344,4 +1344,23 @@ void ScrollPattern::DumpAdvanceInfo(std::unique_ptr& json) } json->Put("scrollMeasureInfos", infochildren); } + +bool ScrollPattern::OnThemeScopeUpdate(int32_t themeScopeId) { + bool result = false; + 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 9a8b258d6d51..c02a8a41e5ce 100644 --- a/frameworks/core/components_ng/pattern/scroll/scroll_pattern.h +++ b/frameworks/core/components_ng/pattern/scroll/scroll_pattern.h @@ -169,6 +169,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 000000000000..b8faf9687f7f --- /dev/null +++ b/frameworks/core/components_ng/pattern/scroll/scroll_theme_wrapper.h @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2024 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/checkable/checkable_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() = 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 (auto themeColors = theme.Colors(); themeColors) { + foregroundColor_ = themeColors->CompFocusedTertiary(); + return; + } + } + + const Color& GetForegroundColor() const override + { + return foregroundColor_; + } + +protected: + ScrollThemeWrapper() = default; +}; + +} // namespace +#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 d578d2eb2900..b956baab0972 100644 --- a/frameworks/core/components_ng/pattern/scrollable/scrollable_paint_property.cpp +++ b/frameworks/core/components_ng/pattern/scrollable/scrollable_paint_property.cpp @@ -43,11 +43,13 @@ void ScrollablePaintProperty::ToJsonValue(std::unique_ptr& json, cons Color ScrollablePaintProperty::GetBarColor() const { + auto host = GetHost(); + CHECK_NULL_RETURN(host, Color::TRANSPARENT); auto context = PipelineContext::GetCurrentContext(); CHECK_NULL_RETURN(context, Color::TRANSPARENT); auto themeManager = context->GetThemeManager(); CHECK_NULL_RETURN(themeManager, Color::TRANSPARENT); - auto scrollBarTheme = themeManager->GetTheme(); + auto scrollBarTheme = themeManager->GetTheme(host->GetThemeScopeId()); CHECK_NULL_RETURN(scrollBarTheme, Color::TRANSPARENT); auto defaultScrollBarColor = scrollBarTheme->GetForegroundColor(); return propScrollBarProperty_ ? propScrollBarProperty_->propScrollBarColor.value_or(defaultScrollBarColor) @@ -56,11 +58,13 @@ Color ScrollablePaintProperty::GetBarColor() const Dimension ScrollablePaintProperty::GetBarWidth() const { + auto host = GetHost(); + CHECK_NULL_RETURN(host, Dimension()); auto context = PipelineContext::GetCurrentContext(); CHECK_NULL_RETURN(context, Dimension()); auto themeManager = context->GetThemeManager(); CHECK_NULL_RETURN(themeManager, Dimension()); - auto scrollBarTheme = themeManager->GetTheme(); + auto scrollBarTheme = themeManager->GetTheme(host->GetThemeScopeId()); 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 6b346aea80bc..76076e0da787 100644 --- a/frameworks/core/components_ng/pattern/scrollable/scrollable_pattern.cpp +++ b/frameworks/core/components_ng/pattern/scrollable/scrollable_pattern.cpp @@ -962,7 +962,7 @@ void ScrollablePattern::SetScrollBar(const std::unique_ptr& p } else { auto pipelineContext = GetContext(); CHECK_NULL_VOID(pipelineContext); - auto theme = pipelineContext->GetTheme(); + auto theme = pipelineContext->GetTheme(GetThemeScopeId()); CHECK_NULL_VOID(theme); scrollBar_->SetForegroundColor(theme->GetForegroundColor()); scrollBar_->SetBackgroundColor(theme->GetBackgroundColor()); -- Gitee From 78cd94d3ef1669d8cf451b28be1e7a3442a4da25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E9=A3=9E?= Date: Wed, 18 Sep 2024 08:38:33 +0000 Subject: [PATCH 2/2] update frameworks/core/components_ng/pattern/scrollable/scrollable_paint_property.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡飞 --- .../pattern/scrollable/scrollable_paint_property.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 b956baab0972..f337ef8758dc 100644 --- a/frameworks/core/components_ng/pattern/scrollable/scrollable_paint_property.cpp +++ b/frameworks/core/components_ng/pattern/scrollable/scrollable_paint_property.cpp @@ -64,7 +64,7 @@ Dimension ScrollablePaintProperty::GetBarWidth() const CHECK_NULL_RETURN(context, Dimension()); auto themeManager = context->GetThemeManager(); CHECK_NULL_RETURN(themeManager, Dimension()); - auto scrollBarTheme = themeManager->GetTheme(host->GetThemeScopeId()); + auto scrollBarTheme = themeManager->GetTheme(); CHECK_NULL_RETURN(scrollBarTheme, Dimension()); auto defaultScrollBarWidth = scrollBarTheme->GetNormalWidth(); return propScrollBarProperty_ ? propScrollBarProperty_->propScrollBarWidth.value_or(defaultScrollBarWidth) -- Gitee