Listening on Events

Overview

You can listen to events such as onLoad, onComplete, and onLoadError in the DotLottieAnimation composable function. It is possible to have multiple event listeners for a single DotLottieAnimation instance.

import androidx.compose.runtime.Composable
import androidx.compose.ui.tooling.preview.Preview
import com.lottiefiles.dotlottie.core.compose.ui.DotLottieAnimation
import com.lottiefiles.dotlottie.core.util.DotLottieSource
@Preview()
@Composable
fun DotLottiePreview() {
DotLottieAnimation(
source = DotLottieSource.Url("https://lottie.host/5525262b-4e57-4f0a-8103-cfdaa7c8969e/VCYIkooYX8.json"),
autoplay = true,
loop = true,
eventListeners = listOf(object: DotLottieEventListener {
override fun onLoad() {
// Handle onLoad event
}
override fun onComplete() {
// Handle onComplete event
}
override fun onLoadError() {
// Handle onLoadError event
}
// Add other event listeners here
})
)
}

Please refer to the DotLottieEventListener interface for a complete list of event listeners and their descriptions.