Update the implementation `SDScaledImageForScaleFactor` to support SDAnimatedImage

This commit is contained in:
DreamPiggy 2023-05-15 14:41:10 +08:00
parent 08ca5f4b22
commit 2331bcc690
1 changed files with 19 additions and 0 deletions

View File

@ -9,6 +9,7 @@
#import "SDWebImageDefine.h"
#import "UIImage+Metadata.h"
#import "NSImage+Compatibility.h"
#import "SDAnimatedImage.h"
#import "SDAssociatedObject.h"
#pragma mark - Image scale
@ -81,6 +82,24 @@ inline UIImage * _Nullable SDScaledImageForScaleFactor(CGFloat scale, UIImage *
return image;
}
UIImage *scaledImage;
// Check SDAnimatedImage support for shortcut
if ([image.class conformsToProtocol:@protocol(SDAnimatedImage)]) {
if ([image respondsToSelector:@selector(animatedCoder)]) {
id<SDAnimatedImageCoder> coder = [(id<SDAnimatedImage>)image animatedCoder];
if (coder) {
scaledImage = [[image.class alloc] initWithAnimatedCoder:coder scale:scale];
}
} else {
// Some class impl does not support `animatedCoder`, keep for compatibility
NSData *data = [(id<SDAnimatedImage>)image animatedImageData];
if (data) {
scaledImage = [[image.class alloc] initWithData:data scale:scale];
}
}
if (scaledImage) {
return scaledImage;
}
}
if (image.sd_isAnimated) {
UIImage *animatedImage;
#if SD_UIKIT || SD_WATCH