pinterest / PINRemoteImage

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

PINAnimatedImageView Initializer with GIF #497

Closed DreamingInBinary closed 5 years ago

DreamingInBinary commented 5 years ago

Right now, if you initialize an instance of an PINAnimatedImageView using its initializer that takes in a PINCachedAnimatedImage it will not load the image due to the way the commonInit works:

- (void)commonInit:(PINCachedAnimatedImage *)animatedImage
{
    _animatedImage = animatedImage;
    _animatedImageRunLoopMode = NSRunLoopCommonModes;
}

It sets the iVar, but for the animated image to show you need:

- (void)setAnimatedImage:(PINCachedAnimatedImage *)animatedImage

TL;DR: If you've got an animated image and don't want to use the category to download it from a URL, and instead want to use it's initializer you've got to do this:

myAnimatedImageView = [PINAnimatedImageView new];
[myAnimatedImageView setAnimatedImage:theGIF];

when you should be able to do this:

myAnimatedImageView =  [[PINAnimatedImageView alloc] initWithAnimatedImage:theGIF];

Locally, I've verified that if you use animatedImage's setter, it works fine using the initializer:

- (void)commonInit:(PINCachedAnimatedImage *)animatedImage
{
    self.animatedImage = animatedImage;
    _animatedImageRunLoopMode = NSRunLoopCommonModes;
}