Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes AnimatedImageView designated inilializer not work #512

Merged
45 changes: 26 additions & 19 deletions Source/Classes/AnimatedImages/PINAnimatedImageView.m
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,31 @@ - (void)commonInit:(PINCachedAnimatedImage *)animatedImage
{
_animatedImage = animatedImage;
_animatedImageRunLoopMode = NSRunLoopCommonModes;

[self initializeAnimatedImage:animatedImage];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a nil check here and make mark initializeAnimatedImage: as taking a non null animatedImage?

}

- (void)initializeAnimatedImage:(PINCachedAnimatedImage *)animatedImage
{
PINWeakify(self);
animatedImage.coverImageReadyCallback = ^(PINImage *coverImage) {
dispatch_async(dispatch_get_main_queue(), ^{
PINStrongify(self);
// In this case the lock is already gone we have to call the unlocked version therefore
[self coverImageCompleted:coverImage];
});
};

animatedImage.playbackReadyCallback = ^{
dispatch_async(dispatch_get_main_queue(), ^{
// In this case the lock is already gone we have to call the unlocked version therefore
PINStrongify(self);
[self checkIfShouldAnimate];
});
};
if (animatedImage.playbackReady) {
[self checkIfShouldAnimate];
}
}

- (void)dealloc
Expand All @@ -84,25 +109,7 @@ - (void)setAnimatedImage:(PINCachedAnimatedImage *)animatedImage
_animatedImage = animatedImage;

if (animatedImage != nil) {
PINWeakify(self);
animatedImage.coverImageReadyCallback = ^(PINImage *coverImage) {
dispatch_async(dispatch_get_main_queue(), ^{
PINStrongify(self);
// In this case the lock is already gone we have to call the unlocked version therefore
[self coverImageCompleted:coverImage];
});
};

animatedImage.playbackReadyCallback = ^{
dispatch_async(dispatch_get_main_queue(), ^{
// In this case the lock is already gone we have to call the unlocked version therefore
PINStrongify(self);
[self checkIfShouldAnimate];
});
};
if (animatedImage.playbackReady) {
[self checkIfShouldAnimate];
}
[self initializeAnimatedImage:animatedImage];
} else {
// Clean up after ourselves.
self.layer.contents = nil;
Expand Down