pinterest / PINRemoteImage

A thread safe, performant, feature rich image fetcher
Apache License 2.0
4.01k stars 511 forks source link

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

Open hovox opened 5 years ago

hovox commented 5 years ago

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.

iwheelbuy commented 4 years ago

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>

alex-vasenin commented 3 years ago

We also have the same issue