How can I set a preview placeholder for a Coil ima...
# compose
m
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
According to the Coil documentation you need to set
placeholder
within request builder scope.
m
That's something different,
placeholder
sets the image visible in the app during loading, not a @Preview replacement image.
s
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
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
Oh, I see. AFAIK, it doesn't exist for Coil.
You can workaround it with if (LocalInspectionMode.current) { // set your placeholder image }
m
That could work, thanks.
439 Views