From f5889b61184d59e49915d5b9f70cde4965913f98 Mon Sep 17 00:00:00 2001 From: zhanghang Date: Sat, 24 May 2025 23:49:19 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20texttimer=20=E6=B5=85=E6=99=AF=E8=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhanghang --- .../jsview/js_texttimer.cpp | 15 +- .../components/common/properties/text_style.h | 2 +- .../texttimer/text_timer_layout_property.h | 1 + .../pattern/texttimer/text_timer_model_ng.cpp | 8 ++ .../pattern/texttimer/text_timer_pattern.cpp | 22 +++ .../pattern/texttimer/text_timer_pattern.h | 1 + hanye.diff | 130 ++++++++++++++++++ 7 files changed, 168 insertions(+), 11 deletions(-) create mode 100644 hanye.diff diff --git a/frameworks/bridge/declarative_frontend/jsview/js_texttimer.cpp b/frameworks/bridge/declarative_frontend/jsview/js_texttimer.cpp index fae763937bd..ae3bee94847 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_texttimer.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_texttimer.cpp @@ -302,19 +302,14 @@ void JSTextTimer::SetFontFamily(const JSCallbackInfo& info) } std::vector fontFamilies; RefPtr resObj; + auto result= ParseJsFontFamilies(info[0], fontFamilies, resObj); if (SystemProperties::ConfigChangePerform()) { - bool state = ParseJsFontFamilies(info[0], fontFamilies, resObj); - if (resObj) { - TextTimerModel::GetInstance()->CreateWithResourceObj(JsTextTimerResourceType::FONTFAMILY, resObj); - } else if (state) { - TextTimerModel::GetInstance()->SetFontFamily(fontFamilies); - } - } else { - if (!ParseJsFontFamilies(info[0], fontFamilies)) { - return; - } + TextTimerModel::GetInstance()->CreateWithResourceObj(JsTextTimerResourceType::FONTFAMILY, resObj); + } + if (result) { TextTimerModel::GetInstance()->SetFontFamily(fontFamilies); } + } } void JSTextTimer::OnTimer(const JSCallbackInfo& info) diff --git a/frameworks/core/components/common/properties/text_style.h b/frameworks/core/components/common/properties/text_style.h index f623a5be38d..1e5d8ab7fa1 100644 --- a/frameworks/core/components/common/properties/text_style.h +++ b/frameworks/core/components/common/properties/text_style.h @@ -687,7 +687,7 @@ public: ACE_DEFINE_TEXT_STYLE_WITH_DEFAULT_VALUE(VariableFontWeight, int32_t, 0, TextStyleAttribute::FONT_VARIATIONS); ACE_DEFINE_TEXT_STYLE_WITH_DEFAULT_VALUE( EnableVariableFontWeight, bool, false, TextStyleAttribute::FONT_VARIATIONS); - ACE_DEFINE_TEXT_STYLE_WITH_DEFAULT_VALUE(TextColor, Color, Color::BLACK, TextStyleAttribute::FONT_COLOR); + ACE_DEFINE_TEXT_STYLE_WITH_DEFAULT_VALUE(TextColor, Color, Color:: , TextStyleAttribute::FONT_COLOR); ACE_DEFINE_TEXT_DIMENSION_STYLE(WordSpacing, TextStyleAttribute::WORD_SPACING); ACE_DEFINE_TEXT_DIMENSION_STYLE_WITH_DEFAULT_VALUE( TextIndent, Dimension(0.0f, DimensionUnit::PX), 0.0f, TextStyleAttribute::RE_CREATE); diff --git a/frameworks/core/components_ng/pattern/texttimer/text_timer_layout_property.h b/frameworks/core/components_ng/pattern/texttimer/text_timer_layout_property.h index e96d8d41109..60eae368dcc 100644 --- a/frameworks/core/components_ng/pattern/texttimer/text_timer_layout_property.h +++ b/frameworks/core/components_ng/pattern/texttimer/text_timer_layout_property.h @@ -74,6 +74,7 @@ public: ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(FontWeight, FontWeight, PROPERTY_UPDATE_MEASURE); ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(FontFamily, std::vector, PROPERTY_UPDATE_MEASURE); ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(TextShadow, std::vector, PROPERTY_UPDATE_MEASURE); + ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(TextColorSetByUser, bool, PROPERTY_UPDATE_MEASURE); private: void ResetCount(); diff --git a/frameworks/core/components_ng/pattern/texttimer/text_timer_model_ng.cpp b/frameworks/core/components_ng/pattern/texttimer/text_timer_model_ng.cpp index ec5647569f4..71941711ea6 100644 --- a/frameworks/core/components_ng/pattern/texttimer/text_timer_model_ng.cpp +++ b/frameworks/core/components_ng/pattern/texttimer/text_timer_model_ng.cpp @@ -41,6 +41,11 @@ RefPtr TextTimerModelNG::Create() textNode->MountToParent(textTimerNode); } stack->Push(textTimerNode); + auto textTimerLayoutProperty = textTimerNode->GetLayoutProperty(); + if(textTimerLayoutProperty){ + textTimerLayoutProperty->ResetTextColorSetByUser(); + } + return textTimerPattern ? textTimerPattern->GetTextTimerController() : nullptr; } @@ -67,6 +72,7 @@ void TextTimerModelNG::SetFontSize(const Dimension& value) void TextTimerModelNG::SetTextColor(const Color& value) { ACE_UPDATE_LAYOUT_PROPERTY(TextTimerLayoutProperty, TextColor, value); + ACE_UPDATE_LAYOUT_PROPERTY(TextTimerLayoutProperty, TextColorSetByUser, true); ACE_UPDATE_RENDER_CONTEXT(ForegroundColor, value); ACE_RESET_RENDER_CONTEXT(RenderContext, ForegroundColorStrategy); ACE_UPDATE_RENDER_CONTEXT(ForegroundColorFlag, true); @@ -212,6 +218,8 @@ void TextTimerModelNG::HandleTextColor(FrameNode* frameNode, const RefPtrGetPattern(); CHECK_NULL_VOID(pattern); + pattern->RemoveResObj(key); + CHECK_NULL_VOID(resObj); auto&& updateFunc = [pattern, key](const RefPtr& resObj, bool isFirstLoad = false) { Color result; if (!ResourceParseUtils::ParseResColor(resObj, result)) { diff --git a/frameworks/core/components_ng/pattern/texttimer/text_timer_pattern.cpp b/frameworks/core/components_ng/pattern/texttimer/text_timer_pattern.cpp index 8d67c69dae3..eeeb37da6c1 100644 --- a/frameworks/core/components_ng/pattern/texttimer/text_timer_pattern.cpp +++ b/frameworks/core/components_ng/pattern/texttimer/text_timer_pattern.cpp @@ -475,4 +475,26 @@ void TextTimerPattern::UpdateFontFamily(const std::vector& fontFami layoutProperty->UpdateFontFamily(fontFamilies); } } + +void TextTimerPattern::OnColorConfigurationUpdate() +{ + if (!SystemProperties::ConfigChangePerform()) { + return; + } + + auto host = GetHost(); + CHECK_NULL_VOID(host); + auto pipeline = host->GetContextWithCheck(); + CHECK_NULL_VOID(pipeline); + + auto theme = pipeline->GetTheme(); + CHECK_NULL_VOID(theme); + + auto pops = host->GetLayoutProperty(); + CHECK_NULL_VOID(textTimerLayoutProperty); + + if (!pops->HasTextColorSetByUser() || (pops->HasTextColorSetByUser() && !pops->GetTextColorSetByUserValue())) { + UpdateTextColor(theme->GetTextStyle().GetTextColor(), false); + } +} } // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/texttimer/text_timer_pattern.h b/frameworks/core/components_ng/pattern/texttimer/text_timer_pattern.h index bd7ed79bbdb..8239ff8233f 100644 --- a/frameworks/core/components_ng/pattern/texttimer/text_timer_pattern.h +++ b/frameworks/core/components_ng/pattern/texttimer/text_timer_pattern.h @@ -104,6 +104,7 @@ public: void DumpInfo() override; void DumpInfo(std::unique_ptr& json) override; void DumpSimplifyInfo(std::unique_ptr& json) override {} + void OnColorConfigurationUpdate() override; void UpdateTextColor(const Color& color, bool isFirstLoad = false); void UpdateFontWeight(const FontWeight& value, bool isFirstLoad = false); diff --git a/hanye.diff b/hanye.diff new file mode 100644 index 00000000000..934bc2ddc9c --- /dev/null +++ b/hanye.diff @@ -0,0 +1,130 @@ +diff --git a/frameworks/bridge/declarative_frontend/jsview/js_texttimer.cpp b/frameworks/bridge/declarative_frontend/jsview/js_texttimer.cpp +index fae763937bd..ae3bee94847 100644 +--- a/frameworks/bridge/declarative_frontend/jsview/js_texttimer.cpp ++++ b/frameworks/bridge/declarative_frontend/jsview/js_texttimer.cpp +@@ -302,19 +302,14 @@ void JSTextTimer::SetFontFamily(const JSCallbackInfo& info) + } + std::vector fontFamilies; + RefPtr resObj; ++ auto result= ParseJsFontFamilies(info[0], fontFamilies, resObj); + if (SystemProperties::ConfigChangePerform()) { +- bool state = ParseJsFontFamilies(info[0], fontFamilies, resObj); +- if (resObj) { +- TextTimerModel::GetInstance()->CreateWithResourceObj(JsTextTimerResourceType::FONTFAMILY, resObj); +- } else if (state) { +- TextTimerModel::GetInstance()->SetFontFamily(fontFamilies); +- } +- } else { +- if (!ParseJsFontFamilies(info[0], fontFamilies)) { +- return; +- } ++ TextTimerModel::GetInstance()->CreateWithResourceObj(JsTextTimerResourceType::FONTFAMILY, resObj); ++ } ++ if (result) { + TextTimerModel::GetInstance()->SetFontFamily(fontFamilies); + } ++ } + } + + void JSTextTimer::OnTimer(const JSCallbackInfo& info) +diff --git a/frameworks/core/components/common/properties/text_style.h b/frameworks/core/components/common/properties/text_style.h +index f623a5be38d..1e5d8ab7fa1 100644 +--- a/frameworks/core/components/common/properties/text_style.h ++++ b/frameworks/core/components/common/properties/text_style.h +@@ -687,7 +687,7 @@ public: + ACE_DEFINE_TEXT_STYLE_WITH_DEFAULT_VALUE(VariableFontWeight, int32_t, 0, TextStyleAttribute::FONT_VARIATIONS); + ACE_DEFINE_TEXT_STYLE_WITH_DEFAULT_VALUE( + EnableVariableFontWeight, bool, false, TextStyleAttribute::FONT_VARIATIONS); +- ACE_DEFINE_TEXT_STYLE_WITH_DEFAULT_VALUE(TextColor, Color, Color::BLACK, TextStyleAttribute::FONT_COLOR); ++ ACE_DEFINE_TEXT_STYLE_WITH_DEFAULT_VALUE(TextColor, Color, Color:: , TextStyleAttribute::FONT_COLOR); + ACE_DEFINE_TEXT_DIMENSION_STYLE(WordSpacing, TextStyleAttribute::WORD_SPACING); + ACE_DEFINE_TEXT_DIMENSION_STYLE_WITH_DEFAULT_VALUE( + TextIndent, Dimension(0.0f, DimensionUnit::PX), 0.0f, TextStyleAttribute::RE_CREATE); +diff --git a/frameworks/core/components_ng/pattern/texttimer/text_timer_layout_property.h b/frameworks/core/components_ng/pattern/texttimer/text_timer_layout_property.h +index e96d8d41109..60eae368dcc 100644 +--- a/frameworks/core/components_ng/pattern/texttimer/text_timer_layout_property.h ++++ b/frameworks/core/components_ng/pattern/texttimer/text_timer_layout_property.h +@@ -74,6 +74,7 @@ public: + ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(FontWeight, FontWeight, PROPERTY_UPDATE_MEASURE); + ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(FontFamily, std::vector, PROPERTY_UPDATE_MEASURE); + ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(TextShadow, std::vector, PROPERTY_UPDATE_MEASURE); ++ ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(TextColorSetByUser, bool, PROPERTY_UPDATE_MEASURE); + + private: + void ResetCount(); +diff --git a/frameworks/core/components_ng/pattern/texttimer/text_timer_model_ng.cpp b/frameworks/core/components_ng/pattern/texttimer/text_timer_model_ng.cpp +index ec5647569f4..71941711ea6 100644 +--- a/frameworks/core/components_ng/pattern/texttimer/text_timer_model_ng.cpp ++++ b/frameworks/core/components_ng/pattern/texttimer/text_timer_model_ng.cpp +@@ -41,6 +41,11 @@ RefPtr TextTimerModelNG::Create() + textNode->MountToParent(textTimerNode); + } + stack->Push(textTimerNode); ++ auto textTimerLayoutProperty = textTimerNode->GetLayoutProperty(); ++ if(textTimerLayoutProperty){ ++ textTimerLayoutProperty->ResetTextColorSetByUser(); ++ } ++ + return textTimerPattern ? textTimerPattern->GetTextTimerController() : nullptr; + } + +@@ -67,6 +72,7 @@ void TextTimerModelNG::SetFontSize(const Dimension& value) + void TextTimerModelNG::SetTextColor(const Color& value) + { + ACE_UPDATE_LAYOUT_PROPERTY(TextTimerLayoutProperty, TextColor, value); ++ ACE_UPDATE_LAYOUT_PROPERTY(TextTimerLayoutProperty, TextColorSetByUser, true); + ACE_UPDATE_RENDER_CONTEXT(ForegroundColor, value); + ACE_RESET_RENDER_CONTEXT(RenderContext, ForegroundColorStrategy); + ACE_UPDATE_RENDER_CONTEXT(ForegroundColorFlag, true); +@@ -212,6 +218,8 @@ void TextTimerModelNG::HandleTextColor(FrameNode* frameNode, const RefPtrGetPattern(); + CHECK_NULL_VOID(pattern); ++ pattern->RemoveResObj(key); ++ CHECK_NULL_VOID(resObj); + auto&& updateFunc = [pattern, key](const RefPtr& resObj, bool isFirstLoad = false) { + Color result; + if (!ResourceParseUtils::ParseResColor(resObj, result)) { +diff --git a/frameworks/core/components_ng/pattern/texttimer/text_timer_pattern.cpp b/frameworks/core/components_ng/pattern/texttimer/text_timer_pattern.cpp +index 8d67c69dae3..eeeb37da6c1 100644 +--- a/frameworks/core/components_ng/pattern/texttimer/text_timer_pattern.cpp ++++ b/frameworks/core/components_ng/pattern/texttimer/text_timer_pattern.cpp +@@ -475,4 +475,26 @@ void TextTimerPattern::UpdateFontFamily(const std::vector& fontFami + layoutProperty->UpdateFontFamily(fontFamilies); + } + } ++ ++void TextTimerPattern::OnColorConfigurationUpdate() ++{ ++ if (!SystemProperties::ConfigChangePerform()) { ++ return; ++ } ++ ++ auto host = GetHost(); ++ CHECK_NULL_VOID(host); ++ auto pipeline = host->GetContextWithCheck(); ++ CHECK_NULL_VOID(pipeline); ++ ++ auto theme = pipeline->GetTheme(); ++ CHECK_NULL_VOID(theme); ++ ++ auto pops = host->GetLayoutProperty(); ++ CHECK_NULL_VOID(textTimerLayoutProperty); ++ ++ if (!pops->HasTextColorSetByUser() || (pops->HasTextColorSetByUser() && !pops->GetTextColorSetByUserValue())) { ++ UpdateTextColor(theme->GetTextStyle().GetTextColor(), false); ++ } ++} + } // namespace OHOS::Ace::NG +diff --git a/frameworks/core/components_ng/pattern/texttimer/text_timer_pattern.h b/frameworks/core/components_ng/pattern/texttimer/text_timer_pattern.h +index bd7ed79bbdb..8239ff8233f 100644 +--- a/frameworks/core/components_ng/pattern/texttimer/text_timer_pattern.h ++++ b/frameworks/core/components_ng/pattern/texttimer/text_timer_pattern.h +@@ -104,6 +104,7 @@ public: + void DumpInfo() override; + void DumpInfo(std::unique_ptr& json) override; + void DumpSimplifyInfo(std::unique_ptr& json) override {} ++ void OnColorConfigurationUpdate() override; + + void UpdateTextColor(const Color& color, bool isFirstLoad = false); + void UpdateFontWeight(const FontWeight& value, bool isFirstLoad = false); -- Gitee