diff --git a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/EntryClearButtonShouldBeVisibleOnDarkTheme.png b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/EntryClearButtonShouldBeVisibleOnDarkTheme.png new file mode 100644 index 000000000000..6d5158999702 Binary files /dev/null and b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/EntryClearButtonShouldBeVisibleOnDarkTheme.png differ diff --git a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/EntryClearButtonShouldBeVisibleOnLightTheme.png b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/EntryClearButtonShouldBeVisibleOnLightTheme.png new file mode 100644 index 000000000000..fe4be74dc09a Binary files /dev/null and b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/EntryClearButtonShouldBeVisibleOnLightTheme.png differ diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue32886.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue32886.cs new file mode 100644 index 000000000000..b9f5498ed4d3 --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue32886.cs @@ -0,0 +1,45 @@ +namespace Maui.Controls.Sample.Issues; + +[Issue(IssueTracker.Github, 32886, "[Android, iOS, Mac] Entry ClearButton not visible on dark theme", PlatformAffected.Android | PlatformAffected.iOS | PlatformAffected.macOS)] +public class Issue32886 : TestContentPage +{ + protected override void Init() + { + Title = "Issue32886"; + + // Create the UITestEntry with ClearButtonVisibility + var entry = new UITestEntry + { + Text = "Entry Text", + IsCursorVisible = false, + IsSpellCheckEnabled = false, + IsTextPredictionEnabled = false, + AutomationId = "TestEntry", + ClearButtonVisibility = ClearButtonVisibility.WhileEditing + }; + + var button = new Button + { + Text = "Change theme", + AutomationId = "ThemeButton" + }; + button.Clicked += Button_Clicked; + + var layout = new VerticalStackLayout(); + layout.Children.Add(entry); + layout.Children.Add(button); + + Content = layout; + + // Set background color based on app theme + this.SetAppThemeColor(BackgroundColorProperty, Colors.White, Colors.Black); + } + + private void Button_Clicked(object sender, EventArgs e) + { + if (Application.Current is not null) + { + Application.Current.UserAppTheme = Application.Current.UserAppTheme != AppTheme.Dark ? AppTheme.Dark : AppTheme.Light; + } + } +} \ No newline at end of file diff --git a/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/EntryClearButtonShouldBeVisibleOnDarkTheme.png b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/EntryClearButtonShouldBeVisibleOnDarkTheme.png new file mode 100644 index 000000000000..12e0dfe930eb Binary files /dev/null and b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/EntryClearButtonShouldBeVisibleOnDarkTheme.png differ diff --git a/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/EntryClearButtonShouldBeVisibleOnLightTheme.png b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/EntryClearButtonShouldBeVisibleOnLightTheme.png new file mode 100644 index 000000000000..56990c3225f6 Binary files /dev/null and b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/EntryClearButtonShouldBeVisibleOnLightTheme.png differ diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue32886.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue32886.cs new file mode 100644 index 000000000000..9cadff37384f --- /dev/null +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue32886.cs @@ -0,0 +1,55 @@ +using NUnit.Framework; +using UITest.Appium; +using UITest.Core; + +namespace Microsoft.Maui.TestCases.Tests.Issues; + +public class Issue32886 : _IssuesUITest +{ + public Issue32886(TestDevice device) : base(device) + { + } + + public override string Issue => "[Android, iOS, Mac] Entry ClearButton not visible on dark theme"; + + [Test, Order(1)] + [Category(UITestCategories.Entry)] + public void EntryClearButtonShouldBeVisibleOnLightTheme() + { + App.WaitForElement("TestEntry"); + App.Tap("TestEntry"); +#if ANDROID // On Android, to address CI flakiness, the keyboard is dismissed. + if (App.WaitForKeyboardToShow(timeout: TimeSpan.FromSeconds(1))) + { + App.DismissKeyboard(); + } +#endif + +#if IOS + // On iOS, the virtual keyboard appears inconsistent with keyboard characters casing, can cause flaky test results. As this test verifying only the entry clear button color, crop the bottom portion of the screenshot to exclude the keyboard. + // Using DismissKeyboard() would unfocus the control in iOS, so we're using cropping instead to maintain focus during testing. + VerifyScreenshot(cropBottom: 1550); +#else + VerifyScreenshot(); +#endif + } + + [Test, Order(2)] + [Category(UITestCategories.Entry)] + public void EntryClearButtonShouldBeVisibleOnDarkTheme() + { + App.WaitForElement("TestEntry"); + App.Tap("ThemeButton"); +#if WINDOWS // On Windows, the clear button isn't visible when Entry loses focus, so manually focused to check its icon color. + App.Tap("TestEntry"); +#endif + +#if IOS + // On iOS, the virtual keyboard appears inconsistent with keyboard characters casing, can cause flaky test results. As this test verifying only the entry clear button color, crop the bottom portion of the screenshot to exclude the keyboard. + // Using DismissKeyboard() would unfocus the control in iOS, so we're using cropping instead to maintain focus during testing. + VerifyScreenshot(cropBottom: 1550); +#else + VerifyScreenshot(); +#endif + } +} \ No newline at end of file diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/EntryClearButtonShouldBeVisibleOnDarkTheme.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/EntryClearButtonShouldBeVisibleOnDarkTheme.png new file mode 100644 index 000000000000..2e31c8a77b08 Binary files /dev/null and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/EntryClearButtonShouldBeVisibleOnDarkTheme.png differ diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/EntryClearButtonShouldBeVisibleOnLightTheme.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/EntryClearButtonShouldBeVisibleOnLightTheme.png new file mode 100644 index 000000000000..b971b924bc2c Binary files /dev/null and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/EntryClearButtonShouldBeVisibleOnLightTheme.png differ diff --git a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/EntryClearButtonShouldBeVisibleOnDarkTheme.png b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/EntryClearButtonShouldBeVisibleOnDarkTheme.png new file mode 100644 index 000000000000..a52d3ac13dcb Binary files /dev/null and b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/EntryClearButtonShouldBeVisibleOnDarkTheme.png differ diff --git a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/EntryClearButtonShouldBeVisibleOnLightTheme.png b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/EntryClearButtonShouldBeVisibleOnLightTheme.png new file mode 100644 index 000000000000..545e17b916f8 Binary files /dev/null and b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/EntryClearButtonShouldBeVisibleOnLightTheme.png differ diff --git a/src/Core/src/Platform/Android/EditTextExtensions.cs b/src/Core/src/Platform/Android/EditTextExtensions.cs index bbb99c029ab4..293571ac8043 100644 --- a/src/Core/src/Platform/Android/EditTextExtensions.cs +++ b/src/Core/src/Platform/Android/EditTextExtensions.cs @@ -231,7 +231,23 @@ internal static void UpdateClearButtonColor(this EditText editText, Graphics.Col } else { - clearButtonDrawable?.ClearColorFilter(); + if (OperatingSystem.IsAndroidVersionAtLeast(23) && editText.Context?.Theme is Resources.Theme theme) + { + using var ta = theme.ObtainStyledAttributes([global::Android.Resource.Attribute.TextColorPrimary]); + var cs = ta.GetColorStateList(0); + + if (cs is not null) + { + // Clear button is only visible when enabled, so just use the enabled state + int[] enabledState = [global::Android.Resource.Attribute.StateEnabled]; + var color = new global::Android.Graphics.Color(cs.GetColorForState(enabledState, Colors.Black.ToPlatform())); + clearButtonDrawable?.SetColorFilter(color, FilterMode.SrcIn); + } + } + else + { + clearButtonDrawable?.ClearColorFilter(); + } } } diff --git a/src/Core/src/Platform/iOS/TextFieldExtensions.cs b/src/Core/src/Platform/iOS/TextFieldExtensions.cs index 886b48fc5f4a..04097c37c60e 100644 --- a/src/Core/src/Platform/iOS/TextFieldExtensions.cs +++ b/src/Core/src/Platform/iOS/TextFieldExtensions.cs @@ -208,8 +208,8 @@ internal static void UpdateClearButtonColor(this UITextField textField, IEntry e if (entry.TextColor is null) { - clearButton.SetImage(defaultClearImage, UIControlState.Normal); - clearButton.SetImage(defaultClearImage, UIControlState.Highlighted); + // Setting TintColor to null allows the system to automatically apply the appropriate color based on the current theme (light or dark mode) + clearButton.TintColor = null; } else {