https://kotlinlang.org logo
#compose
Title
# compose
v

Vitor Prado

01/05/2021, 3:58 PM
hey guys, can you help me with this simple question: How can I check for “preview” state inside composable? Can I know when the view is rendering in preview environment?
k

Kirill Grouchnikov

01/05/2021, 4:02 PM
Why would you want to know that? What do you want to do in preview that you wouldn't want to do in the "real" on-device flow?
v

Vitor Prado

01/05/2021, 4:03 PM
I’m using accompanist lib (for network-image) and it crashes in preview mode, ’cause picasso isn’t available.
thinking about wrap this inside a composable and draw the correct image in production and a placeholder simple image in preview mode.
j

Javier

01/05/2021, 4:04 PM

https://youtu.be/exjL2kGPngI?t=185

A solution could be a
sealed class
which accept a normal local drawable and a url, so you can use the normal drawable branch as fake for previews for example
v

Vitor Prado

01/05/2021, 4:12 PM
thanks @Javier
@Javier is a good idea to use an ambient provider?
c

Colton Idle

01/05/2021, 4:29 PM
Using accompanist for image loading crashes in @Preview? Sounds like accompanist should/could handle that, no?
v

Vitor Prado

01/05/2021, 4:30 PM
@Colton Idle yeps!
7 Views