Lottie is a mobile library for Android and iOS that parses Adobe After Effects animations exported as json with Bodymovin and renders them natively on mobile!
This library is a port from the Java code to support the Universal Windows Platform (UWP). For the official Lottie-Windows project, go here: https://aka.ms/lottie
UWP:
MyGet: https://www.myget.org/F/azchohfi/api/v3/index.json
For the first time, designers can create and ship beautiful animations without an engineer painstakingly recreating it by hand. They say a picture is worth 1,000 words so here are 13,000:
All of these animations were created in After Effects, exported with Bodymovin, and rendered natively with no additional engineering effort.
Bodymovin is an After Effects plugin created by Hernan Torrisi that exports After effects files as json and includes a javascript web player. We've built on top of his great work to extend its usage to Android, iOS, and React Native.
Read more about it on our blog post Or get in touch on Twitter (gpeal8) or via [email protected]
The sample app includes some built in animations.
LottieUWP supports Windows Build 10586+ (November Update) and above. The simplest way to use it is with LottieAnimationView:
<Page
...
xmlns:lottieUwp="using:LottieUWP"
...
/>
<lottieUwp:LottieAnimationView
FileName="Assets/Gears.json"
RepeatCount="-1"
AutoPlay="True"
VerticalAlignment="Center"
HorizontalAlignment="Center"/>
</Page>
Or you can load it programatically in multiple ways. From a json asset in app/src/main/assets:
await animationView.SetAnimationAsync("Assets/hello-world.json");
animationView.RepeatCount = LottieDrawable.Infinite;
This method will load the file and parse the animation in the background and asynchronously start rendering once completed.
If your app is crashing at runtime and you are using Visual Studio, make sure the Build Action for each of your .json files is set to 'Content' and not the default 'None.' To change this, click on the file in the Solution Explorer and change the selection in the dropdown next to 'Build Action' under the 'Advance' header in the properties window.
Note: You may have to redo this if you update the .json depending on how you reimport it.
If you want to reuse an animation such as in each item of a list or load it from a network request JsonObject:
LottieAnimationView.Composition = await LottieComposition.Factory.FromJsonAsync(jsonObject);
LottieAnimationView.PlayAnimation();
You can then control the animation or add event handlers:
animationView.AnimatorUpdate += (object sender, ValueAnimator.ValueAnimatorUpdateEventArgs e) => { ... };
animationView.PlayAnimation();
...
if (animationView.IsAnimating)
{
// Do something.
}
...
animationView.Progress = 0.5f;
...
// Custom animation speed or duration.
ValueAnimator animator = ValueAnimator.OfFloat(0f, 1f);
animator.Duration = 500;
animator.Update += (sender, e) => animationView.Progress = e.Animation.AnimatedValue;
animator.Start();
...
animationView.CancelAnimation();
Under the hood, LottieAnimationView
uses LottieDrawable
to render its animations. If you need to, you can use the the drawable form directly:
LottieDrawable drawable = new LottieDrawable();
var composition = await LottieComposition.Factory.FromAssetFileNameAsync("Assets/hello-world.json");
drawable.SetComposition(composition);
If your animation will be frequently reused, LottieAnimationView
has an optional caching strategy built in. Use LottieAnimationView.SetAnimationAsync(string, CacheStrategy)
. CacheStrategy
can be Strong
, Weak
, or None
to have LottieAnimationView
hold a strong or weak reference to the loaded and parsed animation.
You can also use the awaitable version of LottieComposition's asynchronous methods:
var composition = await LottieComposition.Factory.FromAssetFileNameAsync(assetName);
..
var composition = await LottieComposition.Factory.FromJsonAsync(jsonObject);
...
var composition = await LottieComposition.Factory.FromInputStreamAsync(stream);
You can animate images if your animation is loaded from assets and your image file is in a
subdirectory of assets. Just set ImageAssetsFolder
on LottieAnimationView
or
LottieDrawable
with the relative folder inside of assets and make sure that the images that
bodymovin export are in that folder with their names unchanged (should be img_#).
If you use LottieDrawable
directly, you must call RecycleBitmaps
when you are done with it.
If you need to provide your own bitmaps if you downloaded them from the network or something, you can provide a delegate to do that:
animationView.ImageAssetDelegate = new ImageAssetDelegate();
...
class ImageAssetDelegate : IImageAssetDelegate
{
public BitmapSource FetchBitmap(LottieImageAsset asset)
{
return GetBitmap(asset);
}
}
Linear Interpolation
Bezier Interpolation
Hold Interpolation
Rove Across Time
Spatial Bezier
Transform Anchor Point
Transform Position
Transform Scale
Transform Rotation
Transform Opacity
Path
Opacity
Multiple Masks (additive)
Multiple Parenting
Nulls
Rectangle (All properties)
Ellipse (All properties)
Polystar (All properties)
Polygon (All properties. Integer point values only.)
Path (All properties)
Anchor Point
Position
Scale
Rotation
Opacity
Group Transforms (Anchor point, position, scale etc)
Multiple paths in one group
Stroke Color
Stroke Opacity
Stroke Width
Line Cap
Dashes
Fill Color
Fill Opacity
Trim Paths Start
Trim Paths End
Trim Paths Offset
Clone this repository and run the LottieUWP.Sample module to see a bunch of sample animations. The JSON files for them are located in LottieUWP.Sample/Assets and the orignal After Effects files are located in /After Effects Samples
Lottie is named after a German film director and the foremost pioneer of silhouette animation. Her best known films are The Adventures of Prince Achmed (1926) – the oldest surviving feature-length animated film, preceding Walt Disney's feature-length Snow White and the Seven Dwarfs (1937) by over ten years The art of Lotte Reineger
Contributors are more than welcome. Just upload a PR with a description of your changes.
Other classes may also need changes, but these are the ones that are known to have actionable TODOs.
File github issues for anything that is unexpectedly broken. If an After Effects file is not working, please attach it to your issue. Debugging without the original file is much more difficult.