Skip to content

Commit

Permalink
Fix animated gifs in Release builds
Browse files Browse the repository at this point in the history
  • Loading branch information
mattleibow committed Jun 5, 2024
1 parent 4a3bc31 commit d576c82
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Controls/tests/CustomAttributes/Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ public enum Image
{
Source,
Source_FontImageSource,
IsAnimationPlaying,
Aspect,
IsOpaque,
IsLoading,
Expand Down
1 change: 1 addition & 0 deletions src/Controls/tests/TestCases/Controls.TestCases.App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<OutputType>Exe</OutputType>
<SingleProject>true</SingleProject>
<IsPackable>false</IsPackable>
<ImplicitUsings>enable</ImplicitUsings>
<!-- Disable multi-RID builds to workaround a parallel build issue -->
<RuntimeIdentifier Condition="$(TargetFramework.Contains('-maccatalyst'))">maccatalyst-x64</RuntimeIdentifier>
<RuntimeIdentifier Condition="$(TargetFramework.Contains('-maccatalyst')) and '$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'arm64'">maccatalyst-arm64</RuntimeIdentifier>
Expand Down
15 changes: 15 additions & 0 deletions src/Controls/tests/TestCases/Elements/ImageCoreGalleryPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,20 @@ protected override void Build()
};
Add(familyContainer);
}

{
var image = new Image
{
Source = "red_is_good.gif",
WidthRequest = 100,
HeightRequest = 100,
};
var container = new StateViewContainer<Image>(Test.Image.IsAnimationPlaying, image);
container.StateChangeButton.Clicked += (s, a) =>
{
image.IsAnimationPlaying = !image.IsAnimationPlaying;
};
Add(container);
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions src/Core/src/Platform/Android/ImageViewExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Android.Graphics.Drawables;
using Android.Views;
using Android.Widget;
using Bumptech.Glide.Load.Resource.Gif;

namespace Microsoft.Maui.Platform
{
Expand All @@ -29,7 +30,20 @@ public static void UpdateIsAnimationPlaying(this ImageView imageView, IImageSour

public static void UpdateIsAnimationPlaying(this Drawable? drawable, IImageSourcePart image)
{
// IMPORTANT:
// The linker will remove the interface from the concrete type if we don't force
// the linker to be aware of both the concrete and interface types.

if (drawable is IAnimatable animatable)
Update(image, animatable);
else if (drawable is AnimationDrawable ad)
Update(image, ad);
else if (drawable is GifDrawable gif)
Update(image, gif);
else if (OperatingSystem.IsAndroidVersionAtLeast(28) && drawable is AnimatedImageDrawable aid)
Update(image, aid);

static void Update(IImageSourcePart image, IAnimatable animatable)
{
if (image.IsAnimationPlaying)
{
Expand Down

0 comments on commit d576c82

Please sign in to comment.