Leveraging iOS Animations: The new Figma To Lottie Feature

Seamlessly Create and Integrate High-Quality Animations with the LottieFiles plugin.

Vincenzo Pascarella
5 min readMay 19, 2023

Overview

Lottie animations have become a popular choice for iOS developers looking to enhance their apps with eye-catching and interactive visual elements. This article will explore how you can leverage the LottieFiles Plugin and its new feature “Figma to Lottie” to create stunning animations directly in Figma.

  • Simplified Animation Integration: The LottieFiles Plugin is a game-changer for designers and developers alike, enabling a seamless workflow for creating Lottie animations directly within the Figma design environment. The days of manually exporting assets and hand-coding animations are gone.
  • Lightweight and High Performance: Lottie animations are lightweight, meaning they have a minimal impact on your app’s size and overall performance. The animations are rendered natively by the platform.
  • Customizability: One of the standout features of Lottie is its extensive customizability, allowing you to tailor animations to fit your app’s unique branding and design language.
Photo by LottieFiles on Figma Community

Figma to Lottie

With the introduction of the new “Figma to Lottie” feature, designers now have a powerful tool at their disposal to create production-ready animations within Figma and seamlessly export them as Lottie files.

Figma to Lottie allows you to apply animated presets to a single frame or string together multiple frames to create captivating animations. These are the steps needed to achieve it:

Step 1: Create the Frames

To start creating animations in Figma, you’ll need to create multiple or single (to use motion presets) frames. They act as individual scenes or keyframes in your animation sequence. You can duplicate frames to maintain consistency or create variations to show different states of your design. By organizing your frames in a logical sequence, you’ll be able to animate your design effectively.

Motion Presents of LottieFiles
Motion Presets of LottieFiles

Step 2: Utilize LottieFiles and the Figma to Lottie Feature

To use the “Figma to Lottie” feature of LottieFiles, select all the frames you want to include in your animation.

Alternatively, if you have already created a prototype flow, you can select the entire flow in the plugin window. This ensures that all the frames necessary for your animation are included.

Multiple Frames selection by Vincenzo Pascarella
Multiple Frames selection by Vincenzo Pascarella

Step 3: Export to Lottie

Once you have created your animations, it’s time to export them as Lottie files. In the LottieFiles plugin window, you’ll find an “Export to Lottie” button. Simply click on this button, and Figma will generate the Lottie file containing your animation. Then download the JSON file and add it to your XCode project.

Export to Lottie Steps by Vincenzo Pascarella
Export to Lottie Steps by Vincenzo Pascarella

Integrating Lottie Animations into Your iOS App

Lottie animations can add a touch of magic to your iOS app, captivating users with delightful visual experiences. In this section, we will guide you through the steps to seamlessly incorporate Lottie animations into your iOS app. You can find also an example project on my GitHub.

Step 1: Import the Lottie Swift Package

To begin, import the Lottie Swift package into your Xcode project. You have the option to choose between the lottie-ios repository or the lottie-spm repository, which is smaller in size (less than 500kb). By adding the Lottie Swift package to your project, you gain access to the necessary tools and libraries for working with Lottie animations.

Step 2: Create a UIViewRepresentable

Next, create a UIViewRepresentable wrapper for your Lottie animation view. This allows you to use Lottie animations within SwiftUI views. The UIViewRepresentable protocol provides methods that you can implement to define the underlying UIKit view and manage its lifecycle.

import SwiftUI
import Lottie

struct LottieView: UIViewRepresentable {

/// The Lottie animation view.
let animationView: LottieAnimationView
/// A Boolean value indicating whether the animation is currently playing.
let isAnimationPlaying: Bool
}

Step 3: Adjust LottieAnimationView Properties

Inside the makeUIView method of your UIViewRepresentable, you can customize the properties of your LottieAnimationView. This includes setting such as the loopMode, contentMode, and LayoutConstraints according to your specific requirements.

Experiment with different configurations to achieve the desired animation behavior and visual presentation.

func makeUIView(context: UIViewRepresentableContext<LottieView>) -> UIView {
let view = UIView()

animationView.contentMode = .scaleAspectFit

if isAnimationPlaying {
animationView.play()
} else {
animationView.stop()
}

animationView.loopMode = .loop

animationView.translatesAutoresizingMaskIntoConstraints = false

view.addSubview(animationView)

NSLayoutConstraint.activate([
animationView.heightAnchor.constraint(equalTo: view.heightAnchor),
animationView.widthAnchor.constraint(equalTo: view.widthAnchor),
])

return view
}

Step 4: Create a Coordinator Class

To handle interactions and events related to your LottieAnimationView, create a Coordinator class within your UIViewRepresentable. The Coordinator acts as a bridge between the SwiftUI view hierarchy and the underlying UIKit view.

Implement the necessary methods and callbacks in the Coordinator class to control the animation playback and handle any user interactions.

func makeCoordinator() -> Coordinator {
Coordinator(self)
}

/// A coordinator class that manages the `LottieView`.
class Coordinator: NSObject {
/// The parent `LottieView` instance.
var parent: LottieView

init(_ parent: LottieView) {
self.parent = parent
}
}

Step 5: Update the UIViewRepresentable

In the updateUIView method of your UIViewRepresentable, you can create an if-else statement to play or pause the animation based on a boolean value passed to the view. This enables dynamic control over the animation state, allowing you to start or stop the animation as needed within your app's logic.

func updateUIView(_ uiView: UIView, context: UIViewRepresentableContext<LottieView>) {

if isAnimationPlaying {
context.coordinator.parent.animationView.play()
} else {
context.coordinator.parent.animationView.pause()
}

}

Step 6: Integrate Lottie Animation View in Your SwiftUI View

Finally, you can integrate the Lottie animation view within your SwiftUI view by simply adding an instance of your UIViewRepresentable to your view hierarchy. Customize the appearance and behavior of the SwiftUI view, and use the boolean value to control the animation playback.

import SwiftUI

struct ContentView: View {

/// A boolean value indicating whether the animation is currently playing.
@State private var isPlaying = false

var body: some View {

VStack {

LottieView(isPlaying, filename: "NewAnimation")

Spacer()

Button {
isPlaying.toggle()
} label: {
Text(isPlaying ? "StopAnimation" : "StartAnimation")
}
.buttonStyle(.borderedProminent)
.tint(isPlaying ? .red : .blue)

}
.padding()
}
}

Conclusion

In conclusion, the Figma to Lottie feature offers a seamless and efficient workflow for creating Lottie animations directly in Figma, empowering iOS developers to leverage the power of high-quality animations in their apps. By harnessing the benefits of Lottie, such as simplified animation integration, lightweight and high performance, and extensive customizability, you can elevate your app’s user experience and deliver visually captivating interactions.

So, why wait? Dive into the world of Lottie animations in Figma today and unlock a new realm of creativity and engagement for your iOS applications.

Thanks for reading! If you want to talk or take a coffee, contact me at vincenz.pascarella@gmail.com or connect via LinkedIn.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Vincenzo Pascarella
Vincenzo Pascarella

Written by Vincenzo Pascarella

I have a BSc in Computer Engineering and a strong passion in technologies and innovations. Now I am an iOS Engineer at Comcast.

No responses yet

Write a response