🕓 9 MIN Ever wondered how to …
While having animations in our apps is always a treat, implementing them without a hiccup can sometimes be challenging. Thankfully, Lottie enables us to very easily include beautiful and performant vector animations in our cross-platform apps. Even better yet, since Lottie animations are exported as JSON files, file sizes remain small and your animations can easily be resized, looped, and even interacted with without losing quality.
Let us go ahead and see how we can implement Lottie animations into our Uno Platform applications, whether you’re targeting iOS, Android, macOS, Linux, or even WebAssembly!
On all Uno Platform targets, you’ll need the following package: Uno.WinUI.Lottie (for the LottieVisualSource). You can find the package by:
right-clicking on the project > Manage NuGet Packages > Search Uno.WinUI.Lottie
Feel free to follow along in your preferred IDE or test out Lottie implementation in Uno Playground.
First thing we’ll want to do is add our XML namespace to the mainpage.
On WASM, iOS, and macOS, you can put the Lottie .json files directly in a shared project folder (for example “Lottie/animation.json”) and set their Build action as Content.
On Android, Lottie .json files must be added to the Assets folder. To match the same path as for the other platforms, the file could be stored at “Assets/Lottie/animation.json”. Set its Build action to AndroidAsset.
To reference the animations in XAML, use the ms-appx:
URI, in this case, ms-appx:///Lottie/animation.json
.
Lottie animations are basically SVGs nested in a JSON file and can use scalable graphics. Make sure your animation fits your screen, by setting a HeightRequest and a WidthRequest.
We can subscribe to AnimationFailed and AnimationLoaded events to react to potential issues (for example when loading an externally-hosted Lottie animation file).
To enable or disable the animation, we can use the IsAnimationEnabled property.
In addition, RepeatCount and RepeatMode allow us to control the repetition of the animation itself.
Check out Platform CTO Jerome Laban at .NET Conf: Focus on MAUI discussing building rich Skottie animations for cross-platform .NET applications and learn more about how Skia-based Uno Platform targets are using Skottie to support Lottie animations and the contributions made by the Uno Platform to SkiaSharp and .NET Ecosystem.
Tags:
🕓 9 MIN Ever wondered how to …
🕓 3 MIN State management patterns like …
🕓 3 MIN We are introducing over …
Uno Platform
360 rue Saint-Jacques, suite G101,
Montréal, Québec, Canada
H2Y 1P5
USA/CANADA toll free: +1-877-237-0471
International: +1-514-312-6958
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
Uno Platform 5.2 LIVE Webinar – Today at 3 PM EST – Watch