coil-kt / coil

Image loading for Android and Compose Multiplatform.

Home Page:https://coil-kt.github.io/coil/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

rememberAsyncImagePainter with crossfade setup

hrach opened this issue · comments

Is your feature request related to a problem? Please describe.
In Coil 1.X we were using

Image(rememberImagePainter(avatarUrl) { crossfade(true) })

Describe the solution you'd like

In Coil 2.0, I see no easy way to use this async painter with crossfade, only using ImageRequest.Builder. This make the API a lot more complex.

Image(rememberAsyncImagePainter(avatarUrl, crossfade = true)

or something similar would be nice.

If you'd like to crossfade by default you can set ImageLoader.Builder.crossfade(true) otherwise I'd create a custom extension function in your local build that can apply an ImageRequest DSL builder similar to rememberImagePainter:

@Composable
inline fun rememberAsyncImagePainter(data: Any?, builder: ImageRequest.Builder.() -> Unit) = rememberAsyncImagePainter(ImageRequest.Builder(LocalContext.current).data(data).apply(builder).build())