PINRemoteImage icon indicating copy to clipboard operation
PINRemoteImage copied to clipboard

PINAnimatedImageView bug when loading two or more gifs with the same url

Open hovox opened this issue 5 years ago • 2 comments

Let's say we have a two PINAnimatedImageView instances, if we load same gif url simultaneously for those two image views, only one of them will work. Another one will not load anything.

By simultaneously I mean something like this:

NSURL *url = [NSURL URLWithString:@"google.com"];
[imageView1 pin_setImageFromURL:url];
[imageView2 pin_setImageFromURL:url];

Issue happens because only one PINAnimatedCachedImage instance is created for those two image views so those two views use same PINAnimatedCachedImage instance. PINAnimatedCachedImage has coverImageReadyCallback and playbackReadyCallback properties which seems not designed to work right in this case. What happens is one image view sets coverImageReadyCallback and playbackReadyCallback properties and another one is overriding them.

hovox avatar Jul 10 '19 11:07 hovox

Have the same issue with two images applied simultaneously.

if let object = result.alternativeRepresentation as? PINCachedAnimatedImage {
    // set image
}

We receive one instance of the image for both views:

<PINCachedAnimatedImage: 0x281911d80> <PINCachedAnimatedImage: 0x281911d80>

I believe there is an easy work around

if let object = result.alternativeRepresentation as? PINCachedAnimatedImage {
    let object: PINCachedAnimatedImage = {
        guard let data = object.data else {
            return object
        }
        return PINCachedAnimatedImage(animatedImageData: data) ?? object
    }()
    // set image
}

It might not work in all situations, but it works for me and as a result I get different instances of one image.

<PINCachedAnimatedImage: 0x2837dd100> <PINCachedAnimatedImage: 0x2837e6380>

iwheelbuy avatar Jan 16 '20 07:01 iwheelbuy

We also have the same issue

alex-vasenin avatar Dec 20 '20 01:12 alex-vasenin