From ceec3054f41fc37baa415d8ad87368911ada2bbe Mon Sep 17 00:00:00 2001 From: kseniazakharova Date: Fri, 15 Nov 2024 14:17:16 +0300 Subject: [PATCH] Added support for color changing for PasswordIcon --- .../text_field/text_field_layout_algorithm.cpp | 7 +++++++ .../pattern/text_field/text_field_pattern.cpp | 7 +++++++ .../pattern/text_field/text_field_pattern.h | 1 + .../text_field/text_input_response_area.cpp | 14 ++++++++++++-- .../pattern/text_field/text_input_response_area.h | 1 + 5 files changed, 28 insertions(+), 2 deletions(-) diff --git a/frameworks/core/components_ng/pattern/text_field/text_field_layout_algorithm.cpp b/frameworks/core/components_ng/pattern/text_field/text_field_layout_algorithm.cpp index 7687f2aef08a..534decc9a4b5 100644 --- a/frameworks/core/components_ng/pattern/text_field/text_field_layout_algorithm.cpp +++ b/frameworks/core/components_ng/pattern/text_field/text_field_layout_algorithm.cpp @@ -61,6 +61,7 @@ void TextFieldLayoutAlgorithm::ConstructTextStyles( CHECK_NULL_VOID(textFieldPaintProperty); auto isInlineStyle = pattern->IsNormalInlineState(); auto isTextArea = pattern->IsTextArea(); + bool isShowPassword = pattern->IsShowPasswordIcon(); if (!pattern->GetTextValue().empty()) { UpdateTextStyle(frameNode, textFieldLayoutProperty, textFieldTheme, textStyle, pattern->IsDisabled(), @@ -74,6 +75,12 @@ void TextFieldLayoutAlgorithm::ConstructTextStyles( showPlaceHolder = true; } + if (isShowPassword) { + auto colorIcon = textFieldPaintProperty->HasTextColorFlagByUser() ? + textFieldLayoutProperty->GetTextColorValue(textFieldTheme->GetTextColor()) : textFieldTheme->GetTextColor(); + pattern->UpdatePasswordIconColor(colorIcon); + } + if (pattern->GetMaxFontSizeScale().has_value()) { textStyle.SetMaxFontScale(pattern->GetMaxFontSizeScale().value()); } diff --git a/frameworks/core/components_ng/pattern/text_field/text_field_pattern.cpp b/frameworks/core/components_ng/pattern/text_field/text_field_pattern.cpp index bb4beaac216a..798aed8a2449 100644 --- a/frameworks/core/components_ng/pattern/text_field/text_field_pattern.cpp +++ b/frameworks/core/components_ng/pattern/text_field/text_field_pattern.cpp @@ -7426,6 +7426,13 @@ void TextFieldPattern::OnObscuredChanged(bool isObscured) host->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF_AND_PARENT); } +void TextFieldPattern::UpdatePasswordIconColor(const Color& color) +{ + auto passwordArea = AceType::DynamicCast(responseArea_); + CHECK_NULL_VOID(passwordArea); + passwordArea->UpdatePasswordIconColor(color); +} + void TextFieldPattern::CreateHandles() { if (IsDragging() || !HasFocus()) { diff --git a/frameworks/core/components_ng/pattern/text_field/text_field_pattern.h b/frameworks/core/components_ng/pattern/text_field/text_field_pattern.h index 6712ad15b7fc..939e459d0e69 100644 --- a/frameworks/core/components_ng/pattern/text_field/text_field_pattern.h +++ b/frameworks/core/components_ng/pattern/text_field/text_field_pattern.h @@ -1177,6 +1177,7 @@ public: virtual RefPtr GetFocusHub() const; void UpdateCaretInfoToController(bool forceUpdate = false); void OnObscuredChanged(bool isObscured); + void UpdatePasswordIconColor(const Color& color); const RefPtr& GetResponseArea() { return responseArea_; diff --git a/frameworks/core/components_ng/pattern/text_field/text_input_response_area.cpp b/frameworks/core/components_ng/pattern/text_field/text_input_response_area.cpp index cd72a4e85d2e..39e0a037be78 100644 --- a/frameworks/core/components_ng/pattern/text_field/text_input_response_area.cpp +++ b/frameworks/core/components_ng/pattern/text_field/text_input_response_area.cpp @@ -315,6 +315,16 @@ void PasswordResponseArea::OnPasswordIconClicked() ChangeObscuredState(); } +void PasswordResponseArea::UpdatePasswordIconColor(const Color& color) +{ + showIcon_->SetFillColor(color); + hideIcon_->SetFillColor(color); + + if (!IsSymbolIcon()) { + UpdateImageSource(); + } +} + void PasswordResponseArea::ChangeObscuredState() { auto textFieldPattern = DynamicCast(hostPattern_.Upgrade()); @@ -387,7 +397,7 @@ void PasswordResponseArea::LoadImageSourceInfo() CHECK_NULL_VOID(pipeline); auto themeManager = pipeline->GetThemeManager(); CHECK_NULL_VOID(themeManager); - auto textFieldTheme = themeManager->GetTheme(); + auto textFieldTheme = themeManager->GetTheme(tmpHost->GetThemeScopeId()); CHECK_NULL_VOID(textFieldTheme); if (showIcon_->GetResourceId() == InternalResource::ResourceId::SHOW_PASSWORD_SVG) { showIcon_->SetFillColor(textFieldTheme->GetTextColor()); @@ -462,7 +472,7 @@ void PasswordResponseArea::UpdateSymbolSource() CHECK_NULL_VOID(pipeline); auto themeManager = pipeline->GetThemeManager(); CHECK_NULL_VOID(themeManager); - auto textFieldTheme = themeManager->GetTheme(); + auto textFieldTheme = themeManager->GetTheme(host->GetThemeScopeId()); CHECK_NULL_VOID(textFieldTheme); auto symbolNode = passwordNode_.Upgrade(); CHECK_NULL_VOID(symbolNode); diff --git a/frameworks/core/components_ng/pattern/text_field/text_input_response_area.h b/frameworks/core/components_ng/pattern/text_field/text_input_response_area.h index 00dcc0c3009a..f5fb5b0bf57f 100644 --- a/frameworks/core/components_ng/pattern/text_field/text_input_response_area.h +++ b/frameworks/core/components_ng/pattern/text_field/text_input_response_area.h @@ -106,6 +106,7 @@ public: const RefPtr GetFrameNode() override; + void UpdatePasswordIconColor(const Color& color); void OnPasswordIconClicked(); private: -- Gitee