coil-kt / coil

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

Request support for DrawableResource for compose multiplatform #2345

Closed Junzz0 closed 2 days ago

Junzz0 commented 3 days ago

Is your feature request related to a problem? Please describe. Loading a DrawableResource with coil will cause a crash.

    val imageLoader = rememberAsyncImagePainter(
        model = painterResource(Icons.ABC),
    )

    Image(
        painter = imageLoader,
        contentDescription = contentDescription,
    )

Icons.ABC is DrawableResource

https://www.jetbrains.com/help/kotlin-multiplatform-dev/compose-images-resources.html

Describe the solution you'd like Request support for DrawableResource for compose multiplatform

colinrtwhite commented 2 days ago

Yep, this is planned to be next up now that alpha07 is out. There's already a ticket tracking support here.

Just to note rememberAsyncImagePainter(painterResource(Icons.ABC)) will always crash since you can't pass a Painter to rememberAsyncImagePainter. Painters should be passed directly to Image. This will be supported, though:

AsyncImage(
  model = Res.getUri("files/my_photo.jpg"),
  contentDescription = null,
)