Lottie-Windows is a library for rendering Adobe After Effects animations natively in your application. This project adds Windows to the Lottie family of tools also targeting Android, iOS, and Web.
Lottie simplifies the design-to-code workflow for bringing engaging, interactive vector animations to your Windows applications, with significant improvements in terms of performance, quality, and engineering efficiency over traditional approaches such as gifs, manually coded animations, etc. Lottie-Windows uses the Windows.UI.Composition APIs to provide smooth 60fps animations and resolution-independent vector graphics.
Lottie-Windows consists of 3 related products:
- Lottie-Windows library for parsing and translating Bodymovin JSON files
- LottieGen command-line tool for generating C# or C++ code to be used instead of JSON
- Lottie Viewer application for previewing JSON and also generating code
This repo also contains source code for samples.
It also contains LottieRuntime, native C++/WinRT source that
builds the composition tree at runtime from a serialized animation produced by
LottieGen -Language flatbuffer. It keeps the animation as data, like the JSON path does, but
without shipping a JSON parser or the translator. See
the format for how the two relate.
There are two options to integrate Lottie animations into your WinUI 3 or UWP project.
Option #1, using dynamic loader
- Install
CommunityToolkit.WinUI.Lottienuget package for WinUI project (orCommunityToolkit.Uwp.Lottiefor UWP project).- WinUI 3 apps must target .NET 10 (
net10.0-windows10.0.18362.0or later) and Windows App SDK 1.6.241114003 or later. - .NET UWP apps (
<UseUwp>true</UseUwp>) must targetnet10.0-windows10.0.26100.0or later. Classic UWP apps (uap10.0.16299or later, .NET Native) are still supported.
- WinUI 3 apps must target .NET 10 (
- Dependencies (
Microsoft.Graphics.Win2Dfor WinUI,Win2D.uwpandMicrosoft.UI.Xamlfor UWP) flow transitively, so you don't need to add them yourself.- WinUI 3: the package copies Win2D's native
Microsoft.Graphics.Canvas.dllinto your app output. Build for a specific platform or runtime identifier (x86,x64orarm64, for example-r win-x64); anAnyCPUbuild without a runtime identifier gets no native Win2D DLL. A directMicrosoft.Graphics.Win2Dreference is optional (1.0.5.1 and 1.3.x have been tested). To supply the DLL yourself, set<CommunityToolkitWinUILottieCopyWin2DNative>false</CommunityToolkitWinUILottieCopyWin2DNative>.
- WinUI 3: the package copies Win2D's native
- In your
.xamlmarkup file add:or for UWP project:... xmlns:lottie="using:CommunityToolkit.WinUI.Lottie" ... <AnimatedVisualPlayer> <lottie:LottieVisualSource UriSource="ms-appx:///Assets/Spinner.lcomp" /> </AnimatedVisualPlayer>Use the same... xmlns:muxc="using:Microsoft.UI.Xaml.Controls" xmlns:lottie="using:CommunityToolkit.WinUI.Lottie" ... <muxc:AnimatedVisualPlayer> <lottie:LottieVisualSource UriSource="ms-appx:///Assets/Spinner.lcomp" /> </muxc:AnimatedVisualPlayer>UriSourcefor a.jsonasset. To precompile it, runLottieGen -InputFile Spinner.json -Language flatbuffer -WinUIVersion 3.0(use2.8for WinUI 2/UWP) and include the resulting.lcompas app Content. The managed player reads the compiled composition without translating JSON at runtime; no generated C# or native reader package is needed. If LottieGen produces several UAP variants, point the player at the file compatible with your target. It does not search for fallback files. Thems-appxexamples use package assets. In an unpackaged WinUI 3 app, load a local file withawait source.SetSourceAsync(storageFile)or pass an input stream.
Option #2, using codegen (recommended)
- Install codegen tool using
dotnet tool install lottiegenin powershell - Run codegen tool
lottiegen -InputFile MyAnimation.json -Language cs -WinUIVersion 3.0- For UWP projects use
-WinUIVersion 2.Xdepending on the version ofMicrosoft.UI.Xaml - Other language options:
cppwinrtandcppcx
- For UWP projects use
- Add generated source files to the project
- Generated code doesn't need the Lottie package, but it may need its dependencies. Install them directly if needed:
Microsoft.Graphics.Win2DandMicrosoft.WindowsAppSDKfor WinUI 3, orWin2D.uwpandMicrosoft.UI.Xamlfor UWP. - In your
.xamlmarkup file add:or for UWP project:... xmlns:animatedvisuals="using:AnimatedVisuals" ... <AnimatedVisualPlayer> <animatedvisuals:MyAnimation/> </AnimatedVisualPlayer>... xmlns:muxc="using:Microsoft.UI.Xaml.Controls" xmlns:animatedvisuals="using:AnimatedVisuals" ... <muxc:AnimatedVisualPlayer> <animatedvisuals:MyAnimation/> </muxc:AnimatedVisualPlayer>
- May 2019 Update (18362) and later
| Package | Branch | Status | Latest nuget version |
|---|---|---|---|
| CommunityToolkit.WinUI.Lottie | main | ||
| CommunityToolkit.Uwp.Lottie | main | ||
| LottieGen | main |
Please use GitHub Issues for bug reports and feature requests.
This project has adopted the code of conduct defined by the Contributor Covenant to clarify expected behavior in our community. For more information see the .NET Foundation Code of Conduct.
This project is supported by the .NET Foundation.
