diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue34611.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue34611.cs new file mode 100644 index 000000000000..ffebf3646916 --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue34611.cs @@ -0,0 +1,69 @@ +namespace Maui.Controls.Sample.Issues; + +[Issue(IssueTracker.Github, 34611, "Entry and Editor BackgroundColor not reset to Null", PlatformAffected.iOS | PlatformAffected.macOS)] +public class Issue34611 : TestContentPage +{ + Entry _entry; + Editor _editor; + + protected override void Init() + { + Title = "Issue34611"; + + _entry = new Entry + { + AutomationId = "TestEntry", + Text = "Entry background should reset", + Placeholder = "Entry" + }; + + _editor = new Editor + { + AutomationId = "TestEditor", + Text = "Editor background should reset", + HeightRequest = 120, + Placeholder = "Editor" + }; + + var applyButton = new Button + { + AutomationId = "ApplyBackgroundColorButton", + Text = "Apply BackgroundColor" + }; + + applyButton.Clicked += (_, _) => + { + _entry.BackgroundColor = Colors.Red; + _editor.BackgroundColor = Colors.LightBlue; + }; + + var resetButton = new Button + { + AutomationId = "ResetToDefaultButton", + Text = "Reset to Default" + }; + + resetButton.Clicked += (_, _) => + { + _entry.BackgroundColor = null; + _editor.BackgroundColor = null; + }; + + Content = new VerticalStackLayout + { + Margin = new Thickness(20, 0, 20, 0), + Spacing = 12, + Children = + { + new Label + { + Text = "Apply custom backgrounds, then reset them to null." + }, + _entry, + _editor, + applyButton, + resetButton + } + }; + } +} diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue34611.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue34611.cs new file mode 100644 index 000000000000..dedeb2b26977 --- /dev/null +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue34611.cs @@ -0,0 +1,25 @@ +using NUnit.Framework; +using UITest.Appium; +using UITest.Core; + +namespace Microsoft.Maui.TestCases.Tests.Issues; + +public class Issue34611 : _IssuesUITest +{ + public Issue34611(TestDevice device) : base(device) + { + } + + public override string Issue => "Entry and Editor BackgroundColor not reset to Null"; + + [Test] + [Category(UITestCategories.Entry)] + public void EntryAndEditorBackgroundColorShouldResetToDefaultWhenSetToNull() + { + App.WaitForElement("ApplyBackgroundColorButton"); + App.Tap("ApplyBackgroundColorButton"); + App.WaitForElement("TestEntry"); + App.Tap("ResetToDefaultButton"); + VerifyScreenshot(); + } +} diff --git a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/EntryAndEditorBackgroundColorShouldResetToDefaultWhenSetToNull.png b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/EntryAndEditorBackgroundColorShouldResetToDefaultWhenSetToNull.png new file mode 100644 index 000000000000..3bd55f5c93bb Binary files /dev/null and b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/EntryAndEditorBackgroundColorShouldResetToDefaultWhenSetToNull.png differ diff --git a/src/Core/src/Handlers/Editor/EditorHandler.iOS.cs b/src/Core/src/Handlers/Editor/EditorHandler.iOS.cs index aaf1a2ec7eda..7ce02ec4ed6b 100644 --- a/src/Core/src/Handlers/Editor/EditorHandler.iOS.cs +++ b/src/Core/src/Handlers/Editor/EditorHandler.iOS.cs @@ -84,6 +84,28 @@ public static void MapText(IEditorHandler handler, IEditor editor) MapFormatting(handler, editor); } + public static void MapBackground(IEditorHandler handler, IEditor editor) + { + if (handler.PlatformView is not MauiTextView platformView) + return; + + if (editor.Background is ImageSourcePaint image) + { + var provider = handler.GetRequiredService(); + platformView.UpdateBackgroundImageSourceAsync(image.ImageSource, provider) + .FireAndForget(handler); + } + else if (editor.Background.IsNullOrEmpty()) + { + platformView.RemoveBackgroundLayer(); + platformView.BackgroundColor = null; + } + else + { + platformView.UpdateBackground(editor); + } + } + public static void MapTextColor(IEditorHandler handler, IEditor editor) => handler.PlatformView?.UpdateTextColor(editor); diff --git a/src/Core/src/Handlers/Entry/EntryHandler.iOS.cs b/src/Core/src/Handlers/Entry/EntryHandler.iOS.cs index 728499247c66..ec5779150915 100644 --- a/src/Core/src/Handlers/Entry/EntryHandler.iOS.cs +++ b/src/Core/src/Handlers/Entry/EntryHandler.iOS.cs @@ -48,6 +48,30 @@ public static void MapText(IEntryHandler handler, IEntry entry) MapFormatting(handler, entry); } + public static void MapBackground(IEntryHandler handler, IEntry entry) + { + if (handler.PlatformView is not MauiTextField platformView) + return; + + if (entry.Background is ImageSourcePaint image) + { + var provider = handler.GetRequiredService(); + platformView.UpdateBackgroundImageSourceAsync(image.ImageSource, provider) + .FireAndForget(handler); + return; + } + else if (entry.Background.IsNullOrEmpty()) + { + platformView.RemoveBackgroundLayer(); + platformView.BackgroundColor = null; + return; + } + else + { + platformView.UpdateBackground(entry); + } + } + public static void MapTextColor(IEntryHandler handler, IEntry entry) { handler.PlatformView?.UpdateTextColor(entry); @@ -212,8 +236,8 @@ void OnEditingChanged(object? sender, EventArgs e) VirtualView.UpdateText(platformView.Text); } - } - + } + void OnEditingEnded(object? sender, EventArgs e) { if (sender is MauiTextField platformView && VirtualView is IEntry virtualView) diff --git a/src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt b/src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt index a68fec2e18fa..7a6abe3d1cbd 100644 --- a/src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt +++ b/src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt @@ -1,3 +1,5 @@ #nullable enable override Microsoft.Maui.Handlers.StepperHandler.GetDesiredSize(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size override Microsoft.Maui.Platform.MauiView.DidUpdateFocus(UIKit.UIFocusUpdateContext! context, UIKit.UIFocusAnimationCoordinator! coordinator) -> void +static Microsoft.Maui.Handlers.EditorHandler.MapBackground(Microsoft.Maui.Handlers.IEditorHandler! handler, Microsoft.Maui.IEditor! editor) -> void +static Microsoft.Maui.Handlers.EntryHandler.MapBackground(Microsoft.Maui.Handlers.IEntryHandler! handler, Microsoft.Maui.IEntry! entry) -> void diff --git a/src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt b/src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt index a68fec2e18fa..7a6abe3d1cbd 100644 --- a/src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt +++ b/src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt @@ -1,3 +1,5 @@ #nullable enable override Microsoft.Maui.Handlers.StepperHandler.GetDesiredSize(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size override Microsoft.Maui.Platform.MauiView.DidUpdateFocus(UIKit.UIFocusUpdateContext! context, UIKit.UIFocusAnimationCoordinator! coordinator) -> void +static Microsoft.Maui.Handlers.EditorHandler.MapBackground(Microsoft.Maui.Handlers.IEditorHandler! handler, Microsoft.Maui.IEditor! editor) -> void +static Microsoft.Maui.Handlers.EntryHandler.MapBackground(Microsoft.Maui.Handlers.IEntryHandler! handler, Microsoft.Maui.IEntry! entry) -> void