PINRemoteImage
PINRemoteImage copied to clipboard
PINAnimatedImageView bug when loading two or more gifs with the same url
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.
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>
We also have the same issue