Skip to content

Commit

Permalink
[Android] Fix gif animation initial state (#14295)
Browse files Browse the repository at this point in the history
* Fix gifs initial animation state on Android

* Device tests

* Auto-format source code

* Updated sample

* Updated device tests

* Refactor code

* Update src/Core/src/Handlers/Image/ImageHandler.Android.cs

Co-authored-by: Matthew Leibowitz <mattleibow@live.com>

* Remove unnecessary change

* Fix build errors

* Merge branch 'main' into fix-7019

* Fix merge mistake

---------

Co-authored-by: GitHub Actions Autoformatter <autoformat@example.com>
Co-authored-by: Javier Suárez <6755973+jsuarezruiz@users.noreply.github.com>
Co-authored-by: Matthew Leibowitz <mattleibow@live.com>
Co-authored-by: Gerald Versluis <gerald.versluis@microsoft.com>
  • Loading branch information
5 people authored and PureWeen committed Feb 8, 2024
1 parent c62c876 commit adb7643
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
10 changes: 10 additions & 0 deletions src/Controls/samples/Controls.Sample/Pages/Controls/ImagePage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@
</FontImageSource>
</Image.Source>
</Image>
<Label
Text="Animating a gif"
Style="{StaticResource Headline}"/>
<Switch
x:Name="IsAnimationPlayingSwitch"
IsToggled="True"/>
<Image
Source="animated_heart.gif"
WidthRequest="200"
IsAnimationPlaying="{Binding Source={x:Reference IsAnimationPlayingSwitch},Path=IsToggled}" />
<Label
Text="Stream Source"
Style="{StaticResource Headline}"/>
Expand Down
9 changes: 7 additions & 2 deletions src/Core/src/Handlers/Image/ImageHandler.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,13 @@ public static void MapIsAnimationPlaying(IImageHandler handler, IImage image) =>
public static void MapSource(IImageHandler handler, IImage image) =>
MapSourceAsync(handler, image).FireAndForget(handler);

public static Task MapSourceAsync(IImageHandler handler, IImage image) =>
handler.SourceLoader.UpdateImageSourceAsync();
public static Task MapSourceAsync(IImageHandler handler, IImage image)
{
return handler
.SourceLoader
.UpdateImageSourceAsync()
.ContinueWith((action) => handler.UpdateValue(nameof(IImage.IsAnimationPlaying)));
}

public override void PlatformArrange(Graphics.Rect frame)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ await InvokeOnMainThreadAsync(async () =>
}

[Theory(
#if __IOS__ || __ANDROID__
Skip = "Animated GIFs are not yet supported on iOS. Test failing on ANDROID"
#if __ANDROID_23__ || __IOS__
Skip = "Animated GIFs are not yet supported."
#endif
)]
[InlineData("animated_heart.gif", true)]
Expand Down

0 comments on commit adb7643

Please sign in to comment.