coil-kt / coil

Image loading for Android and Compose Multiplatform.
https://coil-kt.github.io/coil/
Apache License 2.0
10.49k stars 641 forks source link

Support Compose Multiplatform image resources #2077

Open colinrtwhite opened 5 months ago

colinrtwhite commented 5 months ago

Is your feature request related to a problem? Please describe. We should add support to load Compose Multiplatform image resources via Coil.

Describe the solution you'd like I should be able to do:

AsyncImage(
  model = Res.drawable.example_icon,
  contentDescription = null,
)

Additional context I think we're probably going to have to rely on internal semantics to load these resources in customer Fetchers for each platform (similar to how resources are included in the sample:compose app) as we can't use the generated composable functions.

This probably makes sense as an external artifact instead of being bundled with coil-compose-core as these Res classes are only necessary for Compose Multiplatform users - not Compose AndroidX users.

Open to a PR if someone wants to contribute this!

rustamsmax commented 5 months ago

Maybe we can use custom mappers? ImageResMapper to uri

colinrtwhite commented 5 months ago

We could map the Ints to Uris (similar to how we handle Android res IDs), but we'll still need a fetcher to convert the Uri into an ImageSource.