Skip to content

Commit

Permalink
Use the new Skottie animation builder (#277)
Browse files Browse the repository at this point in the history
The new builder supports loading embedded images as well as caching any
images or files if they are re-used.
  • Loading branch information
mattleibow authored Apr 16, 2024
1 parent 4e03974 commit 7d14149
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion samples/SkiaSharpDemo/Demos/Lottie/LottiePage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<Grid RowDefinitions="*,Auto">

<controls:SKLottieView x:Name="lottieView"
Source="Lottie/trophy.json"
Source="Lottie/dotnetbot.json"
Duration="{Binding Duration}"
Progress="{Binding Progress}"
IsAnimationEnabled="{Binding IsBusy}"
Expand Down
1 change: 1 addition & 0 deletions samples/SkiaSharpDemo/Resources/Raw/Lottie/dotnetbot.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public override async Task<SKLottieAnimation> LoadAnimationAsync(CancellationTok
if (stream is null)
throw new FileLoadException($"Unable to load Lottie animation file \"{File}\".");

var animation = Skottie.Animation.Create(stream);
var animation = CreateAnimationBuilder().Build(stream);
if (animation is null)
throw new FileLoadException($"Unable to parse Lottie animation \"{File}\".");

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

using SkiaSharp.Resources;

namespace SkiaSharp.Extended.UI.Controls;

[TypeConverter(typeof(Converters.SKLottieImageSourceConverter))]
Expand All @@ -10,6 +11,11 @@ public abstract class SKLottieImageSource : Element

public abstract Task<SKLottieAnimation> LoadAnimationAsync(CancellationToken cancellationToken = default);

internal Skottie.AnimationBuilder CreateAnimationBuilder() =>
Skottie.Animation.CreateBuilder()
.SetResourceProvider(new CachingResourceProvider(new DataUriResourceProvider()))
.SetFontManager(SKFontManager.Default);

public static object FromUri(Uri uri) =>
new SKUriLottieImageSource { Uri = uri };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public override async Task<SKLottieAnimation> LoadAnimationAsync(CancellationTok
if (stream is null)
throw new FileLoadException($"Unable to load Lottie animation stream.");

var animation = Skottie.Animation.Create(stream);
var animation = CreateAnimationBuilder().Build(stream);
if (animation is null)
throw new FileLoadException($"Unable to parse Lottie animation.");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public override async Task<SKLottieAnimation> LoadAnimationAsync(CancellationTok
if (stream is null)
throw new FileLoadException($"Unable to load Lottie animation uri \"{Uri}\".");

var animation = Skottie.Animation.Create(stream);
var animation = CreateAnimationBuilder().Build(stream);
if (animation is null)
throw new FileLoadException($"Unable to parse Lottie animation \"{Uri}\".");

Expand Down

0 comments on commit 7d14149

Please sign in to comment.