Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add animationImages support when using SDAnimatedImageView #3113

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

Merged
merged 1 commit into from
Nov 3, 2020

Conversation

MoZhouqi
Copy link
Contributor

@MoZhouqi MoZhouqi commented Oct 27, 2020

New Pull Request Checklist

  • I have read and understood the CONTRIBUTING guide

  • I have read the Documentation

  • I have searched for a similar pull request in the project and found none

  • I have updated this branch with the latest master to avoid conflicts (via merge from master or rebase)

  • I have added the required tests to prove the fix/feature I am adding

  • I have updated the documentation (if necessary)

  • I have run the tests and they pass

  • I have run the lint and it passes (pod lib lint)

This merge request fixes / refers to the following issues: ...

Pull Request Description

Add animationImages support when using SDAnimatedImageView.
...

@MoZhouqi
Copy link
Contributor Author

@kinarobin Thanks for your suggestion, I have updated the code.

@dreampiggy
Copy link
Contributor

dreampiggy commented Oct 29, 2020

I wonder, what cause this issue ?

We override the super startAnimating: and setImage:, and setAnimations also use the super implementation.

If you use UIImageView.aniamtionImages, it shoud work as normal, because it's super's implementation

@MoZhouqi
Copy link
Contributor Author

I wonder, what cause this issue ?

We override the super startAnimating: and setImage:, and setAnimations also use the super implementation.

If you use UIImageView.aniamtionImages, it shoud work as normal, because it's super's implementation

For example:

SDAnimatedImageView *imageView = [SDAnimatedImageView alloc] initWithFrame:frame];
imageView.animationImages = animationImages;
[imageView startAnimating];
imageView.hidden = NO;

There are two issues with the above code:

  1. Although the default value of autoPlayAnimatedImage is YES, the animation is not playing automatically after setting a non-nil value on the animationImages property.
  2. When setHidden: method is called, checkPlay method will be invoked and then the animation will be stopped.

@dreampiggy
Copy link
Contributor

I wonder, what cause this issue ?
We override the super startAnimating: and setImage:, and setAnimations also use the super implementation.
If you use UIImageView.aniamtionImages, it shoud work as normal, because it's super's implementation

For example:

SDAnimatedImageView *imageView = [SDAnimatedImageView alloc] initWithFrame:frame];
imageView.animationImages = animationImages;
[imageView startAnimating];
imageView.hidden = NO;

There are two issues with the above code:

  1. Although the default value of autoPlayAnimatedImage is YES, the animation is not playing automatically after setting a non-nil value on the animationImages property.
  2. When setHidden: method is called, checkPlay method will be invoked and then the animation will be stopped.

I see... This can be updated into the Unit Test (SDWebImage Tetsts), so that can ensure this will not be broken in later version.

@MoZhouqi
Copy link
Contributor Author

I wonder, what cause this issue ?
We override the super startAnimating: and setImage:, and setAnimations also use the super implementation.
If you use UIImageView.aniamtionImages, it shoud work as normal, because it's super's implementation

For example:

SDAnimatedImageView *imageView = [SDAnimatedImageView alloc] initWithFrame:frame];
imageView.animationImages = animationImages;
[imageView startAnimating];
imageView.hidden = NO;

There are two issues with the above code:

  1. Although the default value of autoPlayAnimatedImage is YES, the animation is not playing automatically after setting a non-nil value on the animationImages property.
  2. When setHidden: method is called, checkPlay method will be invoked and then the animation will be stopped.

I see... This can be updated into the Unit Test (SDWebImage Tetsts), so that can ensure this will not be broken in later version.

I've added the test cases for animationImages.

Copy link
Contributor

@dreampiggy dreampiggy left a comment

Choose a reason for hiding this comment

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

I have another way to solve this problem, by leaving all the control to UIKit, we don't touch.

Remove all the changes to SDAnimatedImageView, only modify this method:

/// Check if it should be played
- (void)checkPlay
{
    // Only handle for SDAnimatedImage, leave UIAnimatedImage or animatedImages for super implementation control
    if (self.player && self.autoPlayAnimatedImage) {
        [self updateShouldAnimate];
        if (self.shouldAnimate) {
            [self startAnimating];
        } else {
            [self stopAnimating];
        }
    }
}

I have tested this also match your behavior, but it's more suitable and maintainable. I think, SDAnimatedImageView should be a drop-in replacement for UIImageView. So if super class implementation do something, we should call their instead and only handle the case we added (That SDAnimatedImagePlayer or SDAnimatedImage), not assume current iOS's behavior.

For this issue, I think this autoPlayAnimatedImage should only effect SDAnimatedImage, we can update the code comment in header files about this.

See:

image

@MoZhouqi
Copy link
Contributor Author

@dreampiggy Yes I see, it is better, I have updated the code, the test cases and the code comment in header files.

@MoZhouqi MoZhouqi requested a review from dreampiggy October 30, 2020 07:47
Copy link
Contributor

@dreampiggy dreampiggy left a comment

Choose a reason for hiding this comment

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

Now it's better :)

@MoZhouqi
Copy link
Contributor Author

Now it's better :)

🍻 Yes, the previous treatment is not perfect, I should also deal with other properties properly, such as currentFrame.

@dreampiggy dreampiggy merged commit 264d7a4 into SDWebImage:master Nov 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants