diff --git a/src/Core/src/Handlers/Image/ImageHandler.Windows.cs b/src/Core/src/Handlers/Image/ImageHandler.Windows.cs index b6bea6bf9dc0..dc6d61fb073c 100644 --- a/src/Core/src/Handlers/Image/ImageHandler.Windows.cs +++ b/src/Core/src/Handlers/Image/ImageHandler.Windows.cs @@ -6,12 +6,21 @@ namespace Microsoft.Maui.Handlers { - public partial class ImageHandler : ViewHandler + public partial class ImageHandler : ViewHandler { - protected override Image CreatePlatformView() => new Image(); + protected override WImage CreatePlatformView() => new WImage(); - protected override void DisconnectHandler(Image platformView) + protected override void ConnectHandler(WImage platformView) { + platformView.ImageOpened += OnImageOpened; + + base.ConnectHandler(platformView); + } + + protected override void DisconnectHandler(WImage platformView) + { + platformView.ImageOpened -= OnImageOpened; + base.DisconnectHandler(platformView); SourceLoader.Reset(); } @@ -38,6 +47,11 @@ public static void MapSource(IImageHandler handler, IImage image) => public static Task MapSourceAsync(IImageHandler handler, IImage image) => handler.SourceLoader.UpdateImageSourceAsync(); + void OnImageOpened(object sender, RoutedEventArgs e) + { + UpdateValue(nameof(IImage.IsAnimationPlaying)); + } + partial class ImageImageSourcePartSetter { public override void SetImageSource(ImageSource? platformImage) diff --git a/src/Core/src/Platform/Windows/ImageSourcePartExtensions.cs b/src/Core/src/Platform/Windows/ImageSourcePartExtensions.cs index 4a0e9d975dff..3fce54bc6eb5 100644 --- a/src/Core/src/Platform/Windows/ImageSourcePartExtensions.cs +++ b/src/Core/src/Platform/Windows/ImageSourcePartExtensions.cs @@ -42,8 +42,6 @@ internal static class ImageSourcePartExtensions if (applied) { setImage(uiImage); - if (destinationContext is WImage imageView) - imageView.UpdateIsAnimationPlaying(image); } events?.LoadingCompleted(applied); diff --git a/src/Core/src/PublicAPI/net-windows/PublicAPI.Unshipped.txt b/src/Core/src/PublicAPI/net-windows/PublicAPI.Unshipped.txt index cf283eb95a8b..b2b04019cec7 100644 --- a/src/Core/src/PublicAPI/net-windows/PublicAPI.Unshipped.txt +++ b/src/Core/src/PublicAPI/net-windows/PublicAPI.Unshipped.txt @@ -44,6 +44,7 @@ Microsoft.Maui.Platform.MauiWebView.MauiWebView(Microsoft.Maui.Handlers.WebViewH Microsoft.Maui.SizeRequest.Equals(Microsoft.Maui.SizeRequest other) -> bool Microsoft.Maui.SoftInputExtensions override Microsoft.Maui.Handlers.ContentViewHandler.DisconnectHandler(Microsoft.Maui.Platform.ContentPanel! platformView) -> void +override Microsoft.Maui.Handlers.ImageHandler.ConnectHandler(Microsoft.UI.Xaml.Controls.Image! platformView) -> void override Microsoft.Maui.Handlers.MenuFlyoutHandler.DisconnectHandler(Microsoft.UI.Xaml.Controls.MenuFlyout! platformView) -> void override Microsoft.Maui.Layouts.FlexBasis.Equals(object? obj) -> bool override Microsoft.Maui.Layouts.FlexBasis.GetHashCode() -> int diff --git a/src/Core/tests/DeviceTests/Handlers/Image/ImageHandlerTests.cs b/src/Core/tests/DeviceTests/Handlers/Image/ImageHandlerTests.cs index cc072e77cb0a..f1ca85948d0b 100644 --- a/src/Core/tests/DeviceTests/Handlers/Image/ImageHandlerTests.cs +++ b/src/Core/tests/DeviceTests/Handlers/Image/ImageHandlerTests.cs @@ -121,9 +121,7 @@ await InvokeOnMainThreadAsync(async () => #endif )] [InlineData("animated_heart.gif", true)] -#if !WINDOWS [InlineData("animated_heart.gif", false)] -#endif public async virtual Task AnimatedSourceInitializesCorrectly(string filename, bool isAnimating) { var image = new TStub @@ -138,8 +136,10 @@ await InvokeOnMainThreadAsync(async () => await image.WaitUntilLoaded(); - await AttachAndRun(GetPlatformImageView(handler), () => + await AttachAndRun(GetPlatformImageView(handler), async () => { + await image.WaitUntilDecoded(); + Assert.Equal(isAnimating, GetNativeIsAnimationPlaying(handler)); }); }); diff --git a/src/Core/tests/DeviceTests/Stubs/ImageStub.cs b/src/Core/tests/DeviceTests/Stubs/ImageStub.cs index 62e78d887707..19d4f5b9ca7f 100644 --- a/src/Core/tests/DeviceTests/Stubs/ImageStub.cs +++ b/src/Core/tests/DeviceTests/Stubs/ImageStub.cs @@ -46,5 +46,32 @@ public static class ImageStubExtensions { public static Task WaitUntilLoaded(this IImageStub image, int timeout = 1000) => AssertEventually(() => !image.IsLoading, timeout: timeout, message: $"Image {image} did not load before timeout"); + + public static async Task WaitUntilDecoded(this IImageStub image, int timeout = 1000) + { + await WaitUntilLoaded(image, timeout); + +#if WINDOWS + if (image.Handler.PlatformView is Microsoft.UI.Xaml.Controls.Image wimage) + { + var imageOpened = false; + + wimage.ImageOpened += OnOpened; + wimage.ImageFailed += OnFailed; + + await AssertEventually(() => imageOpened, timeout: timeout, message: $"Image {image} did not decode before timeout"); + + void OnOpened(object sender, Microsoft.UI.Xaml.RoutedEventArgs e) + { + imageOpened = true; + } + + void OnFailed(object sender, Microsoft.UI.Xaml.ExceptionRoutedEventArgs e) + { + imageOpened = true; + } + } +#endif + } } } \ No newline at end of file