Home > Net >  How to make animated vectors start on their own in Jetpack Compose?
How to make animated vectors start on their own in Jetpack Compose?

Time:07-22

The problem i have is that i can render SVGs but i can't make them automatically start, i've seen examples where with the onclick method i could start the svg but i'd need it to automatically start without any user action, is it possible?

I used this documentation but it only rembers the svg https://developer.android.com/jetpack/compose/resources#animated-vector-drawables

Note: When i render the SVG in its XML, the animation works fine without any problem.

CodePudding user response:

You could use LaunchedEffect right after the view like that:

val image = AnimatedImageVector.animatedVectorResource(R.drawable.animated_vector)
var atEnd by remember { mutableStateOf(false) }

Icon(
    painter = rememberAnimatedVectorPainter(image, atEnd),
    contentDescription = null // decorative element
)

LaunchedEffect(Unit) {
    //delay(200)
    //Custom delay could be here if needed
    atEnd = true
}
  • Related