Is there something special to get an AnimatedVecto...
# compose
e
Is there something special to get an AnimatedVectorDrawable work with Compose? I have the drawables stored as an Icon and load it this way:
Copy code
val drawable = context.packageManager.getDrawable(icon.resPackage, icon.resId, null)
I then use it using Accompanist:
Copy code
remember(icon.resId) { DrawablePainter(drawable.mutate()) }
It doesn't start by default, and even when I call
drawable.start()
it won't run, and
drawable.isRunning
returns false.
👀 1
j
Did you ever figure this out? I had the same issue a few weeks ago and ended up going over to Lottie for animations.
e
I did manage to get it working with a hack: I had set the drawable to an ImageView that wasn't visible. My suspicion is that the ImageView does something in
setDrawable
that triggers it to start. I wouldn't call it a solution as it's not anything I would put in production, but it points to where the issue might be. I was also able to load the vector as an
AnimatedImageVector
but there's no playback controls from what I can see 😕
i.e. I tried loading it two ways: Using
DrawablePainter
and using
rememberAnimatedVectorPainter
, neither worked.
@justinbis I was able to get it working using an AVI and this code:
Copy code
val vector = AnimatedImageVector.animatedVectorResource(resId)  
var atEnd by remember { mutableStateOf(false) }  
LaunchedEffect(vector) {    atEnd = true  }  Icon(    painter = rememberAnimatedVectorPainter(animatedImageVector = vector, atEnd = atEnd),    contentDescription = null)
Since my resource was in another package I also had to override LocalContext with a ContextWrapper and using
Resources
from that other package.