What is the best way to load a bitmap with a suspe...
# compose
a
What is the best way to load a bitmap with a suspend function? I want to use Google Places sdk and it provide a
Task
that returns
Bitmap
... I've added an
await()
method to convert it to Bitmap directly... but, how to load it onto Composable?
I've thought to use
Coil
with custom ImageLoader, and pass the id as
data =
, but it looks overeenginering
a
You can use the
.asImageBitmap()
extension to get a Compose
ImageBitmap
object for the input Android
Bitmap
, then use it in an
Image
composable
a
uhmmm, but i will need to obtain the bitmap from places sdk on the composabale? i wanted to spslit the code...
a
You can obtain the bitmap from anywhere you can run scoped async code.
LaunchedEffect
would be one way to do it very locally in a composable, but once the proof of concept is up and running I'm guessing you'll want to do the actual load in some other repository scope or similar and cache it more globally for the app