All Downloads are FREE. Search and download functionalities are using the official Maven repository.

iosMain.kottieComposition.animateKottieCompositionAsState.ios.kt Maven / Gradle / Ivy

There is a newer version: 1.9.6
Show newest version
package kottieComposition

import Lottie.CompatibleAnimationView
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.State
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import kotlinx.cinterop.ExperimentalForeignApi
import kottieAnimationState.KottieAnimationState
import lottie.animateLottieCompositionAsState.animateLottieCompositionAsState

@OptIn(ExperimentalForeignApi::class)
@Composable
actual fun animateKottieCompositionAsState(
    composition: Any?,
    speed: Float,
    iterations: Int,
    isPlaying: Boolean,
    restartOnPlay: Boolean
): State {
    val kottieAnimationState = remember { mutableStateOf(KottieAnimationState()) }
    val animationState = animateLottieCompositionAsState(
        composition = composition as? CompatibleAnimationView,
        speed = speed,
        iterations = iterations,
        isPlaying = isPlaying,
        restartOnPlay = restartOnPlay
    )
    LaunchedEffect(
        animationState.progress
    ){
        kottieAnimationState.value = kottieAnimationState.value.copy(
            composition = animationState.composition,
            isPlaying = animationState.isPlaying,
            isCompleted = animationState.isCompleted,
            progress = animationState.progress,
            duration = animationState.duration,
            iterations = animationState.iterations,
            speed = animationState.speed
        )
    }
    return kottieAnimationState
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy