Lottie 4.3.0 now available, with official support for SwiftUI #2189
Replies: 5 comments 9 replies
-
Great job! Thanks for this release 👍 |
Beta Was this translation helpful? Give feedback.
-
Great news! I had two questions which are specifically SwiftUI API-surface related One thing I'm wondering about is why not using a Also wondering if the naming of Maybe you've already considered and discussed just but just popped to my head :) |
Beta Was this translation helpful? Give feedback.
-
Hi! Does it work with watchOS now? |
Beta Was this translation helpful? Give feedback.
-
How do you reduce the animation speed with swiftUI ? |
Beta Was this translation helpful? Give feedback.
-
How can i make a lottie animation to whole screen? i tried but still there are spaces on top and bottom. @calda |
Beta Was this translation helpful? Give feedback.
-
Today we released Lottie 4.3.0. This version adds many new features, including:
CALayer
subclassSwiftUI support
Lottie 4.3.0 introduces a new
LottieView
SwiftUI component, which wraps the UIKitLottieAnimationView
but provides new, reimagined declarative APIs. Let’s take a quick tour of some of the functionality available in the newLottieView
:Loading Lottie animations
LottieView
includes a robust set of APIs for loading and displaying Lottie animations from .json files and .lottie files, both synchronously and asynchronously.You can easily load Lottie animations from json files or dotLottie files available locally:
You can also easily load animations by downloading them from a URL, optionally displaying a placeholder view until the animation finishes downloading:
Declarative playback
LottieView
provides some convenience APIs for the most common types of animation playback. The specified animation starts playing as soon as the animation finishes loading:LottieView
also provides aplaybackMode
API that takes a declarativeLottiePlaybackMode
value, which you can use to update the playback mode in response to state updates.Here’s an example that triggers a Lottie animation to play when you press a button:
All of the most common
LottieAnimationView
APIs are available onLottieView
adapted to fit the declarative model of SwiftUI. If you need to call an API onLottieAnimationView
which is not yet available onLottieView
, you can access the underlyingLottieAnimationView
via theconfigure { ... }
method:Buttons and switches
Lottie 4.3.0 also includes SwiftUI implementations of the UIKit
AnimatedSwitch
andAnimationButton
APIs, also adapted for SwiftUI. This version also adds macOS support to the entire family of animated controls, including the new SwiftUI versions.Here’s an example
LottieSwitch
that tracks whether or not it’s enabled in anisOn
property:and here’s an example
LottieButton
that tracks the number of times its been pressed in apressCount
property:Core Animation
CALayer
APILottie is built on top of Core Animation
CALayer
s, which is how we’ve been able to make it available on both iOS and macOS. Historically this was just an implementation detail, since onlyLottieAnimationView
itself (aUIView
/NSView
implementation) was public.Lottie 4.3.0 adds a new
LottieAnimationLayer
, a publicCALayer
subclass. All of the functionality inLottieAnimationView
has been moved toLottieAnimationLayer
, and now theUIView
implementation simply wraps the underlyingLottieAnimationLayer
.This functionality was added in collaboration with engineers from Meta (thanks!). This enabled them to add support for Lottie to the popular design tool Origami, which is built using Core Animation
CALayer
s rather than UIKit or AppKit:Support for reduced motion
Reduced motion is an important accessibility option on iOS. We’ve been adding support for this system flag in more places throughout the Airbnb app. We’re especially interested in ways to make this automatic, so feature developers get the correct behavior without having to implement it themselves.
There isn't a sufficiently general way for Lottie to decide how to handle reduced motion for an arbitrary animation, since the correct behavior depends on the use case. For example, we can't just always display the first frame of the animation, because that may just be entirely blank.
Instead, Lottie 4.3.0 adds support for “reduced motion” markers. If your animation has a marker named “reduced motion” (or some variation like “reducedMotion” etc), Lottie will override the
play
methods to always play that specific marker any timeUIAccessibility.isReduceMotionEnabled
is true.Here’s an example of an animation that includes a “reduced motion” marker with a start frame pointing to the last frame in the animation, and a marker duration of zero:
If the user has reduced motion enabled (meaning
UIAccessibility.isReduceMotionEnabled
returns true), Lottie automatically displays the last frame of the animation rather than animating it from the start to the end. No extra code required!We’re hoping to bring similar behavior to web and Android in the future, so it can become part of the cross-platform Lottie standard.
Support for drop shadow layer effects
Lottie now includes support for rendering and animating drop shadow layer effects. This means drop shadows are finally supported on all platforms (iOS, Android, and web), meaning designers can safely and confidently use them in Lottie animations shared across all platforms!
Support for visionOS
Lottie 4.3.0 adds support for using Lottie on visionOS! Here’s a gif of the repo’s SwiftUI example app running in the Apple Vision Pro simulator:
The
lottie-spm
repo uses prebuilt XCFramework archives, which we must compile using a production version of Xcode. Since the Apple Vision Pro hasn’t been released yet, only beta versions of Xcode include the visionOS SDK. That means that we can’t support visionOS via thelottie-spm
package quite yet. If you need visionOS support in your project, you’ll need to use thelottie-ios
repo directly for now.Full changelog
There’s tons of other new functionality and fixes included in Lottie 3.4.0. A full changelog is available here: https://github.com/airbnb/lottie-ios/releases/tag/4.3.0
Thanks to everyone who contributed to this release!
Beta Was this translation helpful? Give feedback.
All reactions