diff --git a/frameworks/bridge/declarative_frontend/ark_theme/theme_apply/js_divider_theme.h b/frameworks/bridge/declarative_frontend/ark_theme/theme_apply/js_divider_theme.h deleted file mode 100644 index e965008ccee7813c0c53820080dc340c9f32a9ed..0000000000000000000000000000000000000000 --- a/frameworks/bridge/declarative_frontend/ark_theme/theme_apply/js_divider_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_DIVIDER_THEME_H -#define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_THEME_JS_DIVIDER_THEME_H - -#include "bridge/declarative_frontend/ark_theme/theme_apply/js_theme_utils.h" -#include "core/components_ng/pattern/divider/divider_model.h" - -namespace OHOS::Ace::Framework { -class JSDividerTheme { -public: - static void ApplyTheme() - { - auto themeColors = JSThemeUtils::GetThemeColors(); - if (!themeColors) { - return; - } - - DividerModel::GetInstance()->DividerColor(themeColors->CompDivider()); - } -}; -} - -#endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_THEME_JS_DIVIDER_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 89f4eef4ec041e1d7a12ee0d3da40283933595c8..038f9f4c88c657cf69b34572111e00f15a55158b 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 @@ -25,7 +25,6 @@ class ArkThemeWhiteList { 'Counter', 'DataPanel', 'DatePicker', - 'Divider', 'Menu', 'MenuItem', 'Scroll', diff --git a/frameworks/bridge/declarative_frontend/engine/arkTheme.js b/frameworks/bridge/declarative_frontend/engine/arkTheme.js index b957db8cc0d1fb049efc0708a6439666f2935e0e..79592034f0cbc6681b36f8e643d77106ebe07dde 100644 --- a/frameworks/bridge/declarative_frontend/engine/arkTheme.js +++ b/frameworks/bridge/declarative_frontend/engine/arkTheme.js @@ -1122,7 +1122,6 @@ ArkThemeWhiteList.whiteList = [ 'Counter', 'DataPanel', 'DatePicker', - 'Divider', 'Menu', 'MenuItem', 'Scroll', diff --git a/frameworks/bridge/declarative_frontend/jsview/js_divider.cpp b/frameworks/bridge/declarative_frontend/jsview/js_divider.cpp index 61f0cf07bfe1ba75197a2c34c2052cd7bd9aac79..7f72af87a7ee2a78ad400909a5dad1f6404e0a99 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_divider.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_divider.cpp @@ -17,7 +17,6 @@ #include "base/geometry/dimension.h" #include "bridge/declarative_frontend/jsview/models/divider_model_impl.h" -#include "bridge/declarative_frontend/ark_theme/theme_apply/js_divider_theme.h" #include "core/components/divider/divider_theme.h" #include "core/components_ng/pattern/divider/divider_model_ng.h" #include "core/pipeline/pipeline_base.h" @@ -52,7 +51,6 @@ namespace OHOS::Ace::Framework { void JSDivider::Create() { DividerModel::GetInstance()->Create(); - JSDividerTheme::ApplyTheme(); } void JSDivider::SetVertical(bool isVertical) @@ -83,7 +81,10 @@ void JSDivider::SetDividerColor(const JSCallbackInfo& info) auto theme = GetTheme(); CHECK_NULL_VOID(theme); Color dividerColor = theme->GetColor(); - ParseJsColor(info[0], dividerColor); + if(!ParseJsColor(info[0], dividerColor)){ + DividerModel::GetInstance()->ResetDividerColor(); + return; + } DividerModel::GetInstance()->DividerColor(dividerColor); } diff --git a/frameworks/bridge/declarative_frontend/jsview/models/divider_model_impl.h b/frameworks/bridge/declarative_frontend/jsview/models/divider_model_impl.h index 8fa976e2d4695118ec2fe010ab20feaced896946..5983c87bce3bbb0f3cc556ab321f01e5be8cbeab 100644 --- a/frameworks/bridge/declarative_frontend/jsview/models/divider_model_impl.h +++ b/frameworks/bridge/declarative_frontend/jsview/models/divider_model_impl.h @@ -27,6 +27,7 @@ public: void DividerColor(const Color& value) override; void StrokeWidth(const Dimension& value) override; void LineCap(const enum LineCap& value) override; + void ResetDividerColor() override {}; }; } // namespace OHOS::Ace::Framework diff --git a/frameworks/core/components/divider/divider_theme.h b/frameworks/core/components/divider/divider_theme.h index 64d8621b1b782bf07a1e2df824ac47a32ea37126..1864919a3b563596936e3d5f9756d3ea2ef8d2d5 100644 --- a/frameworks/core/components/divider/divider_theme.h +++ b/frameworks/core/components/divider/divider_theme.h @@ -51,7 +51,7 @@ public: ~DividerTheme() override = default; - const Color& GetColor() const + virtual const Color& GetColor() const { return color_; } @@ -63,10 +63,9 @@ public: protected: DividerTheme() = default; - -private: Color color_; Dimension stokeWidth_; + }; } // namespace OHOS::Ace diff --git a/frameworks/core/components/theme/theme_manager_impl.cpp b/frameworks/core/components/theme/theme_manager_impl.cpp index 74161f386e1dcf3e2593afee4b812d65b9b7ee30..908812625d3934c2a6e70ec65c1648ace2a08c15 100644 --- a/frameworks/core/components/theme/theme_manager_impl.cpp +++ b/frameworks/core/components/theme/theme_manager_impl.cpp @@ -82,6 +82,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/radio/radio_theme_wrapper.h" #include "core/components_v2/pattern_lock/pattern_lock_theme_wrapper.h" #include "core/components_ng/pattern/progress/progress_theme_wrapper.h" @@ -175,6 +176,7 @@ const std::unordered_map(*)(const RefPt TOKEN_THEME_WRAPPER_BUILDERS = { { CheckboxTheme::TypeId(), &ThemeWrapperBuildFunc }, { ButtonTheme::TypeId(), &ThemeWrapperBuildFunc }, + { DividerTheme::TypeId(), &ThemeWrapperBuildFunc }, { V2::PatternLockTheme::TypeId(), &ThemeWrapperBuildFunc }, { ProgressTheme::TypeId(), &ThemeWrapperBuildFunc }, { QrcodeTheme::TypeId(), &ThemeWrapperBuildFunc }, diff --git a/frameworks/core/components_ng/pattern/divider/divider_layout_algorithm.cpp b/frameworks/core/components_ng/pattern/divider/divider_layout_algorithm.cpp index 0ad5e3bd590ee52c9da74026748695c989a64631..7f8e71563ba33f693089064235176c66da284540 100644 --- a/frameworks/core/components_ng/pattern/divider/divider_layout_algorithm.cpp +++ b/frameworks/core/components_ng/pattern/divider/divider_layout_algorithm.cpp @@ -30,9 +30,11 @@ std::optional DividerLayoutAlgorithm::MeasureContent( auto dividerLayoutProperty = DynamicCast(layoutWrapper->GetLayoutProperty()); CHECK_NULL_RETURN(dividerLayoutProperty, std::nullopt); + auto frameNode = layoutWrapper->GetHostNode(); + CHECK_NULL_RETURN(frameNode, std::nullopt); auto pipeline = PipelineBase::GetCurrentContext(); CHECK_NULL_RETURN(pipeline, std::nullopt); - auto theme = pipeline->GetTheme(); + auto theme = pipeline->GetTheme(frameNode->GetThemeScopeId()); CHECK_NULL_RETURN(theme, std::nullopt); auto defaultStrokeWidth = Container::GreatOrEqualAPIVersion(PlatformVersion::VERSION_TEN) ? 1.0_px : theme->GetStokeWidth(); diff --git a/frameworks/core/components_ng/pattern/divider/divider_model.h b/frameworks/core/components_ng/pattern/divider/divider_model.h index 7b7b3ada45a0d4abefb417e94605955e63b0f041..31519f9ee052fb3e77284b28acb9c686de33d2bc 100644 --- a/frameworks/core/components_ng/pattern/divider/divider_model.h +++ b/frameworks/core/components_ng/pattern/divider/divider_model.h @@ -34,6 +34,7 @@ public: virtual void DividerColor(const Color& value) = 0; virtual void StrokeWidth(const Dimension& value) = 0; virtual void LineCap(const LineCap& value) = 0; + virtual void ResetDividerColor() {}; private: static std::unique_ptr instance_; diff --git a/frameworks/core/components_ng/pattern/divider/divider_model_ng.cpp b/frameworks/core/components_ng/pattern/divider/divider_model_ng.cpp index 1c639fa8be7813754ec21b3f7bfc01e4a7b36991..bb91b68fffd4b21d6ba29cac529181cf0f0495e9 100644 --- a/frameworks/core/components_ng/pattern/divider/divider_model_ng.cpp +++ b/frameworks/core/components_ng/pattern/divider/divider_model_ng.cpp @@ -51,6 +51,11 @@ void DividerModelNG::DividerColor(const Color& value) ACE_UPDATE_PAINT_PROPERTY(DividerRenderProperty, DividerColor, value); } +void DividerModelNG::ResetDividerColor() +{ + ACE_RESET_PAINT_PROPERTY_WITH_FLAG(DividerRenderProperty, DividerColor, PROPERTY_UPDATE_RENDER); +} + void DividerModelNG::StrokeWidth(const Dimension& value) { ACE_UPDATE_LAYOUT_PROPERTY(DividerLayoutProperty, StrokeWidth, value); diff --git a/frameworks/core/components_ng/pattern/divider/divider_model_ng.h b/frameworks/core/components_ng/pattern/divider/divider_model_ng.h index 8938ebffa4d883bc1b28891eb195bb264ccd5384..17866c639df101735b7c2db117bfea623803a529 100644 --- a/frameworks/core/components_ng/pattern/divider/divider_model_ng.h +++ b/frameworks/core/components_ng/pattern/divider/divider_model_ng.h @@ -28,6 +28,8 @@ public: void DividerColor(const Color& value) override; void StrokeWidth(const Dimension& value) override; void LineCap(const enum LineCap& value) override; + void ResetDividerColor() override; + static RefPtr CreateFrameNode(int32_t nodeId); static void StrokeWidth(FrameNode* frameNode, const Dimension& value); static void LineCap(FrameNode* frameNode, const enum LineCap& value); diff --git a/frameworks/core/components_ng/pattern/divider/divider_paint_method.h b/frameworks/core/components_ng/pattern/divider/divider_paint_method.h index 83b7af853428552adc10e9eb5914b7c59dd033d8..e2877e9f8afab106c5a3d73b8faeadbcf37b4345 100644 --- a/frameworks/core/components_ng/pattern/divider/divider_paint_method.h +++ b/frameworks/core/components_ng/pattern/divider/divider_paint_method.h @@ -44,9 +44,11 @@ public: CHECK_NULL_VOID(dividerModifier_); auto dividerRenderProperty = DynamicCast(paintWrapper->GetPaintProperty()); CHECK_NULL_VOID(dividerRenderProperty); + auto host = paintWrapper->GetRenderContext()->GetHost(); + CHECK_NULL_VOID(host); auto pipeline = PipelineBase::GetCurrentContext(); CHECK_NULL_VOID(pipeline); - auto theme = pipeline->GetTheme(); + auto theme = pipeline->GetTheme(host->GetThemeScopeId()); CHECK_NULL_VOID(theme); dividerColor_ = dividerRenderProperty->GetDividerColor().value_or(theme->GetColor()); lineCap_ = dividerRenderProperty->GetLineCap().value_or(LineCap::BUTT); diff --git a/frameworks/core/components_ng/pattern/divider/divider_pattern.cpp b/frameworks/core/components_ng/pattern/divider/divider_pattern.cpp index 5f6639463fb09d4b49d55ec06fd2a0c147b4535a..3ceb510d96cf715d8f7f14f209e774627005c2e6 100644 --- a/frameworks/core/components_ng/pattern/divider/divider_pattern.cpp +++ b/frameworks/core/components_ng/pattern/divider/divider_pattern.cpp @@ -31,4 +31,15 @@ bool DividerPattern::OnDirtyLayoutWrapperSwap(const RefPtr& dirty strokeWidthLimitation_ = dividerLayoutAlgorithm->GetStrokeWidthLimitation(); return true; } + +bool DividerPattern::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->HasDividerColor(); + return result; +} + } // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/divider/divider_pattern.h b/frameworks/core/components_ng/pattern/divider/divider_pattern.h index 202dbfcfa8ed50128586955caef0d895e9f24718..e501cace07e30d88b3b5c026de26c3a1f875973d 100644 --- a/frameworks/core/components_ng/pattern/divider/divider_pattern.h +++ b/frameworks/core/components_ng/pattern/divider/divider_pattern.h @@ -60,6 +60,8 @@ public: return { FocusType::NODE, false, FocusStyleType::OUTER_BORDER }; } + bool OnThemeScopeUpdate(int32_t themeScopeId) override; + private: bool OnDirtyLayoutWrapperSwap(const RefPtr& dirty, const DirtySwapConfig& config) override; float constrainStrokeWidth_ = 0; diff --git a/frameworks/core/components_ng/pattern/divider/divider_render_property.h b/frameworks/core/components_ng/pattern/divider/divider_render_property.h index c5a3e2926b91ef34e10d24eb08f23809b2a4b3db..911eb40bb11850912d76485b01847968959f3076 100644 --- a/frameworks/core/components_ng/pattern/divider/divider_render_property.h +++ b/frameworks/core/components_ng/pattern/divider/divider_render_property.h @@ -53,9 +53,12 @@ public: if (filter.IsFastFilter()) { return; } + + auto host = GetHost(); + CHECK_NULL_VOID(host); auto pipelineContext = PipelineBase::GetCurrentContext(); CHECK_NULL_VOID(pipelineContext); - auto theme = pipelineContext->GetTheme(); + auto theme = pipelineContext->GetTheme(host->GetThemeScopeId()); CHECK_NULL_VOID(theme); json->PutExtAttr("color", propDividerColor_.value_or(theme->GetColor()).ColorToString().c_str(), filter); json->PutExtAttr("lineCap", diff --git a/frameworks/core/components_ng/pattern/divider/divider_theme_wrapper.h b/frameworks/core/components_ng/pattern/divider/divider_theme_wrapper.h new file mode 100644 index 0000000000000000000000000000000000000000..88feeb21fdb64a8545b0d431015fef927aeca880 --- /dev/null +++ b/frameworks/core/components_ng/pattern/divider/divider_theme_wrapper.h @@ -0,0 +1,81 @@ +/* + * 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_SWIPER_SWIPER_THEME_WRAPPER_H +#define FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SWIPER_SWIPER_THEME_WRAPPER_H + +#include + +#include "base/memory/ace_type.h" +#include "core/components/divider/divider_theme.h" +#include "core/components_ng/token_theme/token_theme_wrapper.h" + +namespace OHOS::Ace::NG { + +/** + * DividerThemeWrapper defines colors and styles for Indicator and DisplayArrows parts of Divider Component + * basing on TokenTheme's data. + * DividerThemeWrapper should be built using DividerThemeWrapper::WrapperBuilder. + */ +class DividerThemeWrapper : public DividerTheme, public TokenThemeWrapper +{ + DECLARE_ACE_TYPE(DividerThemeWrapper, DividerTheme); + +public: + class WrapperBuilder : public Builder + { + public: + WrapperBuilder() = default; + ~WrapperBuilder() = default; + + RefPtr BuildWrapper(const RefPtr& themeConstants) const + { + auto wrapper = AceType::Claim(new DividerThemeWrapper()); + if (!themeConstants) { + return wrapper; + } + + RefPtr pattern = themeConstants->GetPatternByName(THEME_PATTERN_DIVIDER); + if (pattern) { + wrapper->color_ = pattern->GetAttr("divider_color", Color::BLACK); + wrapper->stokeWidth_ = pattern->GetAttr("divider_stroke_width", 1.0_vp); + } else { + LOGW("find pattern of divider fail"); + } + return wrapper; + } + }; + + ~DividerThemeWrapper() override = default; + + void ApplyTokenTheme(const TokenTheme& theme) override + { + if (auto colors = theme.Colors(); colors) { + color_ = colors->FontPrimary(); + return; + } + } + + const Color& GetColor() const override + { + return color_; + } + +protected: + DividerThemeWrapper() = default; +}; + +} // namespace +#endif \ No newline at end of file