---
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."
---

> **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." />

## Before you start

<Tabs groupId="current-os" queryString>
<TabItem value="kotlin" label="Kotlin" default>

- Update your app to Adapty Android 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](android-get-pb-paywalls) and [display](android-present-paywalls) flows.
- Set up Jetpack Compose in your app module. The animation view in this recipe is a composable.
- Add Lottie for Jetpack Compose to your app with Gradle, from `com.airbnb.android:lottie-compose`.

</TabItem>
<TabItem value="java" label="Java">

- Update your app to Adapty Android 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](android-get-pb-paywalls) and [display](android-present-paywalls) flows.
- Add Lottie to your app with Gradle, from `com.airbnb.android:lottie`.

</TabItem>
</Tabs>

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

In the Flow & Paywall Builder, [add a custom element](flow-custom-elements#add-and-configure) to a flow screen, and set it up for the animation:

- **Type**: `lottie_animation`.
- **ID**: `streak_ring`. In this recipe, the ID is also the name of the animation file.
- **Height**: Keep the default **Fixed** height. The animation scales to fit the custom element.

Inside the custom element, add an [**Image**](custom-media#image) with a still picture of the ring. Users see it as the [fallback](flow-custom-elements#set-fallback-content) when their version of your app doesn't play the animation.

## 2. Add the animation file to your app

Put the animation file in `src/main/assets`, the `assets` folder of your app module. Keep it at the root of this folder, not in a subfolder.

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

## 3. Create the animation view

Create a model for the streak, and a view that plays the animation. Your app updates the model when the streak changes. The view reads the model, so the ring shows the current streak when the screen opens:

<Tabs groupId="current-os" queryString>
<TabItem value="kotlin" label="Kotlin" default>

```kotlin showLineNumbers title="Kotlin"
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import com.airbnb.lottie.compose.LottieAnimation
import com.airbnb.lottie.compose.LottieClipSpec
import com.airbnb.lottie.compose.LottieCompositionSpec
import com.airbnb.lottie.compose.rememberLottieComposition
import kotlinx.coroutines.flow.MutableStateFlow

// the streak that your app keeps up to date
class StreakStore {
    val currentStreak = MutableStateFlow(0) // days in a row
}

@Composable
fun StreakRing(animationFile: String, streakStore: StreakStore) {
    val composition by rememberLottieComposition(LottieCompositionSpec.Asset(animationFile))
    val streak by streakStore.currentStreak.collectAsState()

    // 7 days fill the ring: from 0 for an empty ring to 1 for a full one
    val progress = minOf(streak / 7f, 1f)

    LottieAnimation(
        composition = composition,
        modifier = Modifier.fillMaxSize(), // scale the animation to fit the custom element
        clipSpec = LottieClipSpec.Progress(0f, progress),
    )
}
```

`clipSpec = LottieClipSpec.Progress(0f, progress)` fills the ring once, from empty up to `progress`. If your app already keeps the streak in a `StateFlow`, use that `StateFlow` in place of `StreakStore`.

</TabItem>
<TabItem value="java" label="Java">

```java showLineNumbers title="Java"
import android.content.Context;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.Observer;
import com.airbnb.lottie.LottieAnimationView;

// the streak that your app keeps up to date
public class StreakStore {
    public final MutableLiveData<Integer> currentStreak = new MutableLiveData<>(0); // days in a row
}

public class StreakRingView extends LottieAnimationView {
    private final StreakStore streakStore;

    private final Observer<Integer> streakObserver = streak -> {
        // 7 days fill the ring: from 0 for an empty ring to 1 for a full one
        float progress = Math.min(streak / 7f, 1f);
        setMinAndMaxProgress(0f, progress);
        playAnimation();
    };

    public StreakRingView(Context context, String animationFile, StreakStore streakStore) {
        super(context);
        this.streakStore = streakStore;
        setAnimation(animationFile);
    }

    @Override
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        streakStore.currentStreak.observeForever(streakObserver);
    }

    @Override
    protected void onDetachedFromWindow() {
        streakStore.currentStreak.removeObserver(streakObserver);
        super.onDetachedFromWindow();
    }
}
```

`setMinAndMaxProgress(0f, progress)` and `playAnimation()` fill the ring once, from empty up to `progress`. If your app already keeps the streak in a `LiveData`, use that `LiveData` in place of `StreakStore`.

</TabItem>
</Tabs>

## 4. Match the animation to the custom element

In your [app-wide resolver](android-flow-custom-elements#display-views-in-every-flow), add a property for the streak model. Then return the animation view for the `lottie_animation` Type and the `streak_ring` ID. The highlighted lines show what to add or change. If your app has no app-wide [resolver](android-flow-custom-elements#write-a-resolver-to-match-custom-elements-and-views) yet, copy the whole code:

<Tabs groupId="current-os" queryString>
<TabItem value="kotlin" label="Kotlin" default>

```kotlin showLineNumbers title="Kotlin" {8,22-28}
import android.content.Context
import com.adapty.ui.AdaptyCustomElementContent
import com.adapty.ui.AdaptyCustomElementsResolver
import java.io.IOException

class CustomElementsResolver(
    context: Context,
    private val streakStore: StreakStore,
) : AdaptyCustomElementsResolver {
    // the animation files in the assets folder, listed once
    private val animationFiles: Set<String> = try {
        context.assets.list("").orEmpty().toSet()
    } catch (e: IOException) {
        emptySet() // no list of files: every Lottie element shows the fallback
    }

    override fun resolve(type: String, id: String): AdaptyCustomElementContent? =
        when (type) {
            "lottie_animation" -> {
                // the ID names the animation file, such as streak_ring.json
                val file = "$id.json"
                when {
                    file !in animationFiles -> null // no file for this ID: show the fallback
                    id == "streak_ring" ->
                        AdaptyCustomElementContent.compose { StreakRing(file, streakStore) }
                    // the other animations of your resolver
                    else -> null
                }
            }
            // the other Types of your resolver
            else -> null
        }
}
```

If the `assets` folder has no file for the ID, the resolver returns `null`, and users see the fallback. If your resolver already returns a [view for every animation file](android-flow-custom-elements#write-a-resolver-to-match-custom-elements-and-views), return that view instead of `null` when the ID isn't `streak_ring`. This way, users still see the animations of your other `lottie_animation` custom elements.

</TabItem>
<TabItem value="java" label="Java">

```java showLineNumbers title="Java" {10,14-15,34-40}
import android.content.Context;
import com.adapty.ui.AdaptyCustomElementContent;
import com.adapty.ui.AdaptyCustomElementsResolver;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class CustomElementsResolver implements AdaptyCustomElementsResolver {
    private final StreakStore streakStore;
    // the animation files in the assets folder, listed once
    private final Set<String> animationFiles = new HashSet<>();

    public CustomElementsResolver(Context context, StreakStore streakStore) {
        this.streakStore = streakStore;
        try {
            String[] files = context.getAssets().list("");
            if (files != null) {
                animationFiles.addAll(Arrays.asList(files));
            }
        } catch (IOException e) {
            // no list of files: every Lottie element shows the fallback
        }
    }

    @Override
    public AdaptyCustomElementContent resolve(String type, String id) {
        if (type.equals("lottie_animation")) {
            // the ID names the animation file, such as streak_ring.json
            String file = id + ".json";
            if (!animationFiles.contains(file)) {
                return null; // no file for this ID: show the fallback
            }
            if (id.equals("streak_ring")) {
                return AdaptyCustomElementContent.view(
                        (context, elementContext) -> new StreakRingView(context, file, streakStore)
                );
            }
            // the other animations of your resolver
            return null;
        }
        // the other Types of your resolver
        return null;
    }
}
```

If the `assets` folder has no file for the ID, the resolver returns `null`, and users see the fallback. If your resolver already returns a [view for every animation file](android-flow-custom-elements#write-a-resolver-to-match-custom-elements-and-views), return that view instead of `null` when the ID isn't `streak_ring`. This way, users still see the animations of your other `lottie_animation` custom elements.

</TabItem>
</Tabs>

Create the resolver with the streak model, and set it as the app-wide resolver. Call `AdaptyUI.setCustomElementsResolver` once, such as at app launch:

<Tabs groupId="current-os" queryString>
<TabItem value="kotlin" label="Kotlin" default>

```kotlin showLineNumbers title="Kotlin"
import android.app.Application
import com.adapty.ui.AdaptyUI

class App : Application() {
    // the streak model that your app updates
    val streakStore = StreakStore()

    // keep this instance: a resolver for one flow can reuse it
    // lazy: the context isn't attached yet while App is constructed
    val customElementsResolver by lazy { CustomElementsResolver(this, streakStore) }

    override fun onCreate() {
        super.onCreate()
        AdaptyUI.setCustomElementsResolver(customElementsResolver)
    }
}
```

</TabItem>
<TabItem value="java" label="Java">

```java showLineNumbers title="Java"
import android.app.Application;
import com.adapty.ui.AdaptyUI;

public class App extends Application {
    // the streak model that your app updates
    private final StreakStore streakStore = new StreakStore();
    // keep this instance: a resolver for one flow can reuse it
    private CustomElementsResolver customElementsResolver;

    @Override
    public void onCreate() {
        super.onCreate();
        customElementsResolver = new CustomElementsResolver(this, streakStore);
        AdaptyUI.setCustomElementsResolver(customElementsResolver);
    }

    public StreakStore getStreakStore() {
        return streakStore;
    }

    public CustomElementsResolver getCustomElementsResolver() {
        return customElementsResolver;
    }
}
```

</TabItem>
</Tabs>

## 5. Test on a device

The Flow & Paywall Builder can't run your app code, so its canvas only shows the fallback. To preview the animation:

1. [Publish the flow](builder-save-publish). To see the latest published version instead of a cached one, register the device as a [test device](test-devices).
2. Run a build of your app that includes the resolver. Set the streak to 0 days, open the screen, and verify that the ring stays empty. Repeat with 4 and 7 days, and verify that the ring fills up to each value.

To test the fallback, remove the animation file from the build, and open the screen again.

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