https://kotlinlang.org logo
Title
m

Marcin Wisniowski

01/30/2022, 8:08 PM
How can I set a preview placeholder for a Coil image? It lacks an alternative to
tools:src
. The Accompanist version had a
previewPlaceholder
. But after Compose support moved to the Coil library proper, it was removed. Are there any solutions?
s

Sergey Y.

01/30/2022, 10:03 PM
According to the Coil documentation you need to set
placeholder
within request builder scope.
m

Marcin Wisniowski

01/30/2022, 10:48 PM
That's something different,
placeholder
sets the image visible in the app during loading, not a @Preview replacement image.
s

Sergey Y.

01/30/2022, 11:03 PM
No, it is also working for Preview. Please, read the doc first https://coil-kt.github.io/coil/compose/#migrating-from-accompanist
previewPlaceholder is removed. ImageRequest.placeholder is now automatically used if inspection mode is enabled.
m

Marcin Wisniowski

01/30/2022, 11:10 PM
I know the placeholder image is visible in Preview. But I don't see how that solves my problem. Like I said, I am looking for something like
tools:src
in ImageView or
previewPlaceholder
in the previous version of Coil. They don't affect the app, unlike what you are suggesting. I don't want my placeholder to be visible at runtime.
s

Sergey Y.

01/30/2022, 11:16 PM
Oh, I see. AFAIK, it doesn't exist for Coil.
You can workaround it with if (LocalInspectionMode.current) { // set your placeholder image }
m

Marcin Wisniowski

01/31/2022, 12:22 AM
That could work, thanks.