bumptech / glide

An image loading and caching library for Android focused on smooth scrolling
https://bumptech.github.io/glide/
Other
34.61k stars 6.12k forks source link

[Compose] GlideSubcomposition state is changing from Loading-Success-Loading #5418

Open jimmytrivediuser opened 3 months ago

jimmytrivediuser commented 3 months ago

I'm using the Glide Compose version, and the images were loading fine in the Alpha version. However, after switching to the Beta version, I started encountering this issue.

def glideComposeVersion = '1.0.0-alpha.3' def glideComposeVersion = '1.0.0-beta01'

Older Alpha version code:

val placeholder = placeholder { CustomPlaceHolder(modifier = placeHolderModifier) }
                    GlideImage(
                        model = image?.image,
                        contentDescription = "image",
                        modifier = imageModifier,
                        contentScale = ContentScale.Fit,
                        alignment = Alignment.Center,
                        colorFilter = null,
                        alpha = DefaultAlpha,
                        loading = placeholder,
                        failure = placeholder
                    ) {
                        it.diskCacheStrategy(DiskCacheStrategy.ALL)
                    }](url)

Newer Beta version code:

GlideSubcomposition(
                        image?.image,
                        imageModifier,
                        { it.diskCacheStrategy(DiskCacheStrategy.ALL) }) {

                        if (state !is RequestState.Success) {
                            CustomPlaceHolder(modifier = placeHolderModifier)
                        } else {
                            Image(
                                painter,
                                contentDescription = "image",
                                imageModifier,
                                contentScale = ContentScale.Fit,
                                alignment = Alignment.Center,
                                colorFilter = null,
                                alpha = DefaultAlpha,
                            )
                        }
                    }

Troubleshooting When I printed state in the Beta version, it first shows loading, then success, and then switches back to loading. As a result, the images on the UI flicker and disappear.