rememberLottieComposition

@Composable()
fun rememberLottieComposition(spec: LottieCompositionSpec, imageAssetsFolder: String? = null, fontAssetsFolder: String = "fonts/", fontFileExtension: String = ".ttf", cacheKey: String? = DefaultCacheKey, onRetry: suspend (failCount: Int, previousException: Throwable) -> Boolean = { _, _ -> false }): LottieCompositionResult

Takes a LottieCompositionSpec, attempts to load and parse the animation, and returns a LottieCompositionResult.

LottieCompositionResult allows you to explicitly check for loading, failures, call LottieCompositionResult.await, or invoke it like a function to get the nullable composition.

LottieCompositionResult implements State<LottieComposition?> so if you don't need the full result class, you can use this function like:

val compositionResult: LottieCompositionResult = lottieComposition(spec)
// or...
val composition: State<LottieComposition?> by lottieComposition(spec)

The loaded composition will automatically load and set images that are embedded in the json as a base64 string or will load them from assets if an imageAssetsFolder is supplied.

Parameters

spec

The LottieCompositionSpec that defines which LottieComposition should be loaded.

imageAssetsFolder

A subfolder in src/main/assets that contains the exported images that this composition uses. DO NOT rename any images from your design tool. The filenames must match the values that are in your json file.

fontAssetsFolder

The default folder Lottie will look in to find font files. Fonts will be matched based on the family name specified in the Lottie json file. Defaults to "fonts/" so if "Helvetica" was in the Json file, Lottie will auto-match fonts located at "src/main/assets/fonts/Helvetica.ttf". Missing fonts will be skipped and should be set via fontRemapping or via dynamic properties.

fontFileExtension

The default file extension for font files specified in the fontAssetsFolder or fontRemapping. Defaults to ttf.

cacheKey

Set a cache key for this composition. When set, subsequent calls to fetch this composition will return directly from the cache instead of having to reload and parse the animation. Set this to null to skip the cache. By default, this will automatically generate a cache key derived from your LottieCompositionSpec.

onRetry

An optional callback that will be called if loading the animation fails. It is passed the failed count (the number of times it has failed) and the exception from the previous attempt to load the composition. onRetry is a suspending function so you can do things like add a backoff delay or await an internet connection before retrying again. rememberLottieRetrySignal can be used to handle explicit retires.