From 4a20b3c2a15224e342f54e329e03596611bdcba8 Mon Sep 17 00:00:00 2001 From: Vladislav Kondratyev Date: Mon, 14 Oct 2024 09:15:32 +0300 Subject: [PATCH] Create ThemeWrapper for DataPanel --- .../src/theme/ArkThemeWhiteList.ts | 1 - .../declarative_frontend/engine/arkTheme.js | 1 - .../jsview/js_data_panel.cpp | 2 - .../components/data_panel/data_panel_theme.h | 6 +- .../components/theme/theme_manager_impl.cpp | 2 + .../data_panel/data_panel_paint_method.cpp | 3 +- .../data_panel/data_panel_paint_property.h | 1 + .../pattern/data_panel/data_panel_pattern.cpp | 10 +++- .../pattern/data_panel/data_panel_pattern.h | 1 + .../data_panel/data_panel_theme_wrapper.h} | 60 ++++++++++--------- 10 files changed, 51 insertions(+), 36 deletions(-) rename frameworks/{bridge/declarative_frontend/ark_theme/theme_apply/js_data_panel_theme.h => core/components_ng/pattern/data_panel/data_panel_theme_wrapper.h} (30%) 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 73469ec31f9e..be6112ddcfee 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 @@ -22,7 +22,6 @@ class ArkThemeWhiteList { private static whiteList: Array = [ 'Badge', 'Counter', - 'DataPanel', 'DatePicker', 'Menu', 'MenuItem', diff --git a/frameworks/bridge/declarative_frontend/engine/arkTheme.js b/frameworks/bridge/declarative_frontend/engine/arkTheme.js index 424742e1d3c9..14abe57d5076 100644 --- a/frameworks/bridge/declarative_frontend/engine/arkTheme.js +++ b/frameworks/bridge/declarative_frontend/engine/arkTheme.js @@ -1076,7 +1076,6 @@ class ArkThemeWhiteList { ArkThemeWhiteList.whiteList = [ 'Badge', 'Counter', - 'DataPanel', 'DatePicker', 'Menu', 'MenuItem', diff --git a/frameworks/bridge/declarative_frontend/jsview/js_data_panel.cpp b/frameworks/bridge/declarative_frontend/jsview/js_data_panel.cpp index d7e0af7d7fa5..2c106d849534 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_data_panel.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_data_panel.cpp @@ -22,7 +22,6 @@ #include "bridge/declarative_frontend/jsview/js_utils.h" #include "bridge/declarative_frontend/jsview/js_view_abstract.h" #include "bridge/declarative_frontend/jsview/models/data_panel_model_impl.h" -#include "bridge/declarative_frontend/ark_theme/theme_apply/js_data_panel_theme.h" #include "core/components/data_panel/data_panel_theme.h" #include "core/components_ng/base/view_abstract_model.h" #include "core/components_ng/pattern/data_panel/data_panel_model_ng.h" @@ -131,7 +130,6 @@ void JSDataPanel::Create(const JSCallbackInfo& info) } dataPanelType_ = dataPanelType; DataPanelModel::GetInstance()->Create(dateValues, max, dataPanelType); - JSDataPanelTheme::ApplyTheme(); } void JSDataPanel::CloseEffect(const JSCallbackInfo& info) diff --git a/frameworks/core/components/data_panel/data_panel_theme.h b/frameworks/core/components/data_panel/data_panel_theme.h index 269871c52381..8d789038c79e 100644 --- a/frameworks/core/components/data_panel/data_panel_theme.h +++ b/frameworks/core/components/data_panel/data_panel_theme.h @@ -42,7 +42,7 @@ public: return theme; } - private: + protected: void ParsePattern(const RefPtr& themeConstants, const RefPtr& theme) const { RefPtr dataPanelPattern = themeConstants->GetPatternByName(THEME_PATTERN_DATA_PANEL); @@ -152,11 +152,11 @@ public: } protected: -private: std::vector> percentageColors_; + Color backgroundColor_; +private: std::pair loadingColors_; std::pair progressColors_; - Color backgroundColor_; Dimension defaultHeight_; Dimension defaultWidth_; Dimension defaultBorderRadius_; diff --git a/frameworks/core/components/theme/theme_manager_impl.cpp b/frameworks/core/components/theme/theme_manager_impl.cpp index fd37082614df..a4ee5f80e61d 100644 --- a/frameworks/core/components/theme/theme_manager_impl.cpp +++ b/frameworks/core/components/theme/theme_manager_impl.cpp @@ -77,6 +77,7 @@ #include "core/components_ng/pattern/button/button_theme_wrapper.h" #include "core/components_ng/pattern/checkbox/checkbox_theme_wrapper.h" #include "core/components_ng/pattern/divider/divider_theme_wrapper.h" +#include "core/components_ng/pattern/data_panel/data_panel_theme_wrapper.h" #include "core/components_v2/pattern_lock/pattern_lock_theme_wrapper.h" #include "core/components_ng/pattern/indexer/indexer_theme_wrapper.h" #include "core/components_ng/pattern/progress/progress_theme_wrapper.h" @@ -176,6 +177,7 @@ const std::unordered_map(*)(const RefPt { CheckboxTheme::TypeId(), &ThemeWrapperBuildFunc }, { IndexerTheme::TypeId(), &ThemeWrapperBuildFunc }, { DividerTheme::TypeId(), &ThemeWrapperBuildFunc }, + { DataPanelTheme::TypeId(), &ThemeWrapperBuildFunc }, { V2::PatternLockTheme::TypeId(), &ThemeWrapperBuildFunc }, { ProgressTheme::TypeId(), &ThemeWrapperBuildFunc }, { QrcodeTheme::TypeId(), &ThemeWrapperBuildFunc }, diff --git a/frameworks/core/components_ng/pattern/data_panel/data_panel_paint_method.cpp b/frameworks/core/components_ng/pattern/data_panel/data_panel_paint_method.cpp index b9948379cdb4..9675b1fadd59 100644 --- a/frameworks/core/components_ng/pattern/data_panel/data_panel_paint_method.cpp +++ b/frameworks/core/components_ng/pattern/data_panel/data_panel_paint_method.cpp @@ -29,7 +29,8 @@ void DataPanelPaintMethod::UpdateContentModifier(PaintWrapper* paintWrapper) auto paintProperty = DynamicCast(paintWrapper->GetPaintProperty()); auto pipelineContext = PipelineBase::GetCurrentContext(); CHECK_NULL_VOID(pipelineContext); - auto theme = pipelineContext->GetTheme(); + auto host = paintWrapper->GetRenderContext() ? paintWrapper->GetRenderContext()->GetUnsafeHost() : nullptr; + auto theme = pipelineContext->GetTheme(host ? host->GetThemeScopeId() : 0); auto values_ = paintProperty->GetValues().value(); auto max_ = paintProperty->GetMax().value_or(DEFAULT_MAX_VALUE); diff --git a/frameworks/core/components_ng/pattern/data_panel/data_panel_paint_property.h b/frameworks/core/components_ng/pattern/data_panel/data_panel_paint_property.h index 43389e607e59..b699ad6603e7 100644 --- a/frameworks/core/components_ng/pattern/data_panel/data_panel_paint_property.h +++ b/frameworks/core/components_ng/pattern/data_panel/data_panel_paint_property.h @@ -108,6 +108,7 @@ public: ToJsonTrackShadow(json, filter); } +private: void ToJsonValueColors(std::unique_ptr& json, const InspectorFilter& filter) const { /* no fixed attr below, just return */ diff --git a/frameworks/core/components_ng/pattern/data_panel/data_panel_pattern.cpp b/frameworks/core/components_ng/pattern/data_panel/data_panel_pattern.cpp index dfccf78fbdda..87b1599f3325 100644 --- a/frameworks/core/components_ng/pattern/data_panel/data_panel_pattern.cpp +++ b/frameworks/core/components_ng/pattern/data_panel/data_panel_pattern.cpp @@ -82,6 +82,15 @@ void DataPanelPattern::OnModifyDone() } } +bool DataPanelPattern::OnThemeScopeUpdate(int32_t themeScopeId) { + auto host = GetHost(); + CHECK_NULL_RETURN(host, false); + auto paintProperty = host->GetPaintProperty(); + CHECK_NULL_RETURN(paintProperty, false); + + return !paintProperty->HasValueColors() || !paintProperty->HasTrackBackground(); +} + void DataPanelPattern::FireBuilder() { auto host = GetHost(); @@ -107,7 +116,6 @@ RefPtr DataPanelPattern::BuildContentModifierNode() CHECK_NULL_RETURN(host, nullptr); auto paintProperty = host->GetPaintProperty(); CHECK_NULL_RETURN(paintProperty, nullptr); - auto geometryNode = host->GetGeometryNode(); std::vector tmpArry; if (paintProperty->GetValues().value().size() > 0) { diff --git a/frameworks/core/components_ng/pattern/data_panel/data_panel_pattern.h b/frameworks/core/components_ng/pattern/data_panel/data_panel_pattern.h index fb2fe276a28c..9eb4d3c94884 100644 --- a/frameworks/core/components_ng/pattern/data_panel/data_panel_pattern.h +++ b/frameworks/core/components_ng/pattern/data_panel/data_panel_pattern.h @@ -61,6 +61,7 @@ public: makeFunc_ = std::move(makeFunc); } + bool OnThemeScopeUpdate(int32_t themeScopeId) override; bool UseContentModifier() { return contentModifierNode_ != nullptr; diff --git a/frameworks/bridge/declarative_frontend/ark_theme/theme_apply/js_data_panel_theme.h b/frameworks/core/components_ng/pattern/data_panel/data_panel_theme_wrapper.h similarity index 30% rename from frameworks/bridge/declarative_frontend/ark_theme/theme_apply/js_data_panel_theme.h rename to frameworks/core/components_ng/pattern/data_panel/data_panel_theme_wrapper.h index 16960a9249b5..536d4e8443bb 100644 --- a/frameworks/bridge/declarative_frontend/ark_theme/theme_apply/js_data_panel_theme.h +++ b/frameworks/core/components_ng/pattern/data_panel/data_panel_theme_wrapper.h @@ -13,37 +13,43 @@ * limitations under the License. */ -#ifndef FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_THEME_JS_DATA_PANEL_THEME_H -#define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_THEME_JS_DATA_PANEL_THEME_H +#ifndef FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_DATA_PANEL_DATA_PANEL_THEME_WRAPPER_H +#define FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_DATA_PANEL_DATA_PANEL_THEME_WRAPPER_H -#include "bridge/declarative_frontend/ark_theme/theme_apply/js_theme_utils.h" -#include "core/components_ng/pattern/data_panel/data_panel_model.h" +#include "core/components/data_panel/data_panel_theme.h" +#include "core/components_ng/token_theme/token_theme_wrapper.h" -namespace OHOS::Ace::Framework { -class JSDataPanelTheme { +namespace OHOS::Ace::NG { + +class DataPanelThemeWrapper : public DataPanelTheme, public TokenThemeWrapper { + DECLARE_ACE_TYPE(DataPanelThemeWrapper, DataPanelTheme); +protected: + DataPanelThemeWrapper() = default; public: - static void ApplyTheme() - { - auto themeColors = JSThemeUtils::GetThemeColors(); - if (!themeColors) { - // no need to apply custom theme colors - return; + ~DataPanelThemeWrapper() override = default; + + class WrapperBuilder : public Builder { + public: + WrapperBuilder() = default; + ~WrapperBuilder() = default; + + RefPtr BuildWrapper(const RefPtr& themeConstants) const { + RefPtr wrapper = AceType::Claim(new DataPanelThemeWrapper()); + if (themeConstants) { + ParsePattern(themeConstants, AceType::DynamicCast(wrapper)); + } + return wrapper; } + }; - std::vector valueColors; - OHOS::Ace::NG::Gradient gradient; - OHOS::Ace::NG::GradientColor gradientColorStart; - gradientColorStart.SetLinearColor(LinearColor(themeColors->CompBackgroundEmphasize())); - gradientColorStart.SetDimension(Dimension(0.0)); - gradient.AddColor(gradientColorStart); - OHOS::Ace::NG::GradientColor gradientColorEnd; - gradientColorEnd.SetLinearColor(LinearColor(themeColors->CompBackgroundEmphasize())); - gradientColorEnd.SetDimension(Dimension(1.0)); - gradient.AddColor(gradientColorEnd); - valueColors.emplace_back(gradient); - DataPanelModel::GetInstance()->SetValueColors(valueColors); - DataPanelModel::GetInstance()->SetTrackBackground(themeColors->CompBackgroundTertiary()); + void ApplyTokenTheme(const TokenTheme& theme) override { + if (auto colors = theme.Colors(); colors) { + percentageColors_.clear(); + percentageColors_.emplace_back(colors->CompBackgroundEmphasize(), colors->CompBackgroundEmphasize()); + backgroundColor_ = colors->CompBackgroundTertiary(); + } } }; -} // namespace OHOS::Ace::Framework -#endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_THEME_JS_DATA_PANEL_THEME_H \ No newline at end of file + +} // OHOS::Ace::NG +#endif -- Gitee