How do you handle image resources in compose? I ha...
# compose
p
How do you handle image resources in compose? I have a xml vector that has 4 different colors I need to change at runtime. Using the old xml stuff I'd create a context theme wrapper that wraps a theme and then fetch the drawable. Is there any good solution for compose? The only "workaround" I've found is to do that inside compositon local provider:
Copy code
CompositionLocalProvider(LocalContext provides LocalContext.current.withTheme(R.style.MyTheme)) {
          Image(
            modifier = Modifier.align(Alignment.TopEnd),
            painter = painterResource(id = R.drawable.my_image), contentDescription = null
          )
        }
a
@Nader Jawad
n
We have an experimental API for AnimatedImageVector which is the equivalent to AnimatedVectorDrawable but in compose. Internally it supports an optional lookup mapping to override the default property for any named path or group. We're still iterating in this space and have not exposed it externally yet so the solution you have currently is probably the easiest way to support this case for now.
p
Looking forward towards this, it's good the hear that it's being evaluated.