---
title: "Show user progress with a Lottie animation"
description: "Display the progress of each user, such as a daily streak, as a Lottie animation on a flow screen."
---

> For the complete documentation index, see [llms.txt](https://adapty.io/docs/llms.txt).

> **AI agents**: to search Adapty docs faster and with fewer tokens, install the Adapty skills: `npx adapty skills install --yes`

Follow this recipe to display the user's progress as a Lottie animation — for example, a ring that fills up to indicate their daily streak. Your app renders the animation as a native Lottie view in a [custom element](flow-custom-elements).

<DocVideo id="custom-element-lottie-demo.mp4" width="300px" alt="The finished flow: the user taps See my streak, and on the next screen, the ring fills up to 4 of 7 days." />

This recipe reuses the flow setup and the native views of the [iOS recipe](custom-element-lottie-animation) and the [Android recipe](android-custom-element-lottie-animation). Each step of this recipe says what to copy from them, and what to do differently in a Unity project.

## Before you start

- Update your app to Adapty Unity SDK 4.4 or later. Earlier SDK versions show the [fallback content](flow-custom-elements#set-fallback-content) for every custom element.
- Set up your app to [fetch](unity-get-pb-paywalls) and [display](unity-present-paywalls) flows.
- Set up your app for custom elements, as in [Display custom elements with the Unity SDK](unity-flow-custom-elements). This recipe adds code to the C# and Java `CustomElements` classes from that guide.

Prepare a Lottie animation in `.json` format, or download the sample [`streak_ring.json`](https://raw.githubusercontent.com/adaptyteam/adapty-docs/refs/heads/main/Downloads/streak_ring.json). The app plays the animation from the start and stops it in proportion to the progress, such as halfway through for 50%. To show the exact progress, the animation needs:

- No progress on its first frame, and full progress on its last frame.
- A steady speed, with no easing. If the animation starts slowly and then speeds up, it shows less than half of the progress halfway through.

## 1. Add the custom element to the screen

Add the custom element to the flow screen as in step 1 of the [iOS recipe](custom-element-lottie-animation#1-add-the-custom-element-to-the-screen).

## 2. Add Lottie to your project

### iOS

External Dependency Manager adds Swift packages to the Xcode project that Unity generates, as it does for the Adapty SDK. To add Lottie to your iOS build, declare its Swift package in a file with a name that ends in `Dependencies.xml`, in an `Editor` folder:

```xml showLineNumbers title="Assets/Editor/CustomElementsDependencies.xml"
<dependencies>
  <remoteSwiftPackage url="https://github.com/airbnb/lottie-spm.git" version="4.6.1">
    <swiftPackage name="Lottie"/>
  </remoteSwiftPackage>
</dependencies>
```

### Android

To add Lottie to your Android build, create the `Assets/Plugins/Android/CustomElementsDependencies.androidlib` folder. Unity adds this folder to the Gradle build as an Android library. Put the following files in it:

- **`AndroidManifest.xml`**: One line, `<manifest xmlns:android="http://schemas.android.com/apk/res/android" />`.
- **`project.properties`**: One line, `android.library=true`.
- **`build.gradle`**:

```groovy showLineNumbers title="Assets/Plugins/Android/CustomElementsDependencies.androidlib/build.gradle"
apply plugin: 'com.android.library'

def unityLibraryAndroid = project(':unityLibrary').android

dependencies {
    // api: the Java files in Assets/Plugins/Android can use Lottie
    api 'com.airbnb.android:lottie:6.7.1'
}

android {
    namespace "com.example.app.dependencies"

    compileSdk unityLibraryAndroid.compileSdk
    buildToolsVersion = unityLibraryAndroid.buildToolsVersion

    defaultConfig {
        minSdk unityLibraryAndroid.defaultConfig.minSdk
        targetSdk unityLibraryAndroid.defaultConfig.targetSdk
    }
}
```

## 3. Add the animation file

Put the animation file in the `Assets/StreamingAssets` folder of your Unity project. Unity copies the files of this folder to the `Data/Raw` folder of the iOS app bundle, and to the `assets` folder of the Android app.

The file name without `.json` must match the ID of the custom element, such as `streak_ring.json` for `streak_ring`.

## 4. Add the native code

### iOS

In a Swift file in `Assets/Plugins/iOS`, add the streak model, the animation view, and the resolver from steps 3 and 4 of the [iOS recipe](custom-element-lottie-animation#3-create-the-animation-view). In the resolver, load the animation file from the `Data/Raw` folder:

```swift showLineNumbers title="Swift" {3}
case "lottie_animation" where id == "streak_ring":
    // the files of Assets/StreamingAssets are in the Data/Raw folder of the app bundle
    guard let animation = LottieAnimation.named(id, subdirectory: "Data/Raw") else {
        return nil // no animation file: show the fallback
    }
```

Instead of the code that sets the resolver in step 4 of the iOS recipe, add two functions that your C# code calls. `RegisterCustomElements` sets the resolver at launch, and `SetStreak` updates the streak model:

```swift showLineNumbers title="Assets/Plugins/iOS/CustomElements.swift"
import AdaptyUI

// the streak that your C# code sends
@MainActor let streakStore = StreakStore()

// Called once from C# at launch, before any flow is created.
@_cdecl("RegisterCustomElements")
public func RegisterCustomElements() {
    Task { @MainActor in
        AdaptyUI.setCustomElementsResolver(CustomElementsResolver(streakStore: streakStore))
    }
}

// Called from C# at launch and each time the streak changes.
@_cdecl("SetStreak")
public func SetStreak(_ days: Int32) {
    Task { @MainActor in
        streakStore.currentStreak = Int(days)
    }
}
```

### Android

Copy the `StreakStore` and `StreakRingView` classes from the **Java** tab of step 3 of the [Android recipe](android-custom-element-lottie-animation#3-create-the-animation-view). Copy the `CustomElementsResolver` class from the **Java** tab of [step 4](android-custom-element-lottie-animation#4-match-the-animation-to-the-custom-element) of the same recipe. Save each class in its own file in `Assets/Plugins/Android`, such as `StreakRingView.java`. Start each file with `package com.example.app;` and the imports that its class uses.

In `CustomElements.java`, pass the resolver to the SDK, and add a `setStreak` method for your C# code:

```java showLineNumbers title="Assets/Plugins/Android/CustomElements.java"
package com.example.app;

import android.content.Context;
import com.adapty.ui.AdaptyUI;

public final class CustomElements {
    // the streak that your C# code sends
    private static final StreakStore streakStore = new StreakStore();

    // Called once from C# at launch, before any flow is created.
    public static void register(Context context) {
        AdaptyUI.setCustomElementsResolver(new CustomElementsResolver(context, streakStore));
    }

    // Called from C# at launch and each time the streak changes.
    public static void setStreak(int days) {
        // C# calls from Unity's main thread, not from the Android main thread
        streakStore.currentStreak.postValue(days);
    }
}
```

## 5. Send the streak from your C# code

In the C# `CustomElements` class, add a `SendStreak` method that passes the streak to your native code. The highlighted lines show what to add to the class from the [Unity guide](unity-flow-custom-elements#pass-the-resolver-to-the-sdk):

```csharp showLineNumbers title="Assets/Scripts/CustomElements.cs" {9-10,29-40}
using UnityEngine;

public static class CustomElements
{
#if UNITY_IOS && !UNITY_EDITOR
    [System.Runtime.InteropServices.DllImport("__Internal")]
    private static extern void RegisterCustomElements();

    [System.Runtime.InteropServices.DllImport("__Internal")]
    private static extern void SetStreak(int days);
#endif

    [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
    private static void Register()
    {
#if UNITY_IOS && !UNITY_EDITOR
        RegisterCustomElements();
#elif UNITY_ANDROID && !UNITY_EDITOR
        using (var player = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
        using (var activity = player.GetStatic<AndroidJavaObject>("currentActivity"))
        using (var context = activity.Call<AndroidJavaObject>("getApplicationContext"))
        using (var resolver = new AndroidJavaClass("com.example.app.CustomElements"))
        {
            resolver.CallStatic("register", context);
        }
#endif
    }

    // call at app launch, and each time the streak changes
    public static void SendStreak(int days)
    {
#if UNITY_IOS && !UNITY_EDITOR
        SetStreak(days);
#elif UNITY_ANDROID && !UNITY_EDITOR
        using (var customElements = new AndroidJavaClass("com.example.app.CustomElements"))
        {
            customElements.CallStatic("setStreak", days);
        }
#endif
    }
}
```

Call `CustomElements.SendStreak` at app launch, and each time the streak changes.

## 6. Test on a device

Test the flow as in step 5 of the [iOS](custom-element-lottie-animation#5-test-on-a-device) and [Android](android-custom-element-lottie-animation#5-test-on-a-device) recipes. To set the streak to 0, 4, and 7 days, call `CustomElements.SendStreak`.

To test the fallback, make the resolver return no view for the `streak_ring` ID, and open the screen again. On Android, keep the animation file in the build: the resolver of this recipe doesn't verify that the file exists.

To find out why the fallback appears instead of the animation, follow the instructions in the [Test on a device](unity-flow-custom-elements#test-on-a-device) section of the Unity guide.