Skip to content

Instantly share code, notes, and snippets.

@anhvt52

anhvt52/RemoteImage.kt

Last active Apr 5, 2021
Embed
What would you like to do?
Jetpack Compose Remote Image using Glide
fun RemoteImage(uri: String, modifier: Modifier = Modifier, default: @Composable () -> Unit) {
val bitmapState = remember { mutableStateOf<Bitmap?>(null) }
Glide.with(AmbientContext.current).asBitmap().load(uri).into(
object : CustomTarget<Bitmap>() {
override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>?) {
bitmapState.value = resource
}
override fun onLoadCleared(placeholder: Drawable?) {
}
}
)
if (bitmapState.value != null) {
Image(
bitmap = bitmapState.value!!.asImageBitmap(),
modifier = modifier
)
} else {
default()
}
}
@luangs7

This comment has been minimized.

Copy link

@luangs7 luangs7 commented Apr 5, 2021

onResourceReady is not being called

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment