diff --git a/src/Controls/samples/Controls.Sample.UITests/Issues/Issues17789.xaml b/src/Controls/samples/Controls.Sample.UITests/Issues/Issues17789.xaml new file mode 100644 index 000000000000..f91e856cfb30 --- /dev/null +++ b/src/Controls/samples/Controls.Sample.UITests/Issues/Issues17789.xaml @@ -0,0 +1,13 @@ + + + + + \ No newline at end of file diff --git a/src/Controls/samples/Controls.Sample.UITests/Issues/Issues17789.xaml.cs b/src/Controls/samples/Controls.Sample.UITests/Issues/Issues17789.xaml.cs new file mode 100644 index 000000000000..6e9d345e2650 --- /dev/null +++ b/src/Controls/samples/Controls.Sample.UITests/Issues/Issues17789.xaml.cs @@ -0,0 +1,15 @@ +using Microsoft.Maui.Controls; +using Microsoft.Maui.Controls.Xaml; + +namespace Maui.Controls.Sample.Issues +{ + [XamlCompilation(XamlCompilationOptions.Compile)] + [Issue(IssueTracker.Github, 17789, "ContentPage BackgroundImageSource not working", PlatformAffected.iOS)] + public partial class Issue17789 : ContentPage + { + public Issue17789() + { + InitializeComponent(); + } + } +} \ No newline at end of file diff --git a/src/Controls/samples/Controls.Sample.UITests/Resources/Images/oasis.jpg b/src/Controls/samples/Controls.Sample.UITests/Resources/Images/oasis.jpg new file mode 100644 index 000000000000..e0be19c886ff Binary files /dev/null and b/src/Controls/samples/Controls.Sample.UITests/Resources/Images/oasis.jpg differ diff --git a/src/Controls/tests/UITests/Tests/Issues/Issue17789.cs b/src/Controls/tests/UITests/Tests/Issues/Issue17789.cs new file mode 100644 index 000000000000..64ee7d9a158e --- /dev/null +++ b/src/Controls/tests/UITests/Tests/Issues/Issue17789.cs @@ -0,0 +1,22 @@ +using NUnit.Framework; +using UITest.Appium; +using UITest.Core; + +namespace Microsoft.Maui.AppiumTests.Issues +{ + public class Issue17789 : _IssuesUITest + { + public Issue17789(TestDevice device) : base(device) + { + } + + public override string Issue => "ContentPage BackgroundImageSource not working"; + + [Test] + public void ContentPageBackgroundImageSourceWorks() + { + App.WaitForElement("WaitForStubControl"); + VerifyScreenshot(); + } + } +} diff --git a/src/Controls/tests/UITests/snapshots/android/ContentPageBackgroundImageSourceWorks.png b/src/Controls/tests/UITests/snapshots/android/ContentPageBackgroundImageSourceWorks.png new file mode 100644 index 000000000000..db24d826488c Binary files /dev/null and b/src/Controls/tests/UITests/snapshots/android/ContentPageBackgroundImageSourceWorks.png differ diff --git a/src/Controls/tests/UITests/snapshots/ios/ContentPageBackgroundImageSourceWorks.png b/src/Controls/tests/UITests/snapshots/ios/ContentPageBackgroundImageSourceWorks.png new file mode 100644 index 000000000000..cc75a6794960 Binary files /dev/null and b/src/Controls/tests/UITests/snapshots/ios/ContentPageBackgroundImageSourceWorks.png differ diff --git a/src/Controls/tests/UITests/snapshots/windows/ContentPageBackgroundImageSourceWorks.png b/src/Controls/tests/UITests/snapshots/windows/ContentPageBackgroundImageSourceWorks.png new file mode 100644 index 000000000000..77566b899dfb Binary files /dev/null and b/src/Controls/tests/UITests/snapshots/windows/ContentPageBackgroundImageSourceWorks.png differ diff --git a/src/Core/src/Handlers/Page/PageHandler.iOS.cs b/src/Core/src/Handlers/Page/PageHandler.iOS.cs index f15e95a9ec03..cedec45953ac 100644 --- a/src/Core/src/Handlers/Page/PageHandler.iOS.cs +++ b/src/Core/src/Handlers/Page/PageHandler.iOS.cs @@ -23,20 +23,18 @@ protected override ContentView CreatePlatformView() public static void MapBackground(IPageHandler handler, IContentView page) { - if (handler is IPlatformViewHandler invh && invh.ViewController is not null) + if (handler is IPlatformViewHandler platformViewHandler && platformViewHandler.ViewController is not null) { - invh.ViewController.View?.UpdateBackground(page); + var provider = handler.GetRequiredService(); + platformViewHandler.ViewController.View?.UpdateBackground(page, provider); } } public static void MapTitle(IPageHandler handler, IContentView page) { - if (handler is IPlatformViewHandler invh && invh.ViewController is not null) + if (handler is IPlatformViewHandler platformViewHandler && platformViewHandler.ViewController is not null) { - if (page is ITitledElement titled) - { - invh.ViewController.Title = titled.Title; - } + platformViewHandler.ViewController.UpdateTitle(page); } } } diff --git a/src/Core/src/Platform/iOS/PageExtensions.cs b/src/Core/src/Platform/iOS/PageExtensions.cs new file mode 100644 index 000000000000..8703d891b3a4 --- /dev/null +++ b/src/Core/src/Platform/iOS/PageExtensions.cs @@ -0,0 +1,23 @@ +using UIKit; + +namespace Microsoft.Maui.Platform +{ + internal static class PageExtensions + { + public static void UpdateTitle(this UIViewController viewController, IContentView page) + { + if (page is not ITitledElement titled) + return; + + viewController.Title = titled.Title; + } + + public static void UpdateBackground(this UIView platformView, IContentView page, IImageSourceServiceProvider? provider) + { + if (page.Background is ImageSourcePaint image) + platformView.UpdateBackgroundImageSourceAsync(image.ImageSource, provider).FireAndForget(); + else + platformView.UpdateBackground(page); + } + } +} \ No newline at end of file