facebook / fresco

An Android library for managing images and the memory they use.
https://frescolib.org/
MIT License
17.07k stars 3.75k forks source link

Animated WebP loaded in recyclerView makes the app stutter. #2587

Open ganeshsuriya24 opened 3 years ago

ganeshsuriya24 commented 3 years ago

Description

I have a recyclerView and a list of animated webP static file urls. When I scroll through the recycler view, the UI starts to stutter and I could notice the lag clearly. This happens only if animation is started.

Reproduction

` val imageRequest = ImageRequestBuilder.newBuilderWithSource(Uri.parse("Static URL")).build()

                val controller: DraweeController = Fresco.newDraweeControllerBuilder()

                        .setImageRequest(imageRequest)

                        .setAutoPlayAnimations(false)

                        .setControllerListener(StickerControllerListener())

                        .setOldController(imageView.controller)

                        .build()
                imageView.controller = controller

`

Above code is called from recyclerView onBindViewHolder.

Animation is started and stopped in the below class -

` class StickerControllerListener: BaseControllerListener() {

private var animatable: Animatable? = null 

override fun onFinalImageSet(id: String?, imageInfo: ImageInfo?, animatable: Animatable?) {
    super.onFinalImageSet(id, imageInfo, animatable)
    this.animatable = animatable
    this.animatable?.start()
}

override fun onRelease(id: String?) {
    animatable?.stop()
    animatable = null
    Log.d("Fresco", "onRelease")
    super.onRelease(id)
}

} ` This issue happens when I use GridLayoutManager for RecyclerView.

Additional Information

wying111 commented 2 years ago

modify private var animatable: Animatable? = null to private var animatable: WeakReference<Animatable>? = null