From 60006eb4a115c47e5fb3bf881b385425de1f345c Mon Sep 17 00:00:00 2001 From: huangxiaoxiao Date: Sun, 11 May 2025 15:04:47 +0800 Subject: [PATCH] =?UTF-8?q?picker=E9=80=82=E9=85=8D=E6=B7=B1=E6=B5=85?= =?UTF-8?q?=E8=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huangxiaoxiao --- .../jsview/js_calendar_picker.cpp | 63 +++++- .../jsview/js_calendar_picker.h | 5 + .../jsview/js_datepicker.cpp | 56 +++-- .../jsview/js_datepicker.h | 1 + .../jsview/js_textpicker.cpp | 141 ++++++++---- .../jsview/js_textpicker.h | 1 + .../models/calendar_picker_model_impl.h | 3 + .../calendar/calendar_month_pattern.cpp | 24 +++ .../pattern/calendar/calendar_month_pattern.h | 2 + .../calendar_dialog_pattern.cpp | 5 + .../calendar_picker/calendar_dialog_view.cpp | 11 + .../calendar_picker/calendar_picker_model.h | 4 + .../calendar_picker_model_ng.cpp | 85 ++++++++ .../calendar_picker_model_ng.h | 4 + .../calendar_picker_pattern.cpp | 28 ++- .../calendar_picker/calendar_picker_pattern.h | 9 + .../calendar_picker/calendar_type_define.h | 2 + .../picker/datepicker_column_pattern.cpp | 12 +- .../pattern/picker/datepicker_dialog_view.cpp | 4 +- .../pattern/picker/datepicker_model_ng.cpp | 87 ++++++++ .../pattern/picker/datepicker_model_ng.h | 6 + .../pattern/picker/datepicker_pattern.cpp | 137 +++++++++++- .../pattern/picker/datepicker_pattern.h | 20 ++ .../pattern/picker/picker_model.h | 3 + .../pattern/picker/picker_type_define.h | 8 + .../text_picker/textpicker_column_pattern.cpp | 14 +- .../pattern/text_picker/textpicker_model.h | 6 + .../text_picker/textpicker_model_ng.cpp | 203 ++++++++++++++++++ .../pattern/text_picker/textpicker_model_ng.h | 9 + .../text_picker/textpicker_paint_method.cpp | 1 + .../text_picker/textpicker_pattern.cpp | 181 +++++++++++++++- .../pattern/text_picker/textpicker_pattern.h | 21 ++ .../text_picker/textpicker_properties.h | 7 + .../pattern/time_picker/timepicker_model.h | 3 + .../time_picker/timepicker_model_ng.cpp | 86 ++++++++ .../pattern/time_picker/timepicker_model_ng.h | 5 + .../time_picker/timepicker_row_pattern.cpp | 135 +++++++++++- .../time_picker/timepicker_row_pattern.h | 20 ++ test/unittest/core/pattern/picker/BUILD.gn | 1 + .../picker/date_picker_resource_test.cpp | 160 ++++++++++++++ 40 files changed, 1472 insertions(+), 101 deletions(-) create mode 100644 test/unittest/core/pattern/picker/date_picker_resource_test.cpp diff --git a/frameworks/bridge/declarative_frontend/jsview/js_calendar_picker.cpp b/frameworks/bridge/declarative_frontend/jsview/js_calendar_picker.cpp index 526315412a6..424aa17eb86 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_calendar_picker.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_calendar_picker.cpp @@ -29,6 +29,8 @@ #include "core/components_ng/base/view_stack_processor.h" #include "core/components_ng/pattern/calendar_picker/calendar_picker_model_ng.h" #include "core/pipeline_ng/pipeline_context.h" +#include "core/common/resource/resource_object.h" +#include "core/common/resource/resource_parse_utils.h" namespace OHOS::Ace { std::unique_ptr CalendarPickerModel::instance_ = nullptr; @@ -260,13 +262,29 @@ void JSCalendarPicker::SetEdgeAlign(const JSCallbackInfo& info) return; } auto offsetObj = JSRef::Cast(info[1]); - CalcDimension dx; auto dxValue = offsetObj->GetProperty("dx"); - ParseJsDimensionVp(dxValue, dx); - CalcDimension dy; auto dyValue = offsetObj->GetProperty("dy"); - ParseJsDimensionVp(dyValue, dy); - offset = DimensionOffset(dx, dy); + + CalcDimension dx; + CalcDimension dy; + + if (SystemProperties::ConfigChangePerform()) { + RefPtr dxResObj; + RefPtr dyResObj; + ParseJsDimensionVp(dxValue, dx, dxResObj); + ParseJsDimensionVp(dyValue, dy, dyResObj); + offset = DimensionOffset(dx, dy); + + if (dxResObj || dyResObj) { + std::vector> resArray = { dxResObj, dyResObj }; + CalendarPickerModel::GetInstance()->SetEdgeAlign(alignType, offset, resArray); + return; + } + } else { + ParseJsDimensionVp(dxValue, dx); + ParseJsDimensionVp(dyValue, dy); + offset = DimensionOffset(dx, dy); + } CalendarPickerModel::GetInstance()->SetEdgeAlign(alignType, offset); } @@ -285,7 +303,12 @@ void JSCalendarPicker::SetTextStyle(const JSCallbackInfo& info) CalendarPickerModel::GetInstance()->SetTextStyle(textStyle); return; } + JSCalendarPicker::ParseTextStyle(info[0], textStyle); + + if (SystemProperties::ConfigChangePerform()) { + CalendarPickerModel::GetInstance()->ParseNormalTextStyleResObj(textStyle); + } CalendarPickerModel::GetInstance()->SetTextStyle(textStyle); } @@ -456,6 +479,27 @@ void JSCalendarPicker::ParseDisabledDateRange( } } +void JSCalendarPicker::ParseHintRadius(JSRef& obj, NG::CalendarSettingData& settingData, + CalcDimension& dayRadius) +{ + RefPtr calendarTheme = GetTheme(); + CHECK_NULL_VOID(calendarTheme); + if (SystemProperties::ConfigChangePerform()) { + RefPtr hintRadiusResObj; + if (!ParseJsDimensionVpNG(obj->GetProperty("hintRadius"), dayRadius, hintRadiusResObj)) { + dayRadius = calendarTheme->GetCalendarDayRadius(); + } + + if (hintRadiusResObj) { + settingData.dayRadiusResObj = hintRadiusResObj; + } + } else { + if (!ParseJsDimensionVpNG(obj->GetProperty("hintRadius"), dayRadius)) { + dayRadius = calendarTheme->GetCalendarDayRadius(); + } + } +} + void JSCalendarPicker::Create(const JSCallbackInfo& info) { NG::CalendarSettingData settingData; @@ -464,9 +508,8 @@ void JSCalendarPicker::Create(const JSCallbackInfo& info) CalcDimension dayRadius; if (info[0]->IsObject()) { auto obj = JSRef::Cast(info[0]); - if (!ParseJsDimensionVpNG(obj->GetProperty("hintRadius"), dayRadius)) { - dayRadius = calendarTheme->GetCalendarDayRadius(); - } + ParseHintRadius(obj, settingData, dayRadius); + auto selected = obj->GetProperty("selected"); auto parseSelectedDate = ParseDate(selected); if (selected->IsObject() && parseSelectedDate.GetYear() != 0) { @@ -505,7 +548,7 @@ void JSCalendarPicker::ParseTextStyle(const JSRef& paramObj, NG::Picke auto fontStyle = paramObj->GetProperty("font"); Color color; - if (ParseJsColor(fontColor, color)) { + if (ParseJsColor(fontColor, color, textStyle.textColorResObj)) { textStyle.textColor = color; } @@ -519,7 +562,7 @@ void JSCalendarPicker::ParseTextStyle(const JSRef& paramObj, NG::Picke textStyle.fontSize = Dimension(-1); } else { CalcDimension size; - if (!ParseJsDimensionFpNG(fontSize, size) || size.Unit() == DimensionUnit::PERCENT) { + if (!ParseJsDimensionFpNG(fontSize, size, textStyle.fontSizeResObj) || size.Unit() == DimensionUnit::PERCENT) { textStyle.fontSize = Dimension(-1); } else { textStyle.fontSize = size; diff --git a/frameworks/bridge/declarative_frontend/jsview/js_calendar_picker.h b/frameworks/bridge/declarative_frontend/jsview/js_calendar_picker.h index 3071984a477..ff7a06725e2 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_calendar_picker.h +++ b/frameworks/bridge/declarative_frontend/jsview/js_calendar_picker.h @@ -36,6 +36,8 @@ public: private: static void ParseTextStyle(const JSRef& paramObj, NG::PickerTextStyle& textStyle); + static void ParseTextStyleWithResObj(const JSRef& paramObj, NG::PickerTextStyle& textStyle, + const std::string& key); static void ParseSelectedDateObject(const JSCallbackInfo& info, const JSRef& selectedObject); static PickerDate ParseDate(const JSRef& dateVal, bool useCurrentDate = true); static void ParseCalendarPickerBorderColor(const JSRef& args); @@ -44,6 +46,9 @@ private: const std::optional& right); static bool ParseJsDimensionVpWithCheck(const JSRef& jsValue, CalcDimension& result); static void ParseDisabledDateRange(const JSRef& disabledDateRangeVal, NG::CalendarSettingData& settingData); + static void ParseHintRadius(JSRef& obj, NG::CalendarSettingData& settingData, CalcDimension& dayRadius); + static void ParseTextStyleFontSize(const JSRef& fontSize, NG::PickerTextStyle& textStyle, + const std::string& key); }; class JSCalendarPickerDialog : JSAlertDialog { diff --git a/frameworks/bridge/declarative_frontend/jsview/js_datepicker.cpp b/frameworks/bridge/declarative_frontend/jsview/js_datepicker.cpp index 2c446f29368..8fef6f689ad 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_datepicker.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_datepicker.cpp @@ -38,6 +38,8 @@ #include "core/components_v2/inspector/inspector_constants.h" #include "core/event/ace_event_helper.h" #include "core/pipeline_ng/pipeline_context.h" +#include "core/common/resource/resource_object.h" +#include "core/common/resource/resource_parse_utils.h" namespace OHOS::Ace { namespace { @@ -414,6 +416,20 @@ void JSDatePicker::IsUserDefinedFontFamily(const std::string& pos) } } +void JSDatePicker::ParseTextStyleFontSize(const JSRef& fontSize, NG::PickerTextStyle& textStyle) +{ + if (fontSize->IsNull() || fontSize->IsUndefined()) { + textStyle.fontSize = Dimension(-1); + } else { + CalcDimension size; + if (!ParseJsDimensionFp(fontSize, size, textStyle.fontSizeResObj) || size.Unit() == DimensionUnit::PERCENT) { + textStyle.fontSize = Dimension(-1); + } else { + textStyle.fontSize = size; + } + } +} + void JSDatePicker::ParseTextStyle( const JSRef& paramObj, NG::PickerTextStyle& textStyle, const std::string& pos) { @@ -421,7 +437,7 @@ void JSDatePicker::ParseTextStyle( auto fontOptions = paramObj->GetProperty("font"); Color textColor; - if (JSViewAbstract::ParseJsColor(fontColor, textColor)) { + if (JSViewAbstract::ParseJsColor(fontColor, textColor, textStyle.textColorResObj)) { textStyle.textColor = textColor; } @@ -433,16 +449,8 @@ void JSDatePicker::ParseTextStyle( auto fontWeight = fontObj->GetProperty("weight"); auto fontFamily = fontObj->GetProperty("family"); auto fontStyle = fontObj->GetProperty("style"); - if (fontSize->IsNull() || fontSize->IsUndefined()) { - textStyle.fontSize = Dimension(-1); - } else { - CalcDimension size; - if (!ParseJsDimensionFp(fontSize, size) || size.Unit() == DimensionUnit::PERCENT) { - textStyle.fontSize = Dimension(-1); - } else { - textStyle.fontSize = size; - } - } + + ParseTextStyleFontSize(fontSize, textStyle); if (!fontWeight->IsNull() && !fontWeight->IsUndefined()) { std::string weight; @@ -456,7 +464,7 @@ void JSDatePicker::ParseTextStyle( if (!fontFamily->IsNull() && !fontFamily->IsUndefined()) { std::vector families; - if (ParseJsFontFamilies(fontFamily, families)) { + if (ParseJsFontFamilies(fontFamily, families, textStyle.fontFamilyResObj)) { textStyle.fontFamily = families; IsUserDefinedFontFamily(pos); } @@ -479,6 +487,10 @@ void JSDatePicker::SetDisappearTextStyle(const JSCallbackInfo& info) if (info[0]->IsObject()) { JSDatePicker::ParseTextStyle(info[0], textStyle, "disappearTextStyle"); } + + if (SystemProperties::ConfigChangePerform()) { + DatePickerModel::GetInstance()->ParseDisappearTextStyleResObj(textStyle); + } DatePickerModel::GetInstance()->SetDisappearTextStyle(theme, textStyle); } @@ -490,6 +502,10 @@ void JSDatePicker::SetTextStyle(const JSCallbackInfo& info) if (info[0]->IsObject()) { JSDatePicker::ParseTextStyle(info[0], textStyle, "textStyle"); } + + if (SystemProperties::ConfigChangePerform()) { + DatePickerModel::GetInstance()->ParseNormalTextStyleResObj(textStyle); + } DatePickerModel::GetInstance()->SetNormalTextStyle(theme, textStyle); } @@ -510,6 +526,10 @@ void JSDatePicker::SetSelectedTextStyle(const JSCallbackInfo& info) if (info[0]->IsObject()) { JSDatePicker::ParseTextStyle(info[0], textStyle, "selectedTextStyle"); } + + if (SystemProperties::ConfigChangePerform()) { + DatePickerModel::GetInstance()->ParseSelectedTextStyleResObj(textStyle); + } DatePickerModel::GetInstance()->SetSelectedTextStyle(theme, textStyle); if (textStyle.textColor.has_value() && theme->IsCircleDial()) { DatePickerModel::GetInstance()->UpdateUserSetSelectColor(); @@ -1585,6 +1605,10 @@ void JSTimePicker::SetDisappearTextStyle(const JSCallbackInfo& info) if (info[0]->IsObject()) { JSDatePicker::ParseTextStyle(info[0], textStyle, "disappearTextStyleTime"); } + + if (SystemProperties::ConfigChangePerform()) { + TimePickerModel::GetInstance()->ParseDisappearTextStyleResObj(textStyle); + } TimePickerModel::GetInstance()->SetDisappearTextStyle(theme, textStyle); } @@ -1596,6 +1620,10 @@ void JSTimePicker::SetTextStyle(const JSCallbackInfo& info) if (info[0]->IsObject()) { JSDatePicker::ParseTextStyle(info[0], textStyle, "textStyleTime"); } + + if (SystemProperties::ConfigChangePerform()) { + TimePickerModel::GetInstance()->ParseNormalTextStyleResObj(textStyle); + } TimePickerModel::GetInstance()->SetNormalTextStyle(theme, textStyle); } @@ -1607,6 +1635,10 @@ void JSTimePicker::SetSelectedTextStyle(const JSCallbackInfo& info) if (info[0]->IsObject()) { JSDatePicker::ParseTextStyle(info[0], textStyle, "selectedTextStyleTime"); } + + if (SystemProperties::ConfigChangePerform()) { + TimePickerModel::GetInstance()->ParseSelectedTextStyleResObj(textStyle); + } TimePickerModel::GetInstance()->SetSelectedTextStyle(theme, textStyle); if (textStyle.textColor.has_value() && theme->IsCircleDial()) { TimePickerModel::GetInstance()->UpdateUserSetSelectColor(); diff --git a/frameworks/bridge/declarative_frontend/jsview/js_datepicker.h b/frameworks/bridge/declarative_frontend/jsview/js_datepicker.h index d3dad7597fb..23b7edcf93c 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_datepicker.h +++ b/frameworks/bridge/declarative_frontend/jsview/js_datepicker.h @@ -40,6 +40,7 @@ public: static void SetTextStyle(const JSCallbackInfo& info); static void SetSelectedTextStyle(const JSCallbackInfo& info); static void ParseTextStyle(const JSRef& paramObj, NG::PickerTextStyle& textStyle, const std::string& pos); + static void ParseTextStyleFontSize(const JSRef& fontSize, NG::PickerTextStyle& textStyle); static void ParseTextProperties(const JSRef& paramObj, NG::PickerTextProperties& result); // keep compatible, need remove after static void UseMilitaryTime(bool isUseMilitaryTime); diff --git a/frameworks/bridge/declarative_frontend/jsview/js_textpicker.cpp b/frameworks/bridge/declarative_frontend/jsview/js_textpicker.cpp index bf979fdbe8d..1fad5df1ae5 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_textpicker.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_textpicker.cpp @@ -35,6 +35,7 @@ #include "core/components_ng/pattern/text_picker/textpicker_model_ng.h" #include "core/components_ng/pattern/text_picker/textpicker_properties.h" #include "core/pipeline_ng/pipeline_context.h" +#include "core/common/resource/resource_object.h" namespace OHOS::Ace { namespace { @@ -190,6 +191,52 @@ std::vector ParseButtonStyles(const JSRef& paramObject) return buttonInfos; } + +bool CheckDividerValue(const Dimension &dimension) +{ + if (dimension.Value() >= 0.0f && dimension.Unit() != DimensionUnit::PERCENT) { + return true; + } + return false; +} + +void ParseDivider(JSRef& obj, NG::ItemDivider& divider) +{ + Dimension defaultStrokeWidth = 0.0_vp; + Dimension defaultMargin = 0.0_vp; + Color defaultColor = Color::TRANSPARENT; + + Dimension strokeWidth = defaultStrokeWidth; + RefPtr strokeWidthResObj; + if (ConvertFromJSValueNG(obj->GetProperty("strokeWidth"), strokeWidth, strokeWidthResObj) && + CheckDividerValue(strokeWidth)) { + divider.strokeWidth = strokeWidth; + divider.strokeWidthResObj = strokeWidthResObj; + } + + Color color = defaultColor; + RefPtr colorResObj; + if (ConvertFromJSValue(obj->GetProperty("color"), color, colorResObj)) { + divider.color = color; + divider.colorResObj = colorResObj; + } + + Dimension startMargin = defaultMargin; + RefPtr startMarginResObj; + if (ConvertFromJSValueNG(obj->GetProperty("startMargin"), startMargin, startMarginResObj) && + CheckDividerValue(startMargin)) { + divider.startMargin = startMargin; + divider.startMarginResObj = startMarginResObj; + } + + Dimension endMargin = defaultMargin; + RefPtr endMarginResObj; + if (ConvertFromJSValueNG(obj->GetProperty("endMargin"), endMargin, endMarginResObj) && + CheckDividerValue(endMargin)) { + divider.endMargin = endMargin; + divider.endMarginResObj = endMarginResObj; + } +} } // namespace void JSTextPicker::JSBind(BindingTarget globalObj) @@ -245,6 +292,10 @@ void JSTextPicker::SetDefaultTextStyle(const JSCallbackInfo& info) if (info.Length() >= 1 && info[0]->IsObject()) { JSTextPickerParser::ParseTextStyle(info[0], textStyle, "defaultTextStyle"); } + + if (SystemProperties::ConfigChangePerform()) { + TextPickerModel::GetInstance()->ParseDefaultTextStyleResObj(textStyle); + } TextPickerModel::GetInstance()->SetDefaultTextStyle(theme, textStyle); } @@ -947,15 +998,18 @@ void JSTextPickerParser::ParseDefaultTextStyle(const JSRef& paramObj, { auto minFontSize = paramObj->GetProperty("minFontSize"); auto maxFontSize = paramObj->GetProperty("maxFontSize"); + if (!minFontSize->IsNull() && !minFontSize->IsUndefined()) { CalcDimension minSize; - if (ParseJsDimensionFp(minFontSize, minSize) && minSize.Unit() != DimensionUnit::PERCENT) { + if (ParseJsDimensionFp(minFontSize, minSize, textStyle.minFontSizeResObj) && + minSize.Unit() != DimensionUnit::PERCENT) { textStyle.minFontSize = minSize; } } if (!maxFontSize->IsNull() && !maxFontSize->IsUndefined()) { CalcDimension maxSize; - if (ParseJsDimensionFp(maxFontSize, maxSize) && maxSize.Unit() != DimensionUnit::PERCENT) { + if (ParseJsDimensionFp(maxFontSize, maxSize, textStyle.maxFontSizeResObj) && + maxSize.Unit() != DimensionUnit::PERCENT) { textStyle.maxFontSize = maxSize; } } @@ -971,6 +1025,20 @@ void JSTextPickerParser::ParseDefaultTextStyle(const JSRef& paramObj, } } +void JSTextPickerParser::ParseTextStyleFontSize(const JSRef& fontSize, NG::PickerTextStyle& textStyle) +{ + if (fontSize->IsNull() || fontSize->IsUndefined()) { + textStyle.fontSize = Dimension(-1); + } else { + CalcDimension size; + if (!ParseJsDimensionFp(fontSize, size, textStyle.fontSizeResObj) || size.Unit() == DimensionUnit::PERCENT) { + textStyle.fontSize = Dimension(-1); + } else { + textStyle.fontSize = size; + } + } +} + void JSTextPickerParser::ParseTextStyle( const JSRef& paramObj, NG::PickerTextStyle& textStyle, const std::string& pos) { @@ -978,7 +1046,7 @@ void JSTextPickerParser::ParseTextStyle( auto fontOptions = paramObj->GetProperty("font"); Color textColor; - if (ParseJsColor(fontColor, textColor)) { + if (ParseJsColor(fontColor, textColor, textStyle.textColorResObj)) { textStyle.textColor = textColor; } @@ -992,16 +1060,8 @@ void JSTextPickerParser::ParseTextStyle( auto fontWeight = fontObj->GetProperty("weight"); auto fontFamily = fontObj->GetProperty("family"); auto fontStyle = fontObj->GetProperty("style"); - if (fontSize->IsNull() || fontSize->IsUndefined()) { - textStyle.fontSize = Dimension(-1); - } else { - CalcDimension size; - if (!ParseJsDimensionFp(fontSize, size) || size.Unit() == DimensionUnit::PERCENT) { - textStyle.fontSize = Dimension(-1); - } else { - textStyle.fontSize = size; - } - } + + ParseTextStyleFontSize(fontSize, textStyle); if (!fontWeight->IsNull() && !fontWeight->IsUndefined()) { std::string weight; @@ -1015,7 +1075,7 @@ void JSTextPickerParser::ParseTextStyle( if (!fontFamily->IsNull() && !fontFamily->IsUndefined()) { std::vector families; - if (ParseJsFontFamilies(fontFamily, families)) { + if (ParseJsFontFamilies(fontFamily, families, textStyle.fontFamilyResObj)) { textStyle.fontFamily = families; IsUserDefinedFontFamily(pos); } @@ -1047,6 +1107,7 @@ void JSTextPicker::SetDefaultPickerItemHeight(const JSCallbackInfo& info) void JSTextPicker::SetGradientHeight(const JSCallbackInfo& info) { CalcDimension height; + RefPtr heightResObj; auto pickerTheme = GetTheme(); if (info[0]->IsNull() || info[0]->IsUndefined()) { if (pickerTheme) { @@ -1056,7 +1117,7 @@ void JSTextPicker::SetGradientHeight(const JSCallbackInfo& info) } } if (info.Length() >= 1) { - if (!ConvertFromJSValueNG(info[0], height)) { + if (!ConvertFromJSValueNG(info[0], height, heightResObj)) { if (pickerTheme) { height = pickerTheme->GetGradientHeight(); } @@ -1070,6 +1131,10 @@ void JSTextPicker::SetGradientHeight(const JSCallbackInfo& info) } } } + + if (SystemProperties::ConfigChangePerform()) { + TextPickerModel::GetInstance()->ParseGradientHeight(heightResObj); + } TextPickerModel::GetInstance()->SetGradientHeight(height); } @@ -1099,6 +1164,10 @@ void JSTextPicker::SetDisappearTextStyle(const JSCallbackInfo& info) if (info.Length() >= 1 && info[0]->IsObject()) { JSTextPickerParser::ParseTextStyle(info[0], textStyle, "disappearTextStyle"); } + + if (SystemProperties::ConfigChangePerform()) { + TextPickerModel::GetInstance()->ParseDisappearTextStyleResObj(textStyle); + } TextPickerModel::GetInstance()->SetDisappearTextStyle(theme, textStyle); } @@ -1110,6 +1179,10 @@ void JSTextPicker::SetTextStyle(const JSCallbackInfo& info) if (info.Length() >= 1 && info[0]->IsObject()) { JSTextPickerParser::ParseTextStyle(info[0], textStyle, "textStyle"); } + + if (SystemProperties::ConfigChangePerform()) { + TextPickerModel::GetInstance()->ParseNormalTextStyleResObj(textStyle); + } TextPickerModel::GetInstance()->SetNormalTextStyle(theme, textStyle); } @@ -1121,6 +1194,10 @@ void JSTextPicker::SetSelectedTextStyle(const JSCallbackInfo& info) if (info.Length() >= 1 && info[0]->IsObject()) { JSTextPickerParser::ParseTextStyle(info[0], textStyle, "selectedTextStyle"); } + + if (SystemProperties::ConfigChangePerform()) { + TextPickerModel::GetInstance()->ParseSelectedTextStyleResObj(textStyle); + } TextPickerModel::GetInstance()->SetSelectedTextStyle(theme, textStyle); if (textStyle.textColor.has_value() && theme->IsCircleDial()) { TextPickerModel::GetInstance()->UpdateUserSetSelectColor(); @@ -1278,20 +1355,11 @@ void JSTextPicker::SetSelectedIndex(const JSCallbackInfo& info) } } -bool JSTextPicker::CheckDividerValue(const Dimension &dimension) -{ - if (dimension.Value() >= 0.0f && dimension.Unit() != DimensionUnit::PERCENT) { - return true; - } - return false; -} - void JSTextPicker::SetDivider(const JSCallbackInfo& info) { NG::ItemDivider divider; auto pickerTheme = GetTheme(); Dimension defaultStrokeWidth = 0.0_vp; - Dimension defaultMargin = 0.0_vp; Color defaultColor = Color::TRANSPARENT; // Set default strokeWidth and color if (pickerTheme) { @@ -1303,29 +1371,14 @@ void JSTextPicker::SetDivider(const JSCallbackInfo& info) if (info.Length() >= 1 && info[0]->IsObject()) { JSRef obj = JSRef::Cast(info[0]); - - Dimension strokeWidth = defaultStrokeWidth; - if (ConvertFromJSValueNG(obj->GetProperty("strokeWidth"), strokeWidth) && CheckDividerValue(strokeWidth)) { - divider.strokeWidth = strokeWidth; - } - - Color color = defaultColor; - if (ConvertFromJSValue(obj->GetProperty("color"), color)) { - divider.color = color; - } - - Dimension startMargin = defaultMargin; - if (ConvertFromJSValueNG(obj->GetProperty("startMargin"), startMargin) && CheckDividerValue(startMargin)) { - divider.startMargin = startMargin; - } - - Dimension endMargin = defaultMargin; - if (ConvertFromJSValueNG(obj->GetProperty("endMargin"), endMargin) && CheckDividerValue(endMargin)) { - divider.endMargin = endMargin; - } + ParseDivider(obj, divider); } else if (info.Length() >= 1 && info[0]->IsNull()) { divider.strokeWidth = 0.0_vp; } + + if (SystemProperties::ConfigChangePerform()) { + TextPickerModel::GetInstance()->ParseDividerResObj(); + } TextPickerModel::GetInstance()->SetDivider(divider); } diff --git a/frameworks/bridge/declarative_frontend/jsview/js_textpicker.h b/frameworks/bridge/declarative_frontend/jsview/js_textpicker.h index 73c3baf63d9..34b72c311a7 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_textpicker.h +++ b/frameworks/bridge/declarative_frontend/jsview/js_textpicker.h @@ -48,6 +48,7 @@ public: static bool ParseIconTextArray(const JSRef& paramObject, ParseTextArrayParam& param); static bool ParseTextArray(const JSRef& paramObject, ParseTextArrayParam& param); static void ParseTextStyle(const JSRef& paramObj, NG::PickerTextStyle& textStyle, const std::string& pos); + static void ParseTextStyleFontSize(const JSRef& fontSize, NG::PickerTextStyle& textStyle); static bool ParseMultiTextArray(const JSRef& paramObj, ParseTextArrayParam& param); static bool ParseCascadeTextArray(const JSRef& paramObj, std::vector& selecteds, std::vector& values, NG::TextCascadePickerOptionsAttr& attr); diff --git a/frameworks/bridge/declarative_frontend/jsview/models/calendar_picker_model_impl.h b/frameworks/bridge/declarative_frontend/jsview/models/calendar_picker_model_impl.h index 3acd586e00c..60fb20f267b 100644 --- a/frameworks/bridge/declarative_frontend/jsview/models/calendar_picker_model_impl.h +++ b/frameworks/bridge/declarative_frontend/jsview/models/calendar_picker_model_impl.h @@ -17,12 +17,15 @@ #define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_MODELS_CALENDAR_PICKER_MODEL_IMPL_H #include "core/components_ng/pattern/calendar_picker/calendar_picker_model.h" +#include "core/common/resource/resource_object.h" namespace OHOS::Ace::Framework { class CalendarPickerModelImpl : public OHOS::Ace::CalendarPickerModel { public: void Create(const NG::CalendarSettingData& settingData) override {}; void SetEdgeAlign(const NG::CalendarEdgeAlign& alignType, const DimensionOffset& offset) override {}; + void SetEdgeAlign(const NG::CalendarEdgeAlign& alignType, const DimensionOffset& offset, + const std::vector>& resArray) override {}; void SetTextStyle(const NG::PickerTextStyle& textStyle) override {}; void SetOnChange(NG::SelectedChangeEvent&& onChange) override {}; void SetChangeEvent(NG::SelectedChangeEvent&& onChange) override {}; diff --git a/frameworks/core/components_ng/pattern/calendar/calendar_month_pattern.cpp b/frameworks/core/components_ng/pattern/calendar/calendar_month_pattern.cpp index 38a41d6887b..01deb9d156e 100644 --- a/frameworks/core/components_ng/pattern/calendar/calendar_month_pattern.cpp +++ b/frameworks/core/components_ng/pattern/calendar/calendar_month_pattern.cpp @@ -363,6 +363,11 @@ void CalendarMonthPattern::OnColorConfigurationUpdate() CHECK_NULL_VOID(textLayoutProperty); textLayoutProperty->UpdateTextColor(theme->GetCalendarTheme().weekColor); } + + if (SystemProperties::ConfigChangePerform()) { + rowNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE); + swiperNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE); + } } void CalendarMonthPattern::OnLanguageConfigurationUpdate() @@ -1143,4 +1148,23 @@ void CalendarMonthPattern::ModifyAccessibilityVirtualNode(const ObtainedMonth& c ChangeVirtualNodeContent(day); } } + +void CalendarMonthPattern::UpdateDayRadius(const CalcDimension& dayRadius) +{ + auto host = GetHost(); + CHECK_NULL_VOID(host); + auto paintProperty = host->GetPaintProperty(); + CHECK_NULL_VOID(paintProperty); + + auto pipelineContext = host->GetContext(); + CHECK_NULL_VOID(pipelineContext); + + if (pipelineContext->IsSystmColorChange()) { + paintProperty->UpdateDayRadius(dayRadius); + } + + if (host->GetRerenderable()) { + host->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF); + } +} } // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/calendar/calendar_month_pattern.h b/frameworks/core/components_ng/pattern/calendar/calendar_month_pattern.h index 9253cb3746f..16494cc4fd1 100644 --- a/frameworks/core/components_ng/pattern/calendar/calendar_month_pattern.h +++ b/frameworks/core/components_ng/pattern/calendar/calendar_month_pattern.h @@ -139,6 +139,8 @@ public: void FireIsFoldStatusChanged(); + void UpdateDayRadius(const CalcDimension& dayRadius); + private: void OnAttachToFrameNode() override; void OnColorConfigurationUpdate() override; diff --git a/frameworks/core/components_ng/pattern/calendar_picker/calendar_dialog_pattern.cpp b/frameworks/core/components_ng/pattern/calendar_picker/calendar_dialog_pattern.cpp index 4924515ad14..6da548c6990 100644 --- a/frameworks/core/components_ng/pattern/calendar_picker/calendar_dialog_pattern.cpp +++ b/frameworks/core/components_ng/pattern/calendar_picker/calendar_dialog_pattern.cpp @@ -1458,6 +1458,11 @@ void CalendarDialogPattern::OnColorConfigurationUpdate() CHECK_NULL_VOID(textLayoutProperty); textLayoutProperty->UpdateTextColor(theme->GetCalendarTitleFontColor()); + + if (SystemProperties::ConfigChangePerform()) { + titleNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE); + OnModifyDone(); + } } void CalendarDialogPattern::ToJsonValue(std::unique_ptr& json, const InspectorFilter& filter) const diff --git a/frameworks/core/components_ng/pattern/calendar_picker/calendar_dialog_view.cpp b/frameworks/core/components_ng/pattern/calendar_picker/calendar_dialog_view.cpp index 0ade8b61aab..fee97688f8c 100644 --- a/frameworks/core/components_ng/pattern/calendar_picker/calendar_dialog_view.cpp +++ b/frameworks/core/components_ng/pattern/calendar_picker/calendar_dialog_view.cpp @@ -37,6 +37,7 @@ #include "core/components_ng/pattern/text/text_layout_property.h" #include "core/pipeline_ng/pipeline_context.h" #include "interfaces/inner_api/ui_session/ui_session_manager.h" +#include "core/common/resource/resource_parse_utils.h" namespace OHOS::Ace::NG { namespace { @@ -557,6 +558,16 @@ RefPtr CalendarDialogView::CreateCalendarMonthNode(int32_t calendarNo ViewStackProcessor::GetInstance()->Finish(); auto monthPattern = monthFrameNode->GetPattern(); CHECK_NULL_RETURN(monthPattern, nullptr); + + if (settingData.dayRadiusResObj) { + auto&& updateFunc = [monthPattern, monthFrameNode](const RefPtr& resObj) { + CalcDimension dayRadius; + ResourceParseUtils::ParseResDimensionVpNG(resObj, dayRadius); + monthPattern->UpdateDayRadius(dayRadius); + }; + monthPattern->AddResObj("CalendarDayRadius", settingData.dayRadiusResObj, std::move(updateFunc)); + } + monthPattern->SetCalendarDialogFlag(true); auto calendarEventHub = monthPattern->GetOrCreateEventHub(); CHECK_NULL_RETURN(calendarEventHub, nullptr); diff --git a/frameworks/core/components_ng/pattern/calendar_picker/calendar_picker_model.h b/frameworks/core/components_ng/pattern/calendar_picker/calendar_picker_model.h index e5c006a0440..6204419c0ac 100644 --- a/frameworks/core/components_ng/pattern/calendar_picker/calendar_picker_model.h +++ b/frameworks/core/components_ng/pattern/calendar_picker/calendar_picker_model.h @@ -23,6 +23,7 @@ #include "core/components_ng/pattern/calendar_picker/calendar_picker_event_hub.h" #include "core/components_ng/pattern/calendar_picker/calendar_type_define.h" #include "core/components_ng/pattern/picker/picker_type_define.h" +#include "core/common/resource/resource_object.h" namespace OHOS::Ace { class ACE_FORCE_EXPORT CalendarPickerModel { @@ -32,6 +33,8 @@ public: virtual void Create(const NG::CalendarSettingData& settingData) = 0; virtual void SetEdgeAlign(const NG::CalendarEdgeAlign& alignType, const DimensionOffset& offset) = 0; + virtual void SetEdgeAlign(const NG::CalendarEdgeAlign& alignType, const DimensionOffset& offset, + const std::vector>& resArray); virtual void SetTextStyle(const NG::PickerTextStyle& textStyle) = 0; virtual void SetOnChange(NG::SelectedChangeEvent&& onChange) = 0; virtual void SetChangeEvent(NG::SelectedChangeEvent&& onChange) = 0; @@ -43,6 +46,7 @@ public: virtual void ClearBorderWidth() = 0; virtual void ClearPadding() = 0; virtual void SetMarkToday(bool isMarkToday) = 0; + virtual void ParseNormalTextStyleResObj(const NG::PickerTextStyle& textStyleOpt) {}; private: static std::unique_ptr instance_; diff --git a/frameworks/core/components_ng/pattern/calendar_picker/calendar_picker_model_ng.cpp b/frameworks/core/components_ng/pattern/calendar_picker/calendar_picker_model_ng.cpp index d6da3c55108..e77b614352d 100644 --- a/frameworks/core/components_ng/pattern/calendar_picker/calendar_picker_model_ng.cpp +++ b/frameworks/core/components_ng/pattern/calendar_picker/calendar_picker_model_ng.cpp @@ -24,6 +24,8 @@ #include "core/components_ng/pattern/image/image_pattern.h" #include "core/components_ng/pattern/text/text_pattern.h" #include "core/components_ng/pattern/text_field/text_field_pattern.h" +#include "core/common/resource/resource_object.h" +#include "core/common/resource/resource_parse_utils.h" namespace OHOS::Ace::NG { constexpr int32_t YEAR_NODE_INDEX = 0; @@ -294,6 +296,50 @@ void CalendarPickerModelNG::SetEdgeAlign(const CalendarEdgeAlign& alignType, con ACE_UPDATE_LAYOUT_PROPERTY(CalendarPickerLayoutProperty, DialogOffset, offset); } +void CalendarPickerModelNG::SetEdgeAlign(const CalendarEdgeAlign& alignType, const DimensionOffset& offset, + const std::vector>& resArray) +{ + auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); + CHECK_NULL_VOID(frameNode); + auto pickerPattern = frameNode->GetPattern(); + CHECK_NULL_VOID(pickerPattern); + + auto&& updateFunc = [offset, resArray, weak = AceType::WeakClaim(frameNode)](const RefPtr resObj) { + auto frameNode = weak.Upgrade(); + CHECK_NULL_VOID(frameNode); + + auto calendarPickerPattern = frameNode->GetPattern(); + CHECK_NULL_VOID(calendarPickerPattern); + + DimensionOffset &offsetValue = const_cast(offset); + const std::vector>& resArrayValue = resArray; + + CalcDimension dx = offsetValue.GetX(); + CalcDimension dy = offsetValue.GetY(); + if (resArrayValue[0]) { + ResourceParseUtils::ParseResDimensionVp(resArrayValue[0], dx); + } + + if (resArrayValue[1]) { + ResourceParseUtils::ParseResDimensionVp(resArrayValue[1], dy); + } + + DimensionOffset offsetNew = DimensionOffset(dx, dy); + + calendarPickerPattern->SetCalendarDialogOffset(offset); + ACE_UPDATE_LAYOUT_PROPERTY(CalendarPickerLayoutProperty, DialogOffset, offsetNew); + }; + + RefPtr resObj = AceType::MakeRefPtr(); + pickerPattern->AddResObj("CalendarPickerEdgeAlign", resObj, std::move(updateFunc)); + + pickerPattern->SetCalendarEdgeAlign(alignType); + pickerPattern->SetCalendarDialogOffset(offset); + + ACE_UPDATE_LAYOUT_PROPERTY(CalendarPickerLayoutProperty, DialogAlignType, alignType); + ACE_UPDATE_LAYOUT_PROPERTY(CalendarPickerLayoutProperty, DialogOffset, offset); +} + void CalendarPickerModelNG::SetTextStyle(const PickerTextStyle& textStyle) { auto pipeline = PipelineBase::GetCurrentContext(); @@ -860,4 +906,43 @@ std::string CalendarPickerModelNG::GetDisabledDateRange(FrameNode* frameNode) CHECK_NULL_RETURN(pickerPattern, ""); return pickerPattern->GetDisabledDateRange(); } + +void CalendarPickerModelNG::ParseNormalTextStyleResObj(const PickerTextStyle& textStyleOpt) +{ + if (!SystemProperties::ConfigChangePerform()) { + return; + } + + auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); + CHECK_NULL_VOID(frameNode); + + auto pickerPattern = frameNode->GetPattern(); + CHECK_NULL_VOID(pickerPattern); + + auto&& updateFunc = [textStyleOpt, frameNode](const RefPtr resObj) { + PickerTextStyle textStyle; + auto pickerPattern = frameNode->GetPattern(); + CHECK_NULL_VOID(pickerPattern); + Color color; + if (textStyleOpt.textColorResObj && + ResourceParseUtils::ParseResColor(textStyleOpt.textColorResObj, color)) { + textStyle.textColor = color; + } + + CalcDimension fontSize; + if (textStyleOpt.fontSizeResObj && + ResourceParseUtils::ParseResDimensionFp(textStyleOpt.fontSizeResObj, fontSize)) { + textStyle.fontSize = fontSize; + } + + std::vector families; + if (textStyleOpt.fontFamilyResObj && + ResourceParseUtils::ParseResFontFamilies(textStyleOpt.fontFamilyResObj, families)) { + textStyle.fontFamily = families; + } + pickerPattern->UpdateTextStyle(textStyle); + }; + RefPtr resObj = AceType::MakeRefPtr(); + pickerPattern->AddResObj("CalendarPickerNormalTextStyle", resObj, std::move(updateFunc)); +} } // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/calendar_picker/calendar_picker_model_ng.h b/frameworks/core/components_ng/pattern/calendar_picker/calendar_picker_model_ng.h index 6b29b3d09b1..0fe995aa18f 100644 --- a/frameworks/core/components_ng/pattern/calendar_picker/calendar_picker_model_ng.h +++ b/frameworks/core/components_ng/pattern/calendar_picker/calendar_picker_model_ng.h @@ -25,6 +25,8 @@ class ACE_EXPORT CalendarPickerModelNG : public CalendarPickerModel { public: void Create(const CalendarSettingData& settingData) override; void SetEdgeAlign(const CalendarEdgeAlign& alignType, const DimensionOffset& offset) override; + void SetEdgeAlign(const NG::CalendarEdgeAlign& alignType, const DimensionOffset& offset, + const std::vector>& resArray) override; void SetTextStyle(const PickerTextStyle& textStyle) override; void SetOnChange(SelectedChangeEvent&& onChange) override; void SetChangeEvent(SelectedChangeEvent&& onChange) override; @@ -36,6 +38,8 @@ public: void ClearBorderWidth() override; void ClearPadding() override; void SetMarkToday(bool isMarkToday) override; + void ParseNormalTextStyleResObj(const PickerTextStyle& textStyleOpt) override; + static RefPtr CreateNode(int32_t nodeId, const CalendarSettingData& settingData); static RefPtr CreateFrameNode(int32_t nodeId); static void SetTextStyle(FrameNode* frameNode, const PickerTextStyle& textStyle); diff --git a/frameworks/core/components_ng/pattern/calendar_picker/calendar_picker_pattern.cpp b/frameworks/core/components_ng/pattern/calendar_picker/calendar_picker_pattern.cpp index ebeb2d20fd2..0015cf75933 100644 --- a/frameworks/core/components_ng/pattern/calendar_picker/calendar_picker_pattern.cpp +++ b/frameworks/core/components_ng/pattern/calendar_picker/calendar_picker_pattern.cpp @@ -394,7 +394,7 @@ void CalendarPickerPattern::ResetTextStateByNode(const RefPtr& textFr CHECK_NULL_VOID(host); auto layoutProperty = host->GetLayoutProperty(); CHECK_NULL_VOID(layoutProperty); - auto pipeline = PipelineBase::GetCurrentContext(); + auto pipeline = host->GetContext(); CHECK_NULL_VOID(pipeline); RefPtr calendarTheme = pipeline->GetTheme(); CHECK_NULL_VOID(calendarTheme); @@ -1462,4 +1462,30 @@ std::string CalendarPickerPattern::GetDisabledDateRange() } return disabledDateRangeStr; } + +void CalendarPickerPattern::UpdateTextStyle(const PickerTextStyle& textStyle) +{ + auto host = GetHost(); + CHECK_NULL_VOID(host); + auto pipelineContext = host->GetContext(); + CHECK_NULL_VOID(pipelineContext); + auto calendarTheme = pipelineContext->GetTheme(host->GetThemeScopeId()); + CHECK_NULL_VOID(calendarTheme); + auto pickerProperty = host->GetPaintProperty(); + CHECK_NULL_VOID(pickerProperty); + + if (pipelineContext->IsSystmColorChange()) { + pickerProperty->UpdateColor(textStyle.textColor.value_or(calendarTheme->GetEntryFontColor())); + + Dimension fontSize = calendarTheme->GetEntryFontSize(); + if (textStyle.fontSize.has_value() && textStyle.fontSize->IsValid()) { + fontSize = textStyle.fontSize.value(); + } + pickerProperty->UpdateFontSize(fontSize); + } + + if (host->GetRerenderable()) { + host->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF); + } +} } // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/calendar_picker/calendar_picker_pattern.h b/frameworks/core/components_ng/pattern/calendar_picker/calendar_picker_pattern.h index b21624243cc..784cf004b2f 100644 --- a/frameworks/core/components_ng/pattern/calendar_picker/calendar_picker_pattern.h +++ b/frameworks/core/components_ng/pattern/calendar_picker/calendar_picker_pattern.h @@ -33,6 +33,14 @@ public: CalendarPickerPattern() : LinearLayoutPattern(false) {}; ~CalendarPickerPattern() override = default; + void OnColorModeChange(uint32_t colorMode) override + { + LinearLayoutPattern::OnColorModeChange(colorMode); + auto host = GetHost(); + CHECK_NULL_VOID(host); + host->MarkModifyDone(); + } + bool IsAtomicNode() const override { return true; @@ -180,6 +188,7 @@ public: bool GetMarkToday(); void SetDisabledDateRange(const std::vector>& disabledDateRange); std::string GetDisabledDateRange(); + void UpdateTextStyle(const PickerTextStyle& textStyle); private: void OnModifyDone() override; diff --git a/frameworks/core/components_ng/pattern/calendar_picker/calendar_type_define.h b/frameworks/core/components_ng/pattern/calendar_picker/calendar_type_define.h index 5c6bd0c1015..8d2db071c06 100644 --- a/frameworks/core/components_ng/pattern/calendar_picker/calendar_type_define.h +++ b/frameworks/core/components_ng/pattern/calendar_picker/calendar_type_define.h @@ -24,6 +24,7 @@ #include "core/components/picker/picker_data.h" #include "core/components_ng/base/frame_node.h" #include "core/components_ng/pattern/picker/picker_type_define.h" +#include "core/common/resource/resource_object.h" namespace OHOS::Ace::NG { enum class CalendarEdgeAlign { @@ -46,6 +47,7 @@ struct CalendarSettingData { PickerDate startDate; PickerDate endDate; std::optional dayRadius; + RefPtr dayRadiusResObj; WeakPtr entryNode = nullptr; std::vector> disabledDateRange; bool markToday = false; diff --git a/frameworks/core/components_ng/pattern/picker/datepicker_column_pattern.cpp b/frameworks/core/components_ng/pattern/picker/datepicker_column_pattern.cpp index 11592484b0e..b10ff1c1d4d 100644 --- a/frameworks/core/components_ng/pattern/picker/datepicker_column_pattern.cpp +++ b/frameworks/core/components_ng/pattern/picker/datepicker_column_pattern.cpp @@ -100,7 +100,9 @@ void DatePickerColumnPattern::OnDetachFromFrameNode(FrameNode* frameNode) void DatePickerColumnPattern::OnModifyDone() { - auto pipeline = PipelineBase::GetCurrentContext(); + auto host = GetHost(); + CHECK_NULL_VOID(host); + auto pipeline = host->GetContext(); CHECK_NULL_VOID(pipeline); auto theme = pipeline->GetTheme(GetThemeScopeId()); CHECK_NULL_VOID(theme); @@ -636,7 +638,9 @@ void DatePickerColumnPattern::UpdatePickerTextProperties(uint32_t index, uint32_ const RefPtr& textLayoutProperty, const RefPtr& dataPickerRowLayoutProperty) { - auto pipeline = PipelineBase::GetCurrentContext(); + auto host = GetHost(); + CHECK_NULL_VOID(host); + auto pipeline = host->GetContext(); CHECK_NULL_VOID(pipeline); auto pickerTheme = pipeline->GetTheme(GetThemeScopeId()); CHECK_NULL_VOID(pickerTheme); @@ -741,7 +745,9 @@ void DatePickerColumnPattern::UpdateSelectedTextProperties(const RefPtrGetContext(); CHECK_NULL_VOID(pipeline); auto pickerTheme = pipeline->GetTheme(); CHECK_NULL_VOID(pickerTheme); diff --git a/frameworks/core/components_ng/pattern/picker/datepicker_dialog_view.cpp b/frameworks/core/components_ng/pattern/picker/datepicker_dialog_view.cpp index 64165eec613..519ad689673 100644 --- a/frameworks/core/components_ng/pattern/picker/datepicker_dialog_view.cpp +++ b/frameworks/core/components_ng/pattern/picker/datepicker_dialog_view.cpp @@ -324,7 +324,9 @@ RefPtr DatePickerDialogView::CreateTitleButtonRowNode() void DatePickerDialogView::CreateTitleIconNode(const RefPtr& titleNode) { - auto pipeline = PipelineContext::GetCurrentContext(); + auto container = Container::Current(); + CHECK_NULL_VOID(container); + auto pipeline = container->GetPipelineContext(); CHECK_NULL_VOID(pipeline); auto iconTheme = pipeline->GetTheme(); CHECK_NULL_VOID(iconTheme); diff --git a/frameworks/core/components_ng/pattern/picker/datepicker_model_ng.cpp b/frameworks/core/components_ng/pattern/picker/datepicker_model_ng.cpp index 65f1ebd93d0..9612293ef15 100644 --- a/frameworks/core/components_ng/pattern/picker/datepicker_model_ng.cpp +++ b/frameworks/core/components_ng/pattern/picker/datepicker_model_ng.cpp @@ -14,6 +14,7 @@ */ #include "core/components_ng/pattern/picker/datepicker_model_ng.h" +#include #include #include "base/geometry/dimension.h" @@ -32,6 +33,8 @@ #include "core/components_ng/pattern/text/text_layout_property.h" #include "core/components_ng/pattern/text/text_pattern.h" #include "core/components_v2/inspector/inspector_constants.h" +#include "core/common/resource/resource_object.h" +#include "core/common/resource/resource_parse_utils.h" namespace OHOS::Ace::NG { namespace { @@ -969,4 +972,88 @@ void DatePickerModelNG::UpdateUserSetSelectColor() datePickerPattern->UpdateUserSetSelectColor(); } +void DatePickerModelNG::ParseResTextStyle(const PickerTextStyle& textStyleOpt, const std::string& textStyleType, + std::function updateTextStyleFunc) +{ + if (!SystemProperties::ConfigChangePerform()) { + return; + } + + auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); + CHECK_NULL_VOID(frameNode); + + auto pickerPattern = frameNode->GetPattern(); + CHECK_NULL_VOID(pickerPattern); + + auto&& updateFunc = [textStyleOpt, frameNode, updateTextStyleFunc](const RefPtr resObj) { + PickerTextStyle textStyle; + Color color; + CalcDimension fontSize; + std::vector families; + + if (textStyleOpt.textColorResObj && + ResourceParseUtils::ParseResColor(textStyleOpt.textColorResObj, color)) { + textStyle.textColor = color; + } + + if (textStyleOpt.fontSizeResObj && + ResourceParseUtils::ParseResDimensionFp(textStyleOpt.fontSizeResObj, fontSize)) { + textStyle.fontSize = fontSize; + } + + if (textStyleOpt.fontFamilyResObj && + ResourceParseUtils::ParseResFontFamilies(textStyleOpt.fontFamilyResObj, families)) { + textStyle.fontFamily = families; + } + + updateTextStyleFunc(textStyle); + }; + RefPtr resObj = AceType::MakeRefPtr(); + pickerPattern->AddResObj(textStyleType, resObj, std::move(updateFunc)); +} + +void DatePickerModelNG::ParseDisappearTextStyleResObj(const PickerTextStyle& textStyleOpt) +{ + auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); + CHECK_NULL_VOID(frameNode); + + auto pickerPattern = frameNode->GetPattern(); + CHECK_NULL_VOID(pickerPattern); + + ParseResTextStyle( + textStyleOpt, + "DatePickerDisappearTextStyle", + [pickerPattern](const PickerTextStyle& textStyle) { pickerPattern->UpdateDisappearTextStyle(textStyle); } + ); +} + +void DatePickerModelNG::ParseSelectedTextStyleResObj(const PickerTextStyle& textStyleOpt) +{ + auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); + CHECK_NULL_VOID(frameNode); + + auto pickerPattern = frameNode->GetPattern(); + CHECK_NULL_VOID(pickerPattern); + + ParseResTextStyle( + textStyleOpt, + "DatePickerSelectedTextStyle", + [pickerPattern](const PickerTextStyle& textStyle) { pickerPattern->UpdateSelectedTextStyle(textStyle); } + ); +} + +void DatePickerModelNG::ParseNormalTextStyleResObj(const PickerTextStyle& textStyleOpt) +{ + auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); + CHECK_NULL_VOID(frameNode); + + auto pickerPattern = frameNode->GetPattern(); + CHECK_NULL_VOID(pickerPattern); + + ParseResTextStyle( + textStyleOpt, + "DatePickerNormalTextStyle", + [pickerPattern](const PickerTextStyle& textStyle) { pickerPattern->UpdateNormalTextStyle(textStyle); } + ); +} } // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/picker/datepicker_model_ng.h b/frameworks/core/components_ng/pattern/picker/datepicker_model_ng.h index 6dcb7b5d45d..b5b9da6e785 100644 --- a/frameworks/core/components_ng/pattern/picker/datepicker_model_ng.h +++ b/frameworks/core/components_ng/pattern/picker/datepicker_model_ng.h @@ -57,6 +57,9 @@ public: static RefPtr CreateFrameNode(int32_t nodeId); void SetChangeEvent(DateChangeEvent&& onChange) override; void SetDigitalCrownSensitivity(int32_t crownSensitivity) override; + void ParseDisappearTextStyleResObj(const PickerTextStyle& textStyleOpt) override; + void ParseSelectedTextStyleResObj(const PickerTextStyle& textStyleOpt) override; + void ParseNormalTextStyleResObj(const PickerTextStyle& textStyleOpt) override; static void SetSelectedTextStyle( FrameNode* frameNode, const RefPtr& theme, const PickerTextStyle& value); static void SetNormalTextStyle( @@ -84,6 +87,9 @@ private: static RefPtr CreateColumnNode(); static RefPtr CreateButtonNode(); void CreateDateColumn(const RefPtr& columnNode, const RefPtr& dateNode); + void ParseResTextStyle(const PickerTextStyle& textStyleOpt, const std::string& textStyleType, + std::function updateTextStyleFunc); + std::string dateOrder = ""; std::string dateTimeOrder = ""; }; diff --git a/frameworks/core/components_ng/pattern/picker/datepicker_pattern.cpp b/frameworks/core/components_ng/pattern/picker/datepicker_pattern.cpp index 4740d4803ea..91f1fcd9fd0 100644 --- a/frameworks/core/components_ng/pattern/picker/datepicker_pattern.cpp +++ b/frameworks/core/components_ng/pattern/picker/datepicker_pattern.cpp @@ -15,6 +15,7 @@ #include "core/components_ng/pattern/picker/datepicker_pattern.h" +#include #include #include #include @@ -61,6 +62,7 @@ const int32_t MONTH_DECEMBER = 12; constexpr int32_t RATIO_ZERO = 0; constexpr int32_t RATIO_ONE = 1; constexpr int32_t SECOND_PAGE = 1; +constexpr float PICKER_MAXFONTSCALE = 1.0f; } // namespace bool DatePickerPattern::inited_ = false; const std::string DatePickerPattern::empty_; @@ -637,15 +639,20 @@ void DatePickerPattern::OnColorConfigurationUpdate() CHECK_NULL_VOID(pickerTheme); auto dialogTheme = context->GetTheme(); CHECK_NULL_VOID(dialogTheme); - auto disappearStyle = pickerTheme->GetDisappearOptionStyle(); - auto normalStyle = pickerTheme->GetOptionStyle(false, false); - auto pickerProperty = host->GetLayoutProperty(); - CHECK_NULL_VOID(pickerProperty); - pickerProperty->UpdateColor(GetTextProperties().normalTextStyle_.textColor.value_or(normalStyle.GetTextColor())); - pickerProperty->UpdateDisappearColor( - GetTextProperties().disappearTextStyle_.textColor.value_or(disappearStyle.GetTextColor())); + if (!SystemProperties::ConfigChangePerform()) { + auto disappearStyle = pickerTheme->GetDisappearOptionStyle(); + auto normalStyle = pickerTheme->GetOptionStyle(false, false); + auto pickerProperty = host->GetLayoutProperty(); + CHECK_NULL_VOID(pickerProperty); + pickerProperty->UpdateColor( + GetTextProperties().normalTextStyle_.textColor.value_or(normalStyle.GetTextColor())); + pickerProperty->UpdateDisappearColor( + GetTextProperties().disappearTextStyle_.textColor.value_or(disappearStyle.GetTextColor())); + } if (isPicker_) { - OnModifyDone(); + if (!SystemProperties::ConfigChangePerform()) { + OnModifyDone(); + } return; } SetBackgroundColor(dialogTheme->GetBackgroundColor()); @@ -3050,4 +3057,118 @@ bool DatePickerPattern::CurrentIsLunar() return rowLayoutProperty->GetLunarValue(false); } +Dimension DatePickerPattern::ConvertFontScaleValue(const Dimension& fontSizeValue) +{ + auto host = GetHost(); + CHECK_NULL_RETURN(host, fontSizeValue); + auto pipeline = host->GetContext(); + CHECK_NULL_RETURN(pipeline, fontSizeValue); + + auto maxAppFontScale = pipeline->GetMaxAppFontScale(); + auto follow = pipeline->IsFollowSystem(); + float fontScale = pipeline->GetFontScale(); + if (NearZero(fontScale) || (fontSizeValue.Unit() == DimensionUnit::VP)) { + return fontSizeValue; + } + if (GreatOrEqualCustomPrecision(fontScale, PICKER_MAXFONTSCALE) && follow) { + fontScale = std::clamp(fontScale, 0.0f, maxAppFontScale); + if (!NearZero(fontScale)) { + return Dimension(fontSizeValue / fontScale); + } + } + return fontSizeValue; +} + +void DatePickerPattern::UpdateTextStyleCommon( + const PickerTextStyle& textStyle, + const TextStyle& defaultTextStyle, + std::function updateTextColorFunc, + std::function updateFontSizeFunc, + std::function&)> updateFontFamilyFunc +) +{ + auto host = GetHost(); + CHECK_NULL_VOID(host); + auto pickerProperty = GetLayoutProperty(); + CHECK_NULL_VOID(pickerProperty); + + auto pipelineContext = host->GetContext(); + CHECK_NULL_VOID(pipelineContext); + + if (pipelineContext->IsSystmColorChange()) { + updateTextColorFunc(textStyle.textColor.value_or(defaultTextStyle.GetTextColor())); + + Dimension fontSize = defaultTextStyle.GetFontSize(); + if (textStyle.fontSize.has_value() && textStyle.fontSize->IsValid()) { + fontSize = textStyle.fontSize.value(); + } + updateFontSizeFunc(ConvertFontScaleValue(fontSize)); + + updateFontFamilyFunc(textStyle.fontFamily.value_or(defaultTextStyle.GetFontFamilies())); + } + + if (host->GetRerenderable()) { + host->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF); + } +} + +void DatePickerPattern::UpdateDisappearTextStyle(const PickerTextStyle& textStyle) +{ + auto host = GetHost(); + CHECK_NULL_VOID(host); + auto context = host->GetContext(); + CHECK_NULL_VOID(context); + auto pickerTheme = context->GetTheme(host->GetThemeScopeId()); + CHECK_NULL_VOID(pickerTheme); + auto defaultTextStyle = pickerTheme->GetDisappearOptionStyle(); + auto pickerProperty = GetLayoutProperty(); + CHECK_NULL_VOID(pickerProperty); + UpdateTextStyleCommon( + textStyle, + defaultTextStyle, + [&](const Color& color) { pickerProperty->UpdateDisappearColor(color); }, + [&](const Dimension& fontSize) { pickerProperty->UpdateDisappearFontSize(fontSize); }, + [&](const std::vector& fontFamily) { pickerProperty->UpdateDisappearFontFamily(fontFamily); } + ); +} + +void DatePickerPattern::UpdateNormalTextStyle(const PickerTextStyle& textStyle) +{ + auto host = GetHost(); + CHECK_NULL_VOID(host); + auto context = host->GetContext(); + CHECK_NULL_VOID(context); + auto pickerTheme = context->GetTheme(host->GetThemeScopeId()); + CHECK_NULL_VOID(pickerTheme); + auto defaultTextStyle = pickerTheme->GetOptionStyle(false, false); + auto pickerProperty = GetLayoutProperty(); + CHECK_NULL_VOID(pickerProperty); + UpdateTextStyleCommon( + textStyle, + defaultTextStyle, + [&](const Color& color) { pickerProperty->UpdateColor(color); }, + [&](const Dimension& fontSize) { pickerProperty->UpdateFontSize(fontSize); }, + [&](const std::vector& fontFamily) { pickerProperty->UpdateFontFamily(fontFamily); } + ); +} + +void DatePickerPattern::UpdateSelectedTextStyle(const PickerTextStyle& textStyle) +{ + auto host = GetHost(); + CHECK_NULL_VOID(host); + auto context = host->GetContext(); + CHECK_NULL_VOID(context); + auto pickerTheme = context->GetTheme(host->GetThemeScopeId()); + CHECK_NULL_VOID(pickerTheme); + auto defaultTextStyle = pickerTheme->GetOptionStyle(true, false); + auto pickerProperty = GetLayoutProperty(); + CHECK_NULL_VOID(pickerProperty); + UpdateTextStyleCommon( + textStyle, + defaultTextStyle, + [&](const Color& color) { pickerProperty->UpdateSelectedColor(color); }, + [&](const Dimension& fontSize) { pickerProperty->UpdateSelectedFontSize(fontSize); }, + [&](const std::vector& fontFamily) { pickerProperty->UpdateSelectedFontFamily(fontFamily); } + ); +} } // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/picker/datepicker_pattern.h b/frameworks/core/components_ng/pattern/picker/datepicker_pattern.h index 872ccd5d081..61ed6b0a1a9 100644 --- a/frameworks/core/components_ng/pattern/picker/datepicker_pattern.h +++ b/frameworks/core/components_ng/pattern/picker/datepicker_pattern.h @@ -51,6 +51,14 @@ public: ~DatePickerPattern() override = default; + void OnColorModeChange(uint32_t colorMode) override + { + LinearLayoutPattern::OnColorModeChange(colorMode); + auto host = GetHost(); + CHECK_NULL_VOID(host); + host->MarkModifyDone(); + } + bool IsAtomicNode() const override { return true; @@ -784,6 +792,10 @@ public: void SetDigitalCrownSensitivity(int32_t crownSensitivity); void UpdateUserSetSelectColor(); + void UpdateDisappearTextStyle(const PickerTextStyle& textStyle); + void UpdateNormalTextStyle(const PickerTextStyle& textStyle); + void UpdateSelectedTextStyle(const PickerTextStyle& textStyle); + private: void OnModifyDone() override; void OnAttachToFrameNode() override; @@ -833,6 +845,14 @@ private: void UpdateLunarSwitch(); void UpdateDateOrder(); void UpdateDialogAgingButton(const RefPtr& buttonNode, const bool isNext); + Dimension ConvertFontScaleValue(const Dimension& fontSizeValue); + + void UpdateTextStyleCommon( + const PickerTextStyle& textStyle, + const TextStyle& defaultTextStyle, + std::function updateTextColorFunc, + std::function updateFontSizeFunc, + std::function&)> updateFontFamilyFunc); RefPtr clickEventListener_; bool enabled_ = true; diff --git a/frameworks/core/components_ng/pattern/picker/picker_model.h b/frameworks/core/components_ng/pattern/picker/picker_model.h index 85101fae129..6c6f5f0ef34 100644 --- a/frameworks/core/components_ng/pattern/picker/picker_model.h +++ b/frameworks/core/components_ng/pattern/picker/picker_model.h @@ -84,6 +84,9 @@ public: virtual void SetEnableHapticFeedback(bool isEnableHapticFeedback) {}; virtual void SetDigitalCrownSensitivity(int32_t value) = 0; virtual void UpdateUserSetSelectColor() = 0; + virtual void ParseDisappearTextStyleResObj(const NG::PickerTextStyle& textStyleOpt) {}; + virtual void ParseSelectedTextStyleResObj(const NG::PickerTextStyle& textStyleOpt) {}; + virtual void ParseNormalTextStyleResObj(const NG::PickerTextStyle& textStyleOpt) {}; private: static std::unique_ptr datePickerInstance_; static std::once_flag onceFlag_; diff --git a/frameworks/core/components_ng/pattern/picker/picker_type_define.h b/frameworks/core/components_ng/pattern/picker/picker_type_define.h index 46f4f9e5f26..29c49c51a46 100644 --- a/frameworks/core/components_ng/pattern/picker/picker_type_define.h +++ b/frameworks/core/components_ng/pattern/picker/picker_type_define.h @@ -20,6 +20,7 @@ #include "core/components/common/properties/text_style.h" #include "core/components/picker/picker_data.h" +#include "core/common/resource/resource_object.h" #include "frameworks/base/i18n/time_format.h" namespace OHOS::Ace::NG { @@ -60,7 +61,14 @@ struct PickerTextStyle { std::optional minFontSize; std::optional maxFontSize; std::optional textOverflow; + + RefPtr textColorResObj; + RefPtr fontSizeResObj; + RefPtr fontFamilyResObj; + RefPtr minFontSizeResObj; + RefPtr maxFontSizeResObj; }; + struct PickerTextProperties { PickerTextStyle disappearTextStyle_; PickerTextStyle normalTextStyle_; diff --git a/frameworks/core/components_ng/pattern/text_picker/textpicker_column_pattern.cpp b/frameworks/core/components_ng/pattern/text_picker/textpicker_column_pattern.cpp index ca32073cf5e..1df799c44ff 100644 --- a/frameworks/core/components_ng/pattern/text_picker/textpicker_column_pattern.cpp +++ b/frameworks/core/components_ng/pattern/text_picker/textpicker_column_pattern.cpp @@ -107,7 +107,9 @@ bool TextPickerColumnPattern::OnDirtyLayoutWrapperSwap( void TextPickerColumnPattern::OnModifyDone() { - auto pipeline = PipelineContext::GetCurrentContext(); + auto host = GetHost(); + CHECK_NULL_VOID(host); + auto pipeline = host->GetContext(); CHECK_NULL_VOID(pipeline); auto theme = pipeline->GetTheme(GetThemeScopeId()); CHECK_NULL_VOID(theme); @@ -118,8 +120,6 @@ void TextPickerColumnPattern::OnModifyDone() InitSelectorButtonProperties(theme); InitMouseAndPressEvent(); SetAccessibilityAction(); - auto host = GetHost(); - CHECK_NULL_VOID(host); if (optionProperties_.size() <= 0) { dividerSpacing_ = pipeline->NormalizeToPx(theme->GetDividerSpacing()); gradientHeight_ = static_cast(pipeline->NormalizeToPx(theme->GetGradientHeight())); @@ -536,7 +536,9 @@ void TextPickerColumnPattern::PlayPressAnimation(const Color& pressColor) uint32_t TextPickerColumnPattern::GetShowOptionCount() const { - auto context = PipelineContext::GetCurrentContext(); + auto host = GetHost(); + CHECK_NULL_RETURN(host, 0); + auto context = host->GetContext(); CHECK_NULL_RETURN(context, 0); auto pickerTheme = context->GetTheme(); CHECK_NULL_RETURN(pickerTheme, 0); @@ -2220,7 +2222,9 @@ void TextPickerColumnPattern::UpdateAnimationColor(const RefPtr& pi void TextPickerColumnPattern::InitTextHeightAndFontHeight(uint32_t childIndex, uint32_t midIndex, TextPickerOptionProperty &prop) { - auto pipeline = PipelineContext::GetCurrentContext(); + auto host = GetHost(); + CHECK_NULL_VOID(host); + auto pipeline = host->GetContext(); CHECK_NULL_VOID(pipeline); auto theme = pipeline->GetTheme(); diff --git a/frameworks/core/components_ng/pattern/text_picker/textpicker_model.h b/frameworks/core/components_ng/pattern/text_picker/textpicker_model.h index f9164ca2092..c7b80de3eab 100644 --- a/frameworks/core/components_ng/pattern/text_picker/textpicker_model.h +++ b/frameworks/core/components_ng/pattern/text_picker/textpicker_model.h @@ -99,6 +99,12 @@ public: virtual void SetDefaultTextStyle(const RefPtr& textTheme, const NG::PickerTextStyle& value) = 0; virtual void SetEnableHapticFeedback(bool isEnableHapticFeedback) = 0; virtual void UpdateUserSetSelectColor() = 0; + virtual void ParseGradientHeight(const RefPtr& resObj) {}; + virtual void ParseDividerResObj() {}; + virtual void ParseDisappearTextStyleResObj(const NG::PickerTextStyle& textStyleOpt) {}; + virtual void ParseSelectedTextStyleResObj(const NG::PickerTextStyle& textStyleOpt) {}; + virtual void ParseNormalTextStyleResObj(const NG::PickerTextStyle& textStyleOpt) {}; + virtual void ParseDefaultTextStyleResObj(const NG::PickerTextStyle& textStyleOpt) {}; private: static std::unique_ptr textPickerInstance_; static std::once_flag onceFlag_; diff --git a/frameworks/core/components_ng/pattern/text_picker/textpicker_model_ng.cpp b/frameworks/core/components_ng/pattern/text_picker/textpicker_model_ng.cpp index 3861509cb9d..6613f244312 100644 --- a/frameworks/core/components_ng/pattern/text_picker/textpicker_model_ng.cpp +++ b/frameworks/core/components_ng/pattern/text_picker/textpicker_model_ng.cpp @@ -32,6 +32,8 @@ #include "core/components_ng/pattern/text_picker/textpicker_layout_property.h" #include "core/components_ng/pattern/text_picker/textpicker_pattern.h" #include "core/components_v2/inspector/inspector_constants.h" +#include "core/common/resource/resource_object.h" +#include "core/common/resource/resource_parse_utils.h" namespace OHOS::Ace::NG { namespace { @@ -1503,4 +1505,205 @@ void TextPickerModelNG::UpdateUserSetSelectColor() CHECK_NULL_VOID(textPickerPattern); textPickerPattern->UpdateUserSetSelectColor(); } + +void TextPickerModelNG::ParseGradientHeight(const RefPtr& resObj) +{ + CHECK_NULL_VOID(resObj); + auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); + CHECK_NULL_VOID(frameNode); + auto textPickerPattern = frameNode->GetPattern(); + CHECK_NULL_VOID(textPickerPattern); + + auto&& updateFunc = [frameNode](const RefPtr& resObj) { + CalcDimension height; + if (!resObj || !ResourceParseUtils::ParseResDimensionFp(resObj, height)) { + return; + } + auto textPickerPattern = frameNode->GetPattern(); + CHECK_NULL_VOID(textPickerPattern); + textPickerPattern->SetGradientHeight(height); + ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, GradientHeight, height, frameNode); + }; + textPickerPattern->AddResObj("textPicker.gradientHeight", resObj, std::move(updateFunc)); +} + +void TextPickerModelNG::ParseDividerResObj() +{ + auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); + CHECK_NULL_VOID(frameNode); + auto textPickerPattern = frameNode->GetPattern(); + CHECK_NULL_VOID(textPickerPattern); + + auto&& updateFunc = [frameNode](const RefPtr& resObj) { + auto textPickerPattern = frameNode->GetPattern(); + CHECK_NULL_VOID(textPickerPattern); + ItemDivider curDivider = textPickerPattern->GetDivider(); + + CalcDimension strokeWidth = 0.0_vp; + if (curDivider.strokeWidthResObj && + ResourceParseUtils::ParseResDimensionFpNG(curDivider.strokeWidthResObj, strokeWidth)) { + curDivider.strokeWidth = strokeWidth; + } + + Color color = Color::TRANSPARENT; + if (curDivider.colorResObj && + ResourceParseUtils::ParseResColor(curDivider.colorResObj, color)) { + curDivider.color = color; + } + + CalcDimension startMargin = 0.0_vp; + if (curDivider.startMarginResObj && + ResourceParseUtils::ParseResDimensionFpNG(curDivider.startMarginResObj, startMargin)) { + curDivider.startMargin = startMargin; + } + + CalcDimension endMargin = 0.0_vp; + if (curDivider.endMarginResObj && + ResourceParseUtils::ParseResDimensionFpNG(curDivider.endMarginResObj, endMargin)) { + curDivider.endMargin = endMargin; + } + + textPickerPattern->SetDivider(curDivider); + textPickerPattern->SetCustomDividerFlag(true); + ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, Divider, curDivider, frameNode); + }; + RefPtr resObj = AceType::MakeRefPtr(); + textPickerPattern->AddResObj("textPicker.divider", resObj, std::move(updateFunc)); +} + +void TextPickerModelNG::ParseResTextStyle(const PickerTextStyle& textStyleOpt, const std::string& textStyleType, + std::function updateTextStyleFunc) +{ + if (!SystemProperties::ConfigChangePerform()) { + return; + } + + auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); + CHECK_NULL_VOID(frameNode); + + auto pickerPattern = frameNode->GetPattern(); + CHECK_NULL_VOID(pickerPattern); + + auto&& updateFunc = [textStyleOpt, frameNode, updateTextStyleFunc](const RefPtr resObj) { + PickerTextStyle textStyle; + Color color; + CalcDimension fontSize; + std::vector families; + + if (textStyleOpt.textColorResObj && + ResourceParseUtils::ParseResColor(textStyleOpt.textColorResObj, color)) { + textStyle.textColor = color; + } + + if (textStyleOpt.fontSizeResObj && + ResourceParseUtils::ParseResDimensionFp(textStyleOpt.fontSizeResObj, fontSize)) { + textStyle.fontSize = fontSize; + } + + if (textStyleOpt.fontFamilyResObj && + ResourceParseUtils::ParseResFontFamilies(textStyleOpt.fontFamilyResObj, families)) { + textStyle.fontFamily = families; + } + + updateTextStyleFunc(textStyle); + }; + RefPtr resObj = AceType::MakeRefPtr(); + pickerPattern->AddResObj(textStyleType, resObj, std::move(updateFunc)); +} + +void TextPickerModelNG::ParseDisappearTextStyleResObj(const PickerTextStyle& textStyleOpt) +{ + auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); + CHECK_NULL_VOID(frameNode); + + auto pickerPattern = frameNode->GetPattern(); + CHECK_NULL_VOID(pickerPattern); + + ParseResTextStyle( + textStyleOpt, + "TextPickerDisappearTextStyle", + [pickerPattern](const PickerTextStyle& textStyle) { pickerPattern->UpdateDisappearTextStyle(textStyle); } + ); +} + +void TextPickerModelNG::ParseSelectedTextStyleResObj(const PickerTextStyle& textStyleOpt) +{ + auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); + CHECK_NULL_VOID(frameNode); + + auto pickerPattern = frameNode->GetPattern(); + CHECK_NULL_VOID(pickerPattern); + + ParseResTextStyle( + textStyleOpt, + "TextPickerSelectedTextStyle", + [pickerPattern](const PickerTextStyle& textStyle) { pickerPattern->UpdateSelectedTextStyle(textStyle); } + ); +} + +void TextPickerModelNG::ParseNormalTextStyleResObj(const PickerTextStyle& textStyleOpt) +{ + auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); + CHECK_NULL_VOID(frameNode); + + auto pickerPattern = frameNode->GetPattern(); + CHECK_NULL_VOID(pickerPattern); + + ParseResTextStyle( + textStyleOpt, + "TextPickerNormalTextStyle", + [pickerPattern](const PickerTextStyle& textStyle) { pickerPattern->UpdateNormalTextStyle(textStyle); } + ); +} + +void TextPickerModelNG::ParseDefaultTextStyleResObj(const PickerTextStyle& textStyleOpt) +{ + if (!SystemProperties::ConfigChangePerform()) { + return; + } + + auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); + CHECK_NULL_VOID(frameNode); + + auto pickerPattern = frameNode->GetPattern(); + CHECK_NULL_VOID(pickerPattern); + + auto&& updateFunc = [this, textStyleOpt, frameNode](const RefPtr resObj) { + PickerTextStyle textStyle; + auto pickerPattern = frameNode->GetPattern(); + CHECK_NULL_VOID(pickerPattern); + Color color; + if (textStyleOpt.textColorResObj && + ResourceParseUtils::ParseResColor(textStyleOpt.textColorResObj, color)) { + textStyle.textColor = color; + } + + CalcDimension fontSize; + if (textStyleOpt.fontSizeResObj && + ResourceParseUtils::ParseResDimensionFp(textStyleOpt.fontSizeResObj, fontSize)) { + textStyle.fontSize = fontSize; + } + + std::vector families; + if (textStyleOpt.fontFamilyResObj && + ResourceParseUtils::ParseResFontFamilies(textStyleOpt.fontFamilyResObj, families)) { + textStyle.fontFamily = families; + } + + CalcDimension minFontSize; + if (textStyleOpt.minFontSizeResObj && + ResourceParseUtils::ParseResDimensionFp(textStyleOpt.minFontSizeResObj, minFontSize)) { + textStyle.minFontSize = minFontSize; + } + + CalcDimension maxFontSize; + if (textStyleOpt.maxFontSizeResObj && + ResourceParseUtils::ParseResDimensionFp(textStyleOpt.maxFontSizeResObj, maxFontSize)) { + textStyle.maxFontSize = maxFontSize; + } + pickerPattern->UpdateDefaultTextStyle(textStyle); + }; + RefPtr resObj = AceType::MakeRefPtr(); + pickerPattern->AddResObj("TextPickerDefaultTextStyle", resObj, std::move(updateFunc)); +} } // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/text_picker/textpicker_model_ng.h b/frameworks/core/components_ng/pattern/text_picker/textpicker_model_ng.h index 10f91ded3f0..3309b958852 100644 --- a/frameworks/core/components_ng/pattern/text_picker/textpicker_model_ng.h +++ b/frameworks/core/components_ng/pattern/text_picker/textpicker_model_ng.h @@ -23,6 +23,7 @@ #include "core/components_ng/pattern/text_picker/textpicker_event_hub.h" #include "core/components_ng/pattern/text_picker/textpicker_model.h" #include "core/components_ng/pattern/text_picker/textpicker_properties.h" +#include "core/common/resource/resource_object.h" namespace OHOS::Ace::NG { class ACE_FORCE_EXPORT TextPickerModelNG : public TextPickerModel { public: @@ -95,6 +96,12 @@ public: void SetDefaultTextStyle(const RefPtr& textTheme, const NG::PickerTextStyle& value) override; void SetEnableHapticFeedback(bool isEnableHapticFeedback) override; void UpdateUserSetSelectColor() override; + void ParseGradientHeight(const RefPtr& resObj) override; + void ParseDividerResObj() override; + void ParseDisappearTextStyleResObj(const PickerTextStyle& textStyleOpt) override; + void ParseSelectedTextStyleResObj(const PickerTextStyle& textStyleOpt) override; + void ParseNormalTextStyleResObj(const PickerTextStyle& textStyleOpt) override; + void ParseDefaultTextStyleResObj(const PickerTextStyle& textStyleOpt) override; static void SetCanLoop(FrameNode* frameNode, const bool value); static void SetDigitalCrownSensitivity(FrameNode* frameNode, int32_t crownSensitivity); @@ -159,6 +166,8 @@ private: static RefPtr CreateColumnNode(uint32_t columnKind, uint32_t showCount); static void SetUnCascadeColumnsNode(FrameNode* frameNode, const std::vector& options); static void SetCascadeColumnsNode(FrameNode* frameNode, const std::vector& options); + void ParseResTextStyle(const PickerTextStyle& textStyleOpt, const std::string& textStyleType, + std::function updateTextStyleFunc); uint32_t maxCount_ = 0; std::vector kinds_; diff --git a/frameworks/core/components_ng/pattern/text_picker/textpicker_paint_method.cpp b/frameworks/core/components_ng/pattern/text_picker/textpicker_paint_method.cpp index 0d08cc9fd89..11aba1b73a2 100644 --- a/frameworks/core/components_ng/pattern/text_picker/textpicker_paint_method.cpp +++ b/frameworks/core/components_ng/pattern/text_picker/textpicker_paint_method.cpp @@ -56,6 +56,7 @@ CanvasDrawFunction TextPickerPaintMethod::GetContentDrawFunction(PaintWrapper* p CanvasDrawFunction TextPickerPaintMethod::GetForegroundDrawFunction(PaintWrapper* paintWrapper) { auto pipeline = PipelineContext::GetCurrentContext(); + CHECK_NULL_RETURN(pipeline, nullptr); auto theme = pipeline->GetTheme(); CHECK_NULL_RETURN(theme, nullptr); CHECK_EQUAL_RETURN(theme->IsCircleDial(), true, nullptr); diff --git a/frameworks/core/components_ng/pattern/text_picker/textpicker_pattern.cpp b/frameworks/core/components_ng/pattern/text_picker/textpicker_pattern.cpp index 56b72f1c175..232e5e9e1a6 100644 --- a/frameworks/core/components_ng/pattern/text_picker/textpicker_pattern.cpp +++ b/frameworks/core/components_ng/pattern/text_picker/textpicker_pattern.cpp @@ -16,6 +16,7 @@ #include "core/components_ng/pattern/text_picker/textpicker_pattern.h" #include +#include #include #include "base/i18n/localization.h" @@ -48,6 +49,7 @@ const Dimension LINE_WIDTH = 1.5_vp; constexpr float DISABLE_ALPHA = 0.6f; constexpr float MAX_PERCENT = 100.0f; const int32_t UNOPTION_COUNT = 2; +constexpr float PICKER_MAXFONTSCALE = 1.0f; } // namespace void TextPickerPattern::OnAttachToFrameNode() @@ -1611,16 +1613,19 @@ void TextPickerPattern::OnColorConfigurationUpdate() CHECK_NULL_VOID(context); auto pickerTheme = context->GetTheme(host->GetThemeScopeId()); CHECK_NULL_VOID(pickerTheme); - auto disappearStyle = pickerTheme->GetDisappearOptionStyle(); - auto normalStyle = pickerTheme->GetOptionStyle(false, false); - auto selectedStyle = pickerTheme->GetOptionStyle(true, false); - auto pickerProperty = host->GetLayoutProperty(); - CHECK_NULL_VOID(pickerProperty); - pickerProperty->UpdateColor(GetTextProperties().normalTextStyle_.textColor.value_or(normalStyle.GetTextColor())); - pickerProperty->UpdateDisappearColor( - GetTextProperties().disappearTextStyle_.textColor.value_or(disappearStyle.GetTextColor())); - pickerProperty->UpdateSelectedColor( - GetTextProperties().selectedTextStyle_.textColor.value_or(selectedStyle.GetTextColor())); + if (!SystemProperties::ConfigChangePerform()) { + auto disappearStyle = pickerTheme->GetDisappearOptionStyle(); + auto normalStyle = pickerTheme->GetOptionStyle(false, false); + auto selectedStyle = pickerTheme->GetOptionStyle(true, false); + auto pickerProperty = host->GetLayoutProperty(); + CHECK_NULL_VOID(pickerProperty); + pickerProperty->UpdateColor( + GetTextProperties().normalTextStyle_.textColor.value_or(normalStyle.GetTextColor())); + pickerProperty->UpdateDisappearColor( + GetTextProperties().disappearTextStyle_.textColor.value_or(disappearStyle.GetTextColor())); + pickerProperty->UpdateSelectedColor( + GetTextProperties().selectedTextStyle_.textColor.value_or(selectedStyle.GetTextColor())); + } if (isPicker_) { return; } @@ -1856,4 +1861,160 @@ std::string TextPickerPattern::GetTextPickerRange() const } return result; } + +Dimension TextPickerPattern::ConvertFontScaleValue(const Dimension& fontSizeValue) +{ + auto host = GetHost(); + CHECK_NULL_RETURN(host, fontSizeValue); + auto pipeline = host->GetContext(); + CHECK_NULL_RETURN(pipeline, fontSizeValue); + + auto maxAppFontScale = pipeline->GetMaxAppFontScale(); + auto follow = pipeline->IsFollowSystem(); + float fontScale = pipeline->GetFontScale(); + if (NearZero(fontScale) || (fontSizeValue.Unit() == DimensionUnit::VP)) { + return fontSizeValue; + } + if (GreatOrEqualCustomPrecision(fontScale, PICKER_MAXFONTSCALE) && follow) { + fontScale = std::clamp(fontScale, 0.0f, maxAppFontScale); + if (!NearZero(fontScale)) { + return Dimension(fontSizeValue / fontScale); + } + } + return fontSizeValue; +} + +void TextPickerPattern::UpdateTextStyleCommon( + const PickerTextStyle& textStyle, + const TextStyle& defaultTextStyle, + std::function updateTextColorFunc, + std::function updateFontSizeFunc, + std::function&)> updateFontFamilyFunc +) +{ + auto host = GetHost(); + CHECK_NULL_VOID(host); + auto pickerProperty = GetLayoutProperty(); + CHECK_NULL_VOID(pickerProperty); + + auto pipelineContext = host->GetContext(); + CHECK_NULL_VOID(pipelineContext); + + if (pipelineContext->IsSystmColorChange()) { + updateTextColorFunc(textStyle.textColor.value_or(defaultTextStyle.GetTextColor())); + + Dimension fontSize = defaultTextStyle.GetFontSize(); + if (textStyle.fontSize.has_value() && textStyle.fontSize->IsValid()) { + fontSize = textStyle.fontSize.value(); + } + updateFontSizeFunc(ConvertFontScaleValue(fontSize)); + + updateFontFamilyFunc(textStyle.fontFamily.value_or(defaultTextStyle.GetFontFamilies())); + } + + if (host->GetRerenderable()) { + host->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF); + } +} + +void TextPickerPattern::UpdateDisappearTextStyle(const PickerTextStyle& textStyle) +{ + auto host = GetHost(); + CHECK_NULL_VOID(host); + auto context = host->GetContext(); + CHECK_NULL_VOID(context); + auto pickerTheme = context->GetTheme(host->GetThemeScopeId()); + CHECK_NULL_VOID(pickerTheme); + auto defaultTextStyle = pickerTheme->GetDisappearOptionStyle(); + auto pickerProperty = GetLayoutProperty(); + CHECK_NULL_VOID(pickerProperty); + UpdateTextStyleCommon( + textStyle, + defaultTextStyle, + [&](const Color& color) { pickerProperty->UpdateDisappearColor(color); }, + [&](const Dimension& fontSize) { pickerProperty->UpdateDisappearFontSize(fontSize); }, + [&](const std::vector& fontFamily) { pickerProperty->UpdateDisappearFontFamily(fontFamily); } + ); +} + +void TextPickerPattern::UpdateNormalTextStyle(const PickerTextStyle& textStyle) +{ + auto host = GetHost(); + CHECK_NULL_VOID(host); + auto context = host->GetContext(); + CHECK_NULL_VOID(context); + auto pickerTheme = context->GetTheme(host->GetThemeScopeId()); + CHECK_NULL_VOID(pickerTheme); + auto defaultTextStyle = pickerTheme->GetOptionStyle(false, false); + auto pickerProperty = GetLayoutProperty(); + CHECK_NULL_VOID(pickerProperty); + UpdateTextStyleCommon( + textStyle, + defaultTextStyle, + [&](const Color& color) { pickerProperty->UpdateColor(color); }, + [&](const Dimension& fontSize) { pickerProperty->UpdateFontSize(fontSize); }, + [&](const std::vector& fontFamily) { pickerProperty->UpdateFontFamily(fontFamily); } + ); +} + +void TextPickerPattern::UpdateSelectedTextStyle(const PickerTextStyle& textStyle) +{ + auto host = GetHost(); + CHECK_NULL_VOID(host); + auto context = host->GetContext(); + CHECK_NULL_VOID(context); + auto pickerTheme = context->GetTheme(host->GetThemeScopeId()); + CHECK_NULL_VOID(pickerTheme); + auto defaultTextStyle = pickerTheme->GetOptionStyle(true, false); + auto pickerProperty = GetLayoutProperty(); + CHECK_NULL_VOID(pickerProperty); + UpdateTextStyleCommon( + textStyle, + defaultTextStyle, + [&](const Color& color) { pickerProperty->UpdateSelectedColor(color); }, + [&](const Dimension& fontSize) { pickerProperty->UpdateSelectedFontSize(fontSize); }, + [&](const std::vector& fontFamily) { pickerProperty->UpdateSelectedFontFamily(fontFamily); } + ); +} + +void TextPickerPattern::UpdateDefaultTextStyle(const PickerTextStyle& textStyle) +{ + auto host = GetHost(); + CHECK_NULL_VOID(host); + auto pipelineContext = host->GetContext(); + CHECK_NULL_VOID(pipelineContext); + auto textTheme = pipelineContext->GetTheme(host->GetThemeScopeId()); + CHECK_NULL_VOID(textTheme); + auto defaultTextStyle = textTheme->GetTextStyle(); + auto pickerProperty = GetLayoutProperty(); + CHECK_NULL_VOID(pickerProperty); + + UpdateTextStyleCommon( + textStyle, + defaultTextStyle, + [&](const Color& color) { pickerProperty->UpdateDefaultColor(color); }, + [&](const Dimension& fontSize) { pickerProperty->UpdateDefaultFontSize(fontSize); }, + [&](const std::vector& fontFamily) { pickerProperty->UpdateDefaultFontFamily(fontFamily); } + ); + + if (pipelineContext->IsSystmColorChange()) { + if (textStyle.minFontSize.has_value() && textStyle.minFontSize->IsValid()) { + Dimension minFontSize = textStyle.minFontSize.value(); + pickerProperty->UpdateDefaultMinFontSize(ConvertFontScaleValue(minFontSize)); + } else { + pickerProperty->UpdateDefaultMinFontSize(Dimension()); + } + + if (textStyle.maxFontSize.has_value() && textStyle.maxFontSize->IsValid()) { + Dimension maxFontSize = textStyle.maxFontSize.value(); + pickerProperty->UpdateDefaultMaxFontSize(ConvertFontScaleValue(maxFontSize)); + } else { + pickerProperty->UpdateDefaultMaxFontSize(Dimension()); + } + } + + if (host->GetRerenderable()) { + host->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF); + } +} } // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/text_picker/textpicker_pattern.h b/frameworks/core/components_ng/pattern/text_picker/textpicker_pattern.h index ee83ba9db69..0e49990f47b 100644 --- a/frameworks/core/components_ng/pattern/text_picker/textpicker_pattern.h +++ b/frameworks/core/components_ng/pattern/text_picker/textpicker_pattern.h @@ -53,6 +53,14 @@ public: return true; } + void OnColorModeChange(uint32_t colorMode) override + { + LinearLayoutPattern::OnColorModeChange(colorMode); + auto host = GetHost(); + CHECK_NULL_VOID(host); + host->MarkModifyDone(); + } + RefPtr CreateEventHub() override { return MakeRefPtr(); @@ -527,6 +535,11 @@ public: isSingleRange_ = isSingleRange; } + void UpdateDisappearTextStyle(const PickerTextStyle& textStyle); + void UpdateNormalTextStyle(const PickerTextStyle& textStyle); + void UpdateSelectedTextStyle(const PickerTextStyle& textStyle); + void UpdateDefaultTextStyle(const PickerTextStyle& textStyle); + private: void OnModifyDone() override; void InitCrownAndKeyEvent(); @@ -590,6 +603,14 @@ private: float CalculateColumnSize(int32_t index, float childCount, const SizeF& pickerContentSize); int32_t CalculateIndex(RefPtr& frameNode); void UpdateDialogAgingButton(const RefPtr& buttonNode, const bool isNext); + Dimension ConvertFontScaleValue(const Dimension& fontSizeValue); + + void UpdateTextStyleCommon( + const PickerTextStyle& textStyle, + const TextStyle& defaultTextStyle, + std::function updateTextColorFunc, + std::function updateFontSizeFunc, + std::function&)> updateFontFamilyFunc); bool enabled_ = true; int32_t focusKeyID_ = 0; diff --git a/frameworks/core/components_ng/pattern/text_picker/textpicker_properties.h b/frameworks/core/components_ng/pattern/text_picker/textpicker_properties.h index 654cb946ca8..c2cb36c4aa9 100644 --- a/frameworks/core/components_ng/pattern/text_picker/textpicker_properties.h +++ b/frameworks/core/components_ng/pattern/text_picker/textpicker_properties.h @@ -21,6 +21,7 @@ #include "base/geometry/dimension.h" #include "base/utils/macros.h" #include "core/components/common/properties/color.h" +#include "core/common/resource/resource_object.h" namespace OHOS::Ace::NG { struct ItemDivider final { @@ -29,6 +30,12 @@ struct ItemDivider final { Dimension endMargin = 0.0_vp; Color color = Color::TRANSPARENT; bool isRtl = false; + + RefPtr strokeWidthResObj; + RefPtr startMarginResObj; + RefPtr endMarginResObj; + RefPtr colorResObj; + bool operator==(const ItemDivider& itemDivider) const { return (strokeWidth == itemDivider.strokeWidth) && (startMargin == itemDivider.startMargin) && diff --git a/frameworks/core/components_ng/pattern/time_picker/timepicker_model.h b/frameworks/core/components_ng/pattern/time_picker/timepicker_model.h index 5d9886812ce..e8681bd84f0 100644 --- a/frameworks/core/components_ng/pattern/time_picker/timepicker_model.h +++ b/frameworks/core/components_ng/pattern/time_picker/timepicker_model.h @@ -61,6 +61,9 @@ public: virtual void SetDigitalCrownSensitivity(int32_t value) = 0; virtual void UpdateUserSetSelectColor() = 0; + virtual void ParseDisappearTextStyleResObj(const NG::PickerTextStyle& textStyleOpt) {}; + virtual void ParseSelectedTextStyleResObj(const NG::PickerTextStyle& textStyleOpt) {}; + virtual void ParseNormalTextStyleResObj(const NG::PickerTextStyle& textStyleOpt) {}; private: static std::unique_ptr timePickerInstance_; static std::once_flag onceFlag_; diff --git a/frameworks/core/components_ng/pattern/time_picker/timepicker_model_ng.cpp b/frameworks/core/components_ng/pattern/time_picker/timepicker_model_ng.cpp index 0986f80df90..9159eb25720 100644 --- a/frameworks/core/components_ng/pattern/time_picker/timepicker_model_ng.cpp +++ b/frameworks/core/components_ng/pattern/time_picker/timepicker_model_ng.cpp @@ -28,6 +28,8 @@ #include "core/components_ng/pattern/time_picker/timepicker_layout_property.h" #include "core/components_ng/pattern/time_picker/timepicker_row_pattern.h" #include "core/components_v2/inspector/inspector_constants.h" +#include "core/common/resource/resource_object.h" +#include "core/common/resource/resource_parse_utils.h" namespace OHOS::Ace::NG { namespace { @@ -913,4 +915,88 @@ void TimePickerModelNG::UpdateUserSetSelectColor() timePickerPattern->UpdateUserSetSelectColor(); } +void TimePickerModelNG::ParseResTextStyle(const PickerTextStyle& textStyleOpt, const std::string& textStyleType, + std::function updateTextStyleFunc) +{ + if (!SystemProperties::ConfigChangePerform()) { + return; + } + + auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); + CHECK_NULL_VOID(frameNode); + + auto pickerPattern = frameNode->GetPattern(); + CHECK_NULL_VOID(pickerPattern); + + auto&& updateFunc = [textStyleOpt, frameNode, updateTextStyleFunc](const RefPtr resObj) { + PickerTextStyle textStyle; + Color color; + CalcDimension fontSize; + std::vector families; + + if (textStyleOpt.textColorResObj && + ResourceParseUtils::ParseResColor(textStyleOpt.textColorResObj, color)) { + textStyle.textColor = color; + } + + if (textStyleOpt.fontSizeResObj && + ResourceParseUtils::ParseResDimensionFp(textStyleOpt.fontSizeResObj, fontSize)) { + textStyle.fontSize = fontSize; + } + + if (textStyleOpt.fontFamilyResObj && + ResourceParseUtils::ParseResFontFamilies(textStyleOpt.fontFamilyResObj, families)) { + textStyle.fontFamily = families; + } + + updateTextStyleFunc(textStyle); + }; + RefPtr resObj = AceType::MakeRefPtr(); + pickerPattern->AddResObj(textStyleType, resObj, std::move(updateFunc)); +} + +void TimePickerModelNG::ParseDisappearTextStyleResObj(const PickerTextStyle& textStyleOpt) +{ + auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); + CHECK_NULL_VOID(frameNode); + + auto pickerPattern = frameNode->GetPattern(); + CHECK_NULL_VOID(pickerPattern); + + ParseResTextStyle( + textStyleOpt, + "TimePickerDisappearTextStyle", + [pickerPattern](const PickerTextStyle& textStyle) { pickerPattern->UpdateDisappearTextStyle(textStyle); } + ); +} + +void TimePickerModelNG::ParseSelectedTextStyleResObj(const PickerTextStyle& textStyleOpt) +{ + auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); + CHECK_NULL_VOID(frameNode); + + auto pickerPattern = frameNode->GetPattern(); + CHECK_NULL_VOID(pickerPattern); + + ParseResTextStyle( + textStyleOpt, + "TimePickerSelectedTextStyle", + [pickerPattern](const PickerTextStyle& textStyle) { pickerPattern->UpdateSelectedTextStyle(textStyle); } + ); +} + +void TimePickerModelNG::ParseNormalTextStyleResObj(const PickerTextStyle& textStyleOpt) +{ + auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); + CHECK_NULL_VOID(frameNode); + + auto pickerPattern = frameNode->GetPattern(); + CHECK_NULL_VOID(pickerPattern); + + ParseResTextStyle( + textStyleOpt, + "TimePickerNormalTextStyle", + [pickerPattern](const PickerTextStyle& textStyle) { pickerPattern->UpdateNormalTextStyle(textStyle); } + ); +} } // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/time_picker/timepicker_model_ng.h b/frameworks/core/components_ng/pattern/time_picker/timepicker_model_ng.h index 81b695a4a09..f7923597163 100644 --- a/frameworks/core/components_ng/pattern/time_picker/timepicker_model_ng.h +++ b/frameworks/core/components_ng/pattern/time_picker/timepicker_model_ng.h @@ -47,6 +47,9 @@ public: void SetChangeEvent(TimeChangeEvent&& onChange) override; void HasUserDefinedOpacity() override; void UpdateUserSetSelectColor() override; + void ParseDisappearTextStyleResObj(const PickerTextStyle& textStyleOpt) override; + void ParseSelectedTextStyleResObj(const PickerTextStyle& textStyleOpt) override; + void ParseNormalTextStyleResObj(const PickerTextStyle& textStyleOpt) override; static void SetOnChange(FrameNode* frameNode, TimeChangeEvent&& onChange); static RefPtr CreateFrameNode(int32_t nodeId); @@ -85,6 +88,8 @@ private: static RefPtr CreateStackNode(); static RefPtr CreateColumnNode(); static RefPtr CreateButtonNode(); + void ParseResTextStyle(const PickerTextStyle& textStyleOpt, const std::string& textStyleType, + std::function updateTextStyleFunc); }; class ACE_EXPORT TimePickerDialogModelNG : public TimePickerDialogModel { diff --git a/frameworks/core/components_ng/pattern/time_picker/timepicker_row_pattern.cpp b/frameworks/core/components_ng/pattern/time_picker/timepicker_row_pattern.cpp index 17903aba0d9..0ec0e8567fc 100644 --- a/frameworks/core/components_ng/pattern/time_picker/timepicker_row_pattern.cpp +++ b/frameworks/core/components_ng/pattern/time_picker/timepicker_row_pattern.cpp @@ -61,6 +61,7 @@ const uint32_t INDEX_SECOND_STRAT = 0; const uint32_t INDEX_SECOND_ADD_ZERO = 10; const uint32_t INDEX_SECOND_END = 59; const uint32_t SIZE_OF_AMPM_COLUMN_OPTION = 2; +constexpr float PICKER_MAXFONTSCALE = 1.0f; } // namespace void TimePickerRowPattern::OnAttachToFrameNode() @@ -306,6 +307,8 @@ void TimePickerRowPattern::UpdateTitleNodeContent() auto textLayoutProperty = textTitleNode->GetLayoutProperty(); CHECK_NULL_VOID(textLayoutProperty); textLayoutProperty->UpdateContent(str.ToString(false)); + textTitleNode->MarkModifyDone(); + textTitleNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE); } } @@ -2176,13 +2179,16 @@ void TimePickerRowPattern::OnColorConfigurationUpdate() CHECK_NULL_VOID(pickerTheme); auto dialogTheme = context->GetTheme(); CHECK_NULL_VOID(dialogTheme); - auto disappearStyle = pickerTheme->GetDisappearOptionStyle(); - auto normalStyle = pickerTheme->GetOptionStyle(false, false); - auto pickerProperty = host->GetLayoutProperty(); - CHECK_NULL_VOID(pickerProperty); - pickerProperty->UpdateColor(GetTextProperties().normalTextStyle_.textColor.value_or(normalStyle.GetTextColor())); - pickerProperty->UpdateDisappearColor( - GetTextProperties().disappearTextStyle_.textColor.value_or(disappearStyle.GetTextColor())); + if (!SystemProperties::ConfigChangePerform()) { + auto disappearStyle = pickerTheme->GetDisappearOptionStyle(); + auto normalStyle = pickerTheme->GetOptionStyle(false, false); + auto pickerProperty = host->GetLayoutProperty(); + CHECK_NULL_VOID(pickerProperty); + pickerProperty->UpdateColor( + GetTextProperties().normalTextStyle_.textColor.value_or(normalStyle.GetTextColor())); + pickerProperty->UpdateDisappearColor( + GetTextProperties().disappearTextStyle_.textColor.value_or(disappearStyle.GetTextColor())); + } if (isPicker_) { return; } @@ -2259,4 +2265,119 @@ void TimePickerRowPattern::UpdateUserSetSelectColor() } } +Dimension TimePickerRowPattern::ConvertFontScaleValue(const Dimension& fontSizeValue) +{ + auto host = GetHost(); + CHECK_NULL_RETURN(host, fontSizeValue); + auto pipeline = host->GetContext(); + CHECK_NULL_RETURN(pipeline, fontSizeValue); + + auto maxAppFontScale = pipeline->GetMaxAppFontScale(); + auto follow = pipeline->IsFollowSystem(); + float fontScale = pipeline->GetFontScale(); + if (NearZero(fontScale) || (fontSizeValue.Unit() == DimensionUnit::VP)) { + return fontSizeValue; + } + if (GreatOrEqualCustomPrecision(fontScale, PICKER_MAXFONTSCALE) && follow) { + fontScale = std::clamp(fontScale, 0.0f, maxAppFontScale); + if (!NearZero(fontScale)) { + return Dimension(fontSizeValue / fontScale); + } + } + return fontSizeValue; +} + +void TimePickerRowPattern::UpdateTextStyleCommon( + const PickerTextStyle& textStyle, + const TextStyle& defaultTextStyle, + std::function updateTextColorFunc, + std::function updateFontSizeFunc, + std::function&)> updateFontFamilyFunc +) +{ + auto host = GetHost(); + CHECK_NULL_VOID(host); + auto pickerProperty = GetLayoutProperty(); + CHECK_NULL_VOID(pickerProperty); + + auto pipelineContext = host->GetContext(); + CHECK_NULL_VOID(pipelineContext); + + if (pipelineContext->IsSystmColorChange()) { + updateTextColorFunc(textStyle.textColor.value_or(defaultTextStyle.GetTextColor())); + + Dimension fontSize = defaultTextStyle.GetFontSize(); + if (textStyle.fontSize.has_value() && textStyle.fontSize->IsValid()) { + fontSize = textStyle.fontSize.value(); + } + updateFontSizeFunc(ConvertFontScaleValue(fontSize)); + + updateFontFamilyFunc(textStyle.fontFamily.value_or(defaultTextStyle.GetFontFamilies())); + } + + if (host->GetRerenderable()) { + host->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF); + } +} + +void TimePickerRowPattern::UpdateDisappearTextStyle(const PickerTextStyle& textStyle) +{ + auto host = GetHost(); + CHECK_NULL_VOID(host); + auto context = host->GetContext(); + CHECK_NULL_VOID(context); + auto pickerTheme = context->GetTheme(host->GetThemeScopeId()); + CHECK_NULL_VOID(pickerTheme); + auto defaultTextStyle = pickerTheme->GetDisappearOptionStyle(); + auto pickerProperty = GetLayoutProperty(); + CHECK_NULL_VOID(pickerProperty); + UpdateTextStyleCommon( + textStyle, + defaultTextStyle, + [&](const Color& color) { pickerProperty->UpdateDisappearColor(color); }, + [&](const Dimension& fontSize) { pickerProperty->UpdateDisappearFontSize(fontSize); }, + [&](const std::vector& fontFamily) { pickerProperty->UpdateDisappearFontFamily(fontFamily); } + ); +} + +void TimePickerRowPattern::UpdateNormalTextStyle(const PickerTextStyle& textStyle) +{ + auto host = GetHost(); + CHECK_NULL_VOID(host); + auto context = host->GetContext(); + CHECK_NULL_VOID(context); + auto pickerTheme = context->GetTheme(host->GetThemeScopeId()); + CHECK_NULL_VOID(pickerTheme); + auto defaultTextStyle = pickerTheme->GetOptionStyle(false, false); + auto pickerProperty = GetLayoutProperty(); + CHECK_NULL_VOID(pickerProperty); + UpdateTextStyleCommon( + textStyle, + defaultTextStyle, + [&](const Color& color) { pickerProperty->UpdateColor(color); }, + [&](const Dimension& fontSize) { pickerProperty->UpdateFontSize(fontSize); }, + [&](const std::vector& fontFamily) { pickerProperty->UpdateFontFamily(fontFamily); } + ); +} + +void TimePickerRowPattern::UpdateSelectedTextStyle(const PickerTextStyle& textStyle) +{ + auto host = GetHost(); + CHECK_NULL_VOID(host); + auto context = host->GetContext(); + CHECK_NULL_VOID(context); + auto pickerTheme = context->GetTheme(host->GetThemeScopeId()); + CHECK_NULL_VOID(pickerTheme); + auto defaultTextStyle = pickerTheme->GetOptionStyle(true, false); + auto pickerProperty = GetLayoutProperty(); + CHECK_NULL_VOID(pickerProperty); + UpdateTextStyleCommon( + textStyle, + defaultTextStyle, + [&](const Color& color) { pickerProperty->UpdateSelectedColor(color); }, + [&](const Dimension& fontSize) { pickerProperty->UpdateSelectedFontSize(fontSize); }, + [&](const std::vector& fontFamily) { pickerProperty->UpdateSelectedFontFamily(fontFamily); } + ); +} + } // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/time_picker/timepicker_row_pattern.h b/frameworks/core/components_ng/pattern/time_picker/timepicker_row_pattern.h index 2a9e22b6fe0..fc5fcc3b84d 100644 --- a/frameworks/core/components_ng/pattern/time_picker/timepicker_row_pattern.h +++ b/frameworks/core/components_ng/pattern/time_picker/timepicker_row_pattern.h @@ -55,6 +55,14 @@ public: return true; } + void OnColorModeChange(uint32_t colorMode) override + { + LinearLayoutPattern::OnColorModeChange(colorMode); + auto host = GetHost(); + CHECK_NULL_VOID(host); + host->MarkModifyDone(); + } + RefPtr CreateEventHub() override { return MakeRefPtr(); @@ -663,6 +671,10 @@ public: void SetDigitalCrownSensitivity(int32_t crownSensitivity); bool IsStartEndTimeDefined(); void UpdateUserSetSelectColor(); + void UpdateDisappearTextStyle(const PickerTextStyle& textStyle); + void UpdateNormalTextStyle(const PickerTextStyle& textStyle); + void UpdateSelectedTextStyle(const PickerTextStyle& textStyle); + private: void SetDefaultColoumnFocus(std::unordered_map>::iterator& it, const std::string &id, bool& focus, const std::function& call); @@ -731,6 +743,14 @@ private: void InitFocusEvent(); void SetCallBack(); void UpdateDialogAgingButton(const RefPtr& buttonNode, const bool isNext); + Dimension ConvertFontScaleValue(const Dimension& fontSizeValue); + + void UpdateTextStyleCommon( + const PickerTextStyle& textStyle, + const TextStyle& defaultTextStyle, + std::function updateTextColorFunc, + std::function updateFontSizeFunc, + std::function&)> updateFontFamilyFunc); RefPtr clickEventListener_; bool enabled_ = true; diff --git a/test/unittest/core/pattern/picker/BUILD.gn b/test/unittest/core/pattern/picker/BUILD.gn index c96929ab8be..e7a4eba2451 100644 --- a/test/unittest/core/pattern/picker/BUILD.gn +++ b/test/unittest/core/pattern/picker/BUILD.gn @@ -27,5 +27,6 @@ ace_unittest("date_picker_test_ng") { "date_picker_test_two.cpp", "date_picker_test_update.cpp", "date_picker_column_layout_algorithm_test_ng.cpp", + "date_picker_resource_test.cpp", ] } diff --git a/test/unittest/core/pattern/picker/date_picker_resource_test.cpp b/test/unittest/core/pattern/picker/date_picker_resource_test.cpp new file mode 100644 index 00000000000..352152ed93e --- /dev/null +++ b/test/unittest/core/pattern/picker/date_picker_resource_test.cpp @@ -0,0 +1,160 @@ +/* + * 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. + */ + +#include "gtest/gtest.h" +#define private public +#define protected public +#include "test/mock/core/common/mock_container.h" +#include "test/mock/core/common/mock_theme_default.h" +#include "test/mock/core/common/mock_theme_manager.h" +#include "test/mock/core/pipeline/mock_pipeline_context.h" + +#include "core/components/theme/icon_theme.h" +#include "core/components/picker/picker_theme.h" +#include "core/components/button/button_theme.h" +#include "core/components/dialog/dialog_theme.h" +#include "core/components_ng/pattern/picker/datepicker_model_ng.h" +#include "core/components_ng/pattern/picker/datepicker_pattern.h" + +#undef private +#undef protected + +using namespace testing; +using namespace testing::ext; + +namespace OHOS::Ace::NG { +namespace { +constexpr double TEST_FONT_SIZE = 10.0; +} + +class DatePickerResourceTest : public testing::Test { +public: + static void SetUpTestSuite(); + static void TearDownTestSuite(); + void SetUp() override; + void TearDown() override; + RefPtr GetThemeByType(ThemeType type); + + RefPtr iconThem_; + RefPtr dialogTheme_; + RefPtr pickerThem_; + RefPtr buttonTheme_; +}; + +class TestNode : public UINode { + DECLARE_ACE_TYPE(TestNode, UINode); + +public: + static RefPtr CreateTestNode(int32_t nodeId) + { + auto spanNode = MakeRefPtr(nodeId); + return spanNode; + } + + bool IsAtomicNode() const override + { + return true; + } + + explicit TestNode(int32_t nodeId) : UINode("TestNode", nodeId) {} + ~TestNode() override = default; +}; + +void DatePickerResourceTest::SetUpTestSuite() +{ + MockPipelineContext::SetUp(); + MockContainer::SetUp(); +} + +void DatePickerResourceTest::TearDownTestSuite() +{ + MockPipelineContext::TearDown(); + MockContainer::TearDown(); +} + +void DatePickerResourceTest::SetUp() +{ + iconThem_ = AceType::MakeRefPtr(); + dialogTheme_ = AceType::MakeRefPtr(); + pickerThem_ = MockThemeDefault::GetPickerTheme(); + buttonTheme_ = AceType::MakeRefPtr(); + + auto themeManager = AceType::MakeRefPtr(); + MockPipelineContext::GetCurrent()->SetThemeManager(themeManager); + + EXPECT_CALL(*themeManager, GetTheme(_)) + .WillRepeatedly([this](ThemeType type) -> RefPtr {return GetThemeByType(type);}); + + EXPECT_CALL(*themeManager, GetTheme(_, _)) + .WillRepeatedly([this](ThemeType type, int32_t themeScopeId) -> RefPtr {return GetThemeByType(type);}); +} + +void DatePickerResourceTest::TearDown() +{ + MockPipelineContext::GetCurrent()->themeManager_ = nullptr; + ViewStackProcessor::GetInstance()->ClearStack(); +} + +RefPtr DatePickerResourceTest::GetThemeByType(ThemeType type) +{ + if (type == IconTheme::TypeId()) { + return iconThem_; + } else if (type == DialogTheme::TypeId()) { + return dialogTheme_; + } else if (type == PickerTheme::TypeId()) { + return pickerThem_; + } else if (type == ButtonTheme::TypeId()) { + return buttonTheme_; + } else { + return nullptr; + } +} + +/** + * @tc.name: UpdateDisappearTextStyle001 + * @tc.desc: Test DatePickerPattern UpdateDisappearTextStyle. + * @tc.type: FUNC + */ +HWTEST_F(DatePickerResourceTest, UpdateDisappearTextStyle001, TestSize.Level1) +{ + auto theme = MockPipelineContext::GetCurrent()->GetTheme(); + DatePickerModel::GetInstance()->CreateDatePicker(theme); + auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); + ASSERT_NE(frameNode, nullptr); + auto pipelineContext = PipelineContext::GetCurrentContext(); + ASSERT_NE(pipelineContext, nullptr); + pipelineContext->SetIsSystemColorChange(true); + + PickerTextStyle textStyle; + textStyle.textColor = Color::RED; + textStyle.fontSize = Dimension(TEST_FONT_SIZE); + DatePickerModel::GetInstance()->SetDisappearTextStyle(theme, textStyle); + + auto pickerProperty = frameNode->GetLayoutProperty(); + ASSERT_NE(pickerProperty, nullptr); + EXPECT_EQ(pickerProperty->GetDisappearColor().value(), Color::RED); + EXPECT_EQ(pickerProperty->GetDisappearFontSize().value(), Dimension(TEST_FONT_SIZE)); + + textStyle.textColor = Color::GREEN; + textStyle.fontSize = Dimension(TEST_FONT_SIZE + 1); + auto datePickerPattern = frameNode->GetPattern(); + ASSERT_NE(datePickerPattern, nullptr); + datePickerPattern->UpdateDisappearTextStyle(textStyle); + + EXPECT_EQ(pickerProperty->GetDisappearColor().value(), Color::GREEN); + EXPECT_EQ(pickerProperty->GetDisappearFontSize().value(), Dimension(TEST_FONT_SIZE + 1)); +} + +} // namespace OHOS::Ace::NG -- Gitee