Hey guys, I have a animated resource that i am trying to display in compose-multiplatform but my app keeps crashing whenever it reaches the stage of rendering the resource, in android I would do this
Copy code
@Composable
fun AnimatedVectorDrawable() {
val image = AnimatedImageVector.animatedVectorResource(R.drawable.ic_hourglass_animated)
var atEnd by remember { mutableStateOf(false) }
Image(
painter = rememberAnimatedVectorPainter(image, atEnd),
contentDescription = "Timer",
modifier = Modifier.clickable {
atEnd = !atEnd
},
contentScale = ContentScale.Crop
)
}
in commonMain i tried this but the
id, property
that animatedVectorResource is trying to identify is not present in the Res.drawable.ic_hourglass_animated
m
Max
04/07/2024, 12:34 PM
Not sure if animated vector drawables are supported with the current Resource api? I would say not yet
k
Kambi Victor
04/07/2024, 12:36 PM
I visited the docs as well as experimental apis and it doesn't seem to support it yet. Do you have any work arounds for animating vector drawables?
m
Max
04/08/2024, 8:14 AM
@Kambi Victor Since XML drawables are a very specific format for animation, i’d say there is no way currently. You could rebuild the animation in pure compose, or use a Lottie. There are Lottie libs out there afaik for CMP. Personally, i try to minimize 3rd party usage, to minimize build breakage when KMP/CMP will be upgraded. So personally i would try to use pure compose
k
Kambi Victor
04/08/2024, 8:16 AM
@Max I plan on using pure compose for this. Thanks for the suggestion.