KingsMentor / BlurHashExt

Kotlin extensions of BlurHash for ImageView, Glide, Coil, Piccasso, and fast loading BlurHashDrawable optimized for Android.
https://github.com/woltapp/blurhash
MIT License
122 stars 7 forks source link

blurhash doesn't seem to work w/ Coil 1.0 #5

Open kenyee opened 3 years ago

kenyee commented 3 years ago

Calling it with:

           image.load(it.imageUrls.small) {
                crossfade(true)
                blurPlaceHolder(it.blurHash, image, blurHash = blurHashHandler)
                { coilImageBuilder ->
                    coilImageBuilder.build()
                }
            }

blurHashHandler is initialized in the fragment like so:

val blurHashHandler = BlurHash(requireContext(), lruSize = 20, punch = 1F)

The images pop into view w/o showing the blurhash placeholder.

kenyee commented 3 years ago

hmm...could be related to the use of a gridlayout and constraintlayout fit sizing...image width/height is zero in the viewholder bind...
If I do this, it semi works but then you have a race condition w/ Coil so sometimes the images don't load properly and only the blurhash remains :-(

            blurHashHandler.execute(it.blurHash, 100, 100) { bitmapDrawable ->
                image.setImageDrawable(bitmapDrawable)
            }
            image.load(it.imageUrls.small) {
                crossfade(true)
            }
kenyee commented 3 years ago

this seems to work:

            image.load(it.imageUrls.small) {
                crossfade(true)
                blurPlaceHolder(it.blurHash, blurImageSizePx, blurImageSizePx, blurHash = blurHashHandler)
                { coilImageBuilder ->
                    coilImageBuilder.build()
                }
            }

but it's fairly slow generating the blur hash so the background stays white for a while