What I Learned from Implementing Lottie Animations in SwiftUI

November 2, 2025 (1w ago)

Slipi OnBoarding

When I started working on Slipi, I wanted to make the sleep experience feel more alive. Instead of static icons or text, I thought it’d be fun to represent different sleep states with subtle, looping animations.

That’s when I discovered Lottie, a lightweight animation framework from Airbnb that renders After Effects animations natively on iOS. I had seen it used in many apps before but never tried it myself — so this became the perfect opportunity to explore it hands-on.


🧩 Installing Lottie

The Lottie iOS library can be installed in several ways:

Since I was new to Lottie and my project was built entirely with SwiftUI, I decided to use Swift Package Manager because it felt the most beginner-friendly and integrated nicely with Xcode.

📚 Resource: Lottie iOS GitHub Repository

After installation, all you need to do is:

import Lottie

🛠️ Implementing Lottie in SwiftUI

Lottie Code

At first, I thought integrating Lottie might be complicated — especially since it was originally designed for UIKit — but it turned out to be much simpler than expected.

The LottieView provided by the library works differently depending on the file type you’re using.

For .json files:

LottieView(animation: .named("StarAnimation"))

For .lottie files:

LottieView {
  try await DotLottieFile.named("StarAnimation")
}

Once your animation is set up, you can control playback using simple modifiers:

.playing()          // Plays the animation once
.looping()          // Loops the animation continuously
.currentProgress(0.5) // Pauses halfway through

📚 Resource: Lottie iOS Discussions - Usage Guide

These modifiers made it easy to test different behaviors in Slipi — for instance, looping animations for “deep sleep” and one-time animations for “wake up.”


💡 What I Learned

There’s also a version of the implementation for UIKit, which is explained in this great tutorial from LottieFiles:

📚 Resource: How to add Lottie Animation in iOS (UIKit)

I didn’t try this approach since Slipi is fully built with SwiftUI, but it’s a helpful resource if you’re working on UIKit-based apps.


✨ Closing Thoughts

Using Lottie taught me that animations can be both expressive and functional. In Slipi, they weren’t just decorations — they visually communicated the user’s current sleep state, making the experience calmer and more engaging.

At first, I thought integrating Lottie into SwiftUI would be challenging. But after working through it, I realized it’s a powerful and surprisingly accessible tool. I’m definitely planning to use it again in future projects — especially when I want to bring more personality and motion into my apps.