androidx.compose.animation.graphics.res

Top-level functions summary

Painter

Creates and remembers a Painter to render an AnimatedImageVector.

Extension functions summary

Top-level functions

rememberAnimatedVectorPainter

@ExperimentalAnimationGraphicsApi
@Composable
fun rememberAnimatedVectorPainter(
    animatedImageVector: AnimatedImageVector,
    atEnd: Boolean
): Painter

Creates and remembers a Painter to render an AnimatedImageVector. It renders the image either at the start or the end of all the animations depending on the atEnd. Changes to atEnd are animated.

import androidx.annotation.DrawableRes
import androidx.compose.animation.graphics.ExperimentalAnimationGraphicsApi
import androidx.compose.animation.graphics.res.animatedVectorResource
import androidx.compose.animation.graphics.res.rememberAnimatedVectorPainter
import androidx.compose.animation.graphics.vector.AnimatedImageVector
import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp

@OptIn(ExperimentalAnimationGraphicsApi::class)
@Composable
fun AnimatedVector(@DrawableRes drawableId: Int) {
    val image = AnimatedImageVector.animatedVectorResource(drawableId)
    var atEnd by remember { mutableStateOf(false) }
    Image(
        painter = rememberAnimatedVectorPainter(image, atEnd),
        contentDescription = "Your content description",
        modifier = Modifier.size(64.dp).clickable { atEnd = !atEnd }
    )
}
Parameters
atEnd: Boolean

Whether the animated vector should be rendered at the end of all its animations.

Extension functions

@ExperimentalAnimationGraphicsApi
@Composable
fun AnimatedImageVector.Companion.animatedVectorResource(
    id: @DrawableRes Int
): AnimatedImageVector

Load an AnimatedImageVector from an Android resource id.

import androidx.annotation.DrawableRes
import androidx.compose.animation.graphics.ExperimentalAnimationGraphicsApi
import androidx.compose.animation.graphics.res.animatedVectorResource
import androidx.compose.animation.graphics.res.rememberAnimatedVectorPainter
import androidx.compose.animation.graphics.vector.AnimatedImageVector
import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp

@OptIn(ExperimentalAnimationGraphicsApi::class)
@Composable
fun AnimatedVector(@DrawableRes drawableId: Int) {
    val image = AnimatedImageVector.animatedVectorResource(drawableId)
    var atEnd by remember { mutableStateOf(false) }
    Image(
        painter = rememberAnimatedVectorPainter(image, atEnd),
        contentDescription = "Your content description",
        modifier = Modifier.size(64.dp).clickable { atEnd = !atEnd }
    )
}
Parameters
id: @DrawableRes Int

the resource identifier

Returns
AnimatedImageVector

an animated vector drawable resource.