Kotlin Apache-2.0

kottie

Render After Effects Animations Library - Compose Multiplatform | Inspired by Airbnb/Lottie

I

ismai117

Dernière activité 9 mars 2026
ismai117/kottie

301

étoiles

16

forks

0

issues ouvertes

Ce README est souvent en anglais.

Latest release Latest build

Kottie

Compose Multiplatform animation library that parses Adobe After Effects animations. Inspired by Airbnb/Lottie.

Platform Android Platform iOS Platform JVM Platform Js Platform Wasm

Kottie

Installation

Add the dependency in your common module's commonMain source set:

implementation("io.github.ismai117:kottie:latest_version")

iOS Setup

For iOS, add the Lottie framework via Swift Package Manager:

  1. In Xcode, select File → Add Packages...
  2. Enter https://github.com/airbnb/lottie-spm.git
  3. Go to File → Packages → Resolve Package Versions

Usage

Basic Example

// Load composition
val composition = rememberKottieComposition(
    KottieCompositionSpec.Url("https://example.com/animation.json")
)

// Animate
val animationState by animateKottieCompositionAsState(
    composition = composition,
    iterations = Kottie.IterateForever
)

// Display
KottieAnimation(
    composition = composition,
    progress = { animationState.progress },
    modifier = Modifier.size(300.dp)
)

Loading Compositions

Load animations from different sources using KottieCompositionSpec:

// From URL
val composition = rememberKottieComposition(
    KottieCompositionSpec.Url("https://example.com/animation.json")
)

// From file (using Compose Resources)
var json by remember { mutableStateOf("") }
LaunchedEffect(Unit) {
    json = Res.readBytes("files/animation.json").decodeToString()
}
val composition = rememberKottieComposition(KottieCompositionSpec.File(json))

// From JSON string
val composition = rememberKottieComposition(
    KottieCompositionSpec.JsonString("""{"v":"5.7.4",...}""")
)

Handling Loading States

KottieComposition is a sealed type with three states:

when (composition) {
    is KottieComposition.Loading -> {
        CircularProgressIndicator()
    }
    is KottieComposition.Success -> {
        KottieAnimation(
            composition = composition,
            progress = { animationState.progress }
        )
    }
    is KottieComposition.Failure -> {
        Text("Error: ${composition.error.message}")
    }
}

Controlling Playback

var isPlaying by remember { mutableStateOf(true) }

val animationState by animateKottieCompositionAsState(
    composition = composition,
    isPlaying = isPlaying
)

Button(onClick = { isPlaying = !isPlaying }) {
    Text(if (isPlaying) "Pause" else "Play")
}

Speed

val animationState by animateKottieCompositionAsState(
    composition = composition,
    speed = 1.5f
)

Iterations

// Play 3 times
val animationState by animateKottieCompositionAsState(
    composition = composition,
    iterations = 3
)

// Loop forever
val animationState by animateKottieCompositionAsState(
    composition = composition,
    iterations = Kottie.IterateForever
)

Observing Animation State

val animationState by animateKottieCompositionAsState(
    composition = composition,
    iterations = Kottie.IterateForever
)

LaunchedEffect(animationState) {
    println("Progress: ${animationState.progress}")
    println("Playing: ${animationState.isPlaying}")
    println("Completed: ${animationState.isCompleted}")
    println("Iteration: ${animationState.iteration}")
}

License

Copyright 2024 ismai117

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Contributing

Contributions are welcome! Feel free to open issues or submit pull requests.

Projets similaires

Render After Effects animations natively on Android and iOS, Web, and React Native

Javaafter-effectsairbnbandroid
Aairbnb
35,7 k étoiles5,4 k

Compose Multiplatform library for rendering Lottie animations with a custom pure Kotlin renderer

Kotlinafter-effectsanimationbodymovin
Aalexzhirkevich
690 étoiles27

Lottie wrapper for React Native.

TypeScriptafter-effectsanimationsbodymovin
Llottie-react-native
17,2 k étoiles1,8 k