Skip to content

Commit

Permalink
Use proper keys for image state in `IOSImageLoader#rememberImageLoade…
Browse files Browse the repository at this point in the history
…rState`

This was causing issues were a different image was loading for few seconds before correct image is loaded
  • Loading branch information
msasikanth committed Sep 18, 2023
1 parent 2502fc9 commit 405909f
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
package dev.sasikanth.rss.reader.components

import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.State
import androidx.compose.runtime.produceState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.asComposeImageBitmap
import dev.sasikanth.rss.reader.di.scopes.AppScope
Expand Down Expand Up @@ -62,15 +64,20 @@ internal fun rememberImageLoaderState(url: String?): State<ImageLoaderState> {
ImageLoaderState.Loading
}
val imageLoader = LocalImageLoader.current
val result = remember(url, imageLoader) { mutableStateOf(initialState) }

return produceState(initialState, url) {
value =
LaunchedEffect(url) {
val imageLoaderState =
try {
ImageLoaderState.Loaded(imageLoader?.getImage(url!!, size = null)!!)
} catch (e: Exception) {
ImageLoaderState.Error
}

result.value = imageLoaderState
}

return result
}

internal sealed interface ImageLoaderState {
Expand Down

0 comments on commit 405909f

Please sign in to comment.