Update the behavior about `SDAnimatedImage` for the category metadata

Now `SDAnimatedImage` can be static image, so some check is not correct
This commit is contained in:
DreamPiggy 2024-05-06 15:20:39 +08:00
parent e55cb041d0
commit fb7ded8066
3 changed files with 24 additions and 9 deletions

View File

@ -335,7 +335,7 @@ static CGFloat SDImageScaleFromPath(NSString *string) {
@implementation SDAnimatedImage (Metadata)
- (BOOL)sd_isAnimated {
return YES;
return self.animatedImageFrameCount > 1;
}
- (NSUInteger)sd_imageLoopCount {
@ -347,11 +347,21 @@ static CGFloat SDImageScaleFromPath(NSString *string) {
}
- (NSUInteger)sd_imageFrameCount {
return self.animatedImageFrameCount;
NSUInteger frameCount = self.animatedImageFrameCount;
if (frameCount > 1) {
return frameCount;
} else {
return 1;
}
}
- (SDImageFormat)sd_imageFormat {
return self.animatedImageFormat;
NSData *animatedImageData = self.animatedImageData;
if (animatedImageData) {
return [NSData sd_imageFormatForImageData:animatedImageData];
} else {
return [super sd_imageFormat];
}
}
- (void)setSd_imageFormat:(SDImageFormat)sd_imageFormat {

View File

@ -83,11 +83,8 @@ inline UIImage * _Nullable SDScaledImageForScaleFactor(CGFloat scale, UIImage *
scaledImage = [[image.class alloc] initWithData:data scale:scale];
}
}
if (scaledImage) {
return scaledImage;
}
}
if (image.sd_isAnimated) {
if (!scaledImage && image.sd_isAnimated) {
UIImage *animatedImage;
#if SD_UIKIT || SD_WATCH
// `UIAnimatedImage` images share the same size and scale.
@ -100,7 +97,6 @@ inline UIImage * _Nullable SDScaledImageForScaleFactor(CGFloat scale, UIImage *
}
animatedImage = [UIImage animatedImageWithImages:scaledImages duration:image.duration];
animatedImage.sd_imageLoopCount = image.sd_imageLoopCount;
#else
// Animated GIF for `NSImage` need to grab `NSBitmapImageRep`;
NSRect imageRect = NSMakeRect(0, 0, image.size.width, image.size.height);

View File

@ -24,6 +24,8 @@
* NSImage currently only support animated via `NSBitmapImageRep`(GIF) or `SDAnimatedImageRep`(APNG/GIF/WebP) unlike UIImage.
* The getter of this property will get the loop count from animated imageRep
* The setter of this property will set the loop count from animated imageRep
* SDAnimatedImage:
* Returns `animatedImageLoopCount`
*/
@property (nonatomic, assign) NSUInteger sd_imageLoopCount;
@ -35,6 +37,8 @@
* AppKit:
* Returns the underlaying `NSBitmapImageRep` or `SDAnimatedImageRep` frame count.
* Returns 1 for static image.
* SDAnimatedImage:
* Returns `animatedImageFrameCount`
*/
@property (nonatomic, assign, readonly) NSUInteger sd_imageFrameCount;
@ -42,7 +46,9 @@
* UIKit:
* Check the `images` array property.
* AppKit:
* NSImage currently only support animated via GIF imageRep unlike UIImage. It will check the imageRep's frame count.
* NSImage currently only support animated via GIF imageRep unlike UIImage. It will check the imageRep's frame count > 1.
* SDAnimatedImage:
* Check `animatedImageFrameCount` > 1
*/
@property (nonatomic, assign, readonly) BOOL sd_isAnimated;
@ -51,6 +57,8 @@
* Check the `isSymbolImage` property. Also check the system PDF(iOS 11+) && SVG(iOS 13+) support.
* AppKit:
* NSImage supports PDF && SVG && EPS imageRep, check the imageRep class.
* SDAnimatedImage:
* Returns `NO`
*/
@property (nonatomic, assign, readonly) BOOL sd_isVector;
@ -58,6 +66,7 @@
* The image format represent the original compressed image data format.
* If you don't manually specify a format, this information is retrieve from CGImage using `CGImageGetUTType`, which may return nil for non-CG based image. At this time it will return `SDImageFormatUndefined` as default value.
* @note Note that because of the limitations of categories this property can get out of sync if you create another instance with CGImage or other methods.
* @note For `SDAnimatedImage`, returns `animatedImageFormat` when animated, or fallback when static.
*/
@property (nonatomic, assign) SDImageFormat sd_imageFormat;