-
Notifications
You must be signed in to change notification settings - Fork 6.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Jetpack Compose Support #4459
Comments
take a look at this: |
It looks like this has been deprecated. It would be good to port this behaviour and support it going forward within this project instead :) |
@sjudd Hey, I believe you're one of the maintainers of Glide. Is it a planned feature? Does Glide's team want help from the community on this? Jetpack Compose is going to stable soon, I believe later this month or next month |
I'm totally happy to get contributions here. I personally don't have much opportunity to use compose or Kotlin at work right now, so someone familiar with the space would be great. Probably it would make sense to convert one of the existing sample apps to kotlin/compose, then write the integration library. |
This library looks like an alternative... |
Glide works fine with compose using this little helper method: @Composable
fun loadPicture(url: String, placeholder: Painter? = null): Painter? {
var state by remember {
mutableStateOf(placeholder)
}
val options: RequestOptions = originalSizeStrategy
val context = LocalContext.current
val result = object : CustomTarget<Bitmap>() {
override fun onLoadCleared(p: Drawable?) {
state = placeholder
}
override fun onResourceReady(
resource: Bitmap,
transition: Transition<in Bitmap>?,
) {
state = BitmapPainter(resource.asImageBitmap())
}
}
try {
Glide.with(context)
.asBitmap()
.load(url)
.apply(options)
.into(result)
} catch (e: Exception) {
// Can't use LocalContext in Compose Preview
}
return state
} @Composable
fun ImageItem() {
val painter = loadPicture(
url = item.image.fragments.image.href,
placeholder = painterResource(id = R.drawable.tc_ic_no_image)
)
if (painter != null) {
Image(painter = painter)
}
} |
@kurtsson it might cause out of memory exception, you can use BoxWithConstraints to get available size of composable and reduce resolution of bitmap before setting it to state |
@sanjeevirajm Good point, it's more a proof of concept than a solution every possible outcome. But if you trust your indata you shouldn't have to worry about that right? |
Any updates on this issue? Do you have plans to implement it? |
will Glide has support for Jetpack compose? |
Created a POC. It does these two things, Properly cancels the image request |
@sanjeevirajm I had problem with GlideImage using so much memory when fetching images from Firebase Storage and was causing lags especially when used in LazyColumn. This implementation works great. One thing that could be improved is the blinking of the image. If you could look into that would be great. |
I have used it in LazyColumn. It works well. But not sure about large images. Ideally it shouldn't consume much memory since it adds glide target size based on the composable size. |
My bad for not explaining well. GlideImage was another library that was causing heavy memory usage. This implementation of yours is great fixed all that. A minor improvement is that flashing that is happening when you load images or if you go back to a screen where they were loaded the just flash like is loading them again |
@ndriqimh Try passing a placeholder value and check whether the issue persists. If you don't have any placeholder drawable, pass an empty transparent drawable. I think it will work fine. |
guys, use Coil library. it supports compose very well. you can even use composables as loading/error placeholders |
@kurtsson @sanjeevirajm I adopted this solution here: jaredsburrows/android-gif-search@5690523. Code:
Usage:
|
@mykola-dev Images load slower in Coil. |
An initial version is available see https://bumptech.github.io/glide/int/compose.html for how to access it. The remaining steps are to do an actual release of the alpha version and then iterate on any feedback. |
It'd be great if Glide can support Jetpack compose with a composable like
GlideImage
Expected Usage (minimum)
setContent { GlideImage(url) }
The text was updated successfully, but these errors were encountered: