-
-
Notifications
You must be signed in to change notification settings - Fork 6k
Fix sd_imageFormat
sometimes returns undefined
on static image
#3760
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
Conversation
@@ -182,6 +182,8 @@ - (instancetype)initWithData:(NSData *)data scale:(CGFloat)scale options:(SDImag | |||
#else | |||
self = [super initWithCGImage:image.CGImage scale:MAX(scale, 1) orientation:image.imageOrientation]; | |||
#endif | |||
// Defines the associated object that holds the format for static images | |||
super.sd_imageFormat = format; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems it's better to just to override the sd_imageFormat
and return the animatedImageFormat
Oh, I've already use this 2 years ago...
It's a history issue of Some of SDImageFormat format;
UIImage *image;
if ([image isKindOfClass:SDAnimatedImage.class]) {
format = [image animatedImageFormat];
} else {
format = image.sd_imageFormat;
} After #3626, I've fixed some of them, but not all of them. It's OK to merge this PR, but I doubt this will make things more and more difficult to maintain. Should all the Because in some use case, |
By the way, your comment here:
Is not correct. Check the Only if you use the |
SDWebImage/Core/SDAnimatedImage.m
Outdated
@@ -375,7 +377,8 @@ - (SDImageFormat)sd_imageFormat { | |||
} | |||
|
|||
- (void)setSd_imageFormat:(SDImageFormat)sd_imageFormat { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This override method does nothing (The same as super implementation actually). You can just remove this function at all, which has the same effect.
It's OK I can just merge this, and remove that |
Thank you for reviewing my PR. I can certainly remove that override. I mainly left it there to comment on the situations in which the user might expect it to be triggered. |
sd_imageFormat
sometimes returns undefined
sd_imageFormat
sometimes returns undefined
on static image
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:
sd_imageFormat
returns nil when used onSDAnimatedImage
to which static image were loaded.Pull Request Description
When a static image is loaded into
SDAnimatedImage
, thesd_imageFormat
remains unset. As a result, the associated object on the underlyingUIImage
is not present. This value is typically assigned by decoders; for instance,SDImageIOCoder
does so here. However, withSDAnimatedImage
, the correct format is returned only if theanimatedImageData
is included.I’m uncertain if my solution is accurate (I’ve tested it, but I’m unsure if it’s the right approach). I’ve opened this PR to initiate a discussion on how to properly address that issue.