androidandroid-jetpack-composeandroid-drawableandroid-imageandroid-vectordrawable

How to use Animated vector drawable in Compose


I created my vector drawable animation and I want to use in in Compose. I found in official documentation that I need to call animatedVectorResource. But whole AnimatedImageVector has been removed from compose till next versions. How to launch animated drawable in current compose version?


Solution

  • You need to update compose to 1.1.0-alpha01 and add the module androidx.compose.animation:animation-graphics as indicated in the last changelog

    enter image description here

    implementation("androidx.compose.animation:animation-graphics:1.1.0-alpha01")
    
    val image = animatedVectorResource(id = R.drawable.animated_vector)
    val atEnd by remember { mutableStateOf(false) }
    Icon(
       painter = image.painterFor(atEnd = atEnd),
       contentDescription = null
    )