From 6b4a1678ec8b5fc26768ee34c79c4eab7a12be45 Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Tue, 16 Apr 2024 19:23:18 +0200 Subject: [PATCH 1/2] Update to SkiaSharp v3.0 --- .../SkiaSharp.Extended.UI.Maui.csproj | 6 +++--- source/SkiaSharp.Extended/SkiaSharp.Extended.csproj | 2 +- .../SkiaSharp.Extended.Tests.csproj | 4 ++-- .../SkiaSharp.Extended.UI.Maui.Tests.csproj | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/source/SkiaSharp.Extended.UI.Maui/SkiaSharp.Extended.UI.Maui.csproj b/source/SkiaSharp.Extended.UI.Maui/SkiaSharp.Extended.UI.Maui.csproj index f992c02..ad97141 100644 --- a/source/SkiaSharp.Extended.UI.Maui/SkiaSharp.Extended.UI.Maui.csproj +++ b/source/SkiaSharp.Extended.UI.Maui/SkiaSharp.Extended.UI.Maui.csproj @@ -29,9 +29,9 @@ - - - + + + diff --git a/source/SkiaSharp.Extended/SkiaSharp.Extended.csproj b/source/SkiaSharp.Extended/SkiaSharp.Extended.csproj index 313a21a..ea9e6f0 100644 --- a/source/SkiaSharp.Extended/SkiaSharp.Extended.csproj +++ b/source/SkiaSharp.Extended/SkiaSharp.Extended.csproj @@ -13,7 +13,7 @@ - + \ No newline at end of file diff --git a/tests/SkiaSharp.Extended.Tests/SkiaSharp.Extended.Tests.csproj b/tests/SkiaSharp.Extended.Tests/SkiaSharp.Extended.Tests.csproj index fd1af27..fe552da 100644 --- a/tests/SkiaSharp.Extended.Tests/SkiaSharp.Extended.Tests.csproj +++ b/tests/SkiaSharp.Extended.Tests/SkiaSharp.Extended.Tests.csproj @@ -5,8 +5,8 @@ - - + + diff --git a/tests/SkiaSharp.Extended.UI.Maui.Tests/SkiaSharp.Extended.UI.Maui.Tests.csproj b/tests/SkiaSharp.Extended.UI.Maui.Tests/SkiaSharp.Extended.UI.Maui.Tests.csproj index 4e53055..e5df03d 100644 --- a/tests/SkiaSharp.Extended.UI.Maui.Tests/SkiaSharp.Extended.UI.Maui.Tests.csproj +++ b/tests/SkiaSharp.Extended.UI.Maui.Tests/SkiaSharp.Extended.UI.Maui.Tests.csproj @@ -7,8 +7,8 @@ - - + + From ed1becb3ece8c68f71c8abbae8ef7d665a56a891 Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Tue, 16 Apr 2024 22:07:18 +0200 Subject: [PATCH 2/2] Use the new Skottie animation builder The new builder supports loading embedded images as well as caching any images or files if they are re-used. --- samples/SkiaSharpDemo/Demos/Lottie/LottiePage.xaml | 2 +- samples/SkiaSharpDemo/Resources/Raw/Lottie/dotnetbot.json | 1 + .../Controls/Lottie/SKFileLottieImageSource.shared.cs | 2 +- .../Controls/Lottie/SKLottieImageSource.shared.cs | 8 +++++++- .../Controls/Lottie/SKStreamLottieImageSource.shared.cs | 2 +- .../Controls/Lottie/SKUriLottieImageSource.shared.cs | 2 +- 6 files changed, 12 insertions(+), 5 deletions(-) create mode 100644 samples/SkiaSharpDemo/Resources/Raw/Lottie/dotnetbot.json diff --git a/samples/SkiaSharpDemo/Demos/Lottie/LottiePage.xaml b/samples/SkiaSharpDemo/Demos/Lottie/LottiePage.xaml index 76bc247..05905b1 100644 --- a/samples/SkiaSharpDemo/Demos/Lottie/LottiePage.xaml +++ b/samples/SkiaSharpDemo/Demos/Lottie/LottiePage.xaml @@ -8,7 +8,7 @@ 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}\"."); diff --git a/source/SkiaSharp.Extended.UI.Maui/Controls/Lottie/SKLottieImageSource.shared.cs b/source/SkiaSharp.Extended.UI.Maui/Controls/Lottie/SKLottieImageSource.shared.cs index ae8ec4d..8a62e36 100644 --- a/source/SkiaSharp.Extended.UI.Maui/Controls/Lottie/SKLottieImageSource.shared.cs +++ b/source/SkiaSharp.Extended.UI.Maui/Controls/Lottie/SKLottieImageSource.shared.cs @@ -1,4 +1,5 @@ - +using SkiaSharp.Resources; + namespace SkiaSharp.Extended.UI.Controls; [TypeConverter(typeof(Converters.SKLottieImageSourceConverter))] @@ -10,6 +11,11 @@ public abstract class SKLottieImageSource : Element public abstract Task 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 }; diff --git a/source/SkiaSharp.Extended.UI.Maui/Controls/Lottie/SKStreamLottieImageSource.shared.cs b/source/SkiaSharp.Extended.UI.Maui/Controls/Lottie/SKStreamLottieImageSource.shared.cs index e7068b9..0332b56 100644 --- a/source/SkiaSharp.Extended.UI.Maui/Controls/Lottie/SKStreamLottieImageSource.shared.cs +++ b/source/SkiaSharp.Extended.UI.Maui/Controls/Lottie/SKStreamLottieImageSource.shared.cs @@ -23,7 +23,7 @@ public override async Task 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."); diff --git a/source/SkiaSharp.Extended.UI.Maui/Controls/Lottie/SKUriLottieImageSource.shared.cs b/source/SkiaSharp.Extended.UI.Maui/Controls/Lottie/SKUriLottieImageSource.shared.cs index 7ec62be..efd84ad 100644 --- a/source/SkiaSharp.Extended.UI.Maui/Controls/Lottie/SKUriLottieImageSource.shared.cs +++ b/source/SkiaSharp.Extended.UI.Maui/Controls/Lottie/SKUriLottieImageSource.shared.cs @@ -30,7 +30,7 @@ public override async Task 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}\".");