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

Lauren Yew

01/21/2021, 1:42 AM
Does anyone know how far
remember{…}
can work on a list of Bitmaps? I was trying to use it to remember the state of a Bitmap I loaded from Picasso for list items, but scrolling back and forth on a list, I still see the bitmaps having to reload. Following example here: https://stackoverflow.com/questions/58594262/how-do-i-load-url-into-image-into-drawimage-in-compose-ui-android-jetpack
Copy code
val imageState = remember(id) { loadPicture(url = item.photoUrl) }
private fun loadPicture(url: String?): State<ImageState> {
val imageState: MutableState<ImageState> = mutableStateOf(ImageState.Empty)
... //Picasso
}

sealed class ImageState {
    data class Success(val image: Bitmap) : ImageState()
    object Failed : ImageState()
    object Loading : ImageState()
    object Empty : ImageState()
}
1
d

Dominaezzz

01/21/2021, 9:43 AM
Remember doesn't remember anything after it gets disposed/ removed from the composition.
You'll probably just need to use a map outside the lazy column.
j

jw

01/21/2021, 3:41 PM
Picasso already implements that map for you though. Re-requesting the same image is effectively free.
l

Lauren Yew

01/21/2021, 5:08 PM
The weird thing is I still get a delay from Picasso to get the old image. Delay can last up to 30 secs.
When I had this list not in jet pack compose I hardly had a delay at all.
3 Views