Fix the issue that SDAnimatedImage breaks the vector on macOS

This commit is contained in:
DreamPiggy 2024-07-01 18:21:01 +08:00
parent b8523c1642
commit e665fb52d6
2 changed files with 11 additions and 1 deletions

View File

@ -72,7 +72,7 @@
// This class override these methods from UIImage(NSImage), and it supports NSSecureCoding. // This class override these methods from UIImage(NSImage), and it supports NSSecureCoding.
// You should use these methods to create a new animated image. Use other methods just call super instead. // You should use these methods to create a new animated image. Use other methods just call super instead.
// @note Before 5.19, these initializer will return nil for static image (when all candidate SDAnimatedImageCoder returns nil instance), like JPEG data. After 5.19, these initializer will retry for static image as well, so JPEG data will return non-nil instance. // @note Before 5.19, these initializer will return nil for static image (when all candidate SDAnimatedImageCoder returns nil instance), like JPEG data. After 5.19, these initializer will retry for static image as well, so JPEG data will return non-nil instance. For vector image(PDF/SVG), always return nil.
// @note When the animated image frame count <= 1, all the `SDAnimatedImageProvider` protocol methods will return nil or 0 value, you'd better check the frame count before usage and keep fallback. // @note When the animated image frame count <= 1, all the `SDAnimatedImageProvider` protocol methods will return nil or 0 value, you'd better check the frame count before usage and keep fallback.
+ (nullable instancetype)imageNamed:(nonnull NSString *)name; // Cache in memory, no Asset Catalog support + (nullable instancetype)imageNamed:(nonnull NSString *)name; // Cache in memory, no Asset Catalog support
#if __has_include(<UIKit/UITraitCollection.h>) #if __has_include(<UIKit/UITraitCollection.h>)

View File

@ -141,6 +141,12 @@ static CGFloat SDImageScaleFromPath(NSString *string) {
if (!data || data.length == 0) { if (!data || data.length == 0) {
return nil; return nil;
} }
// Vector image does not supported, guard firstly
SDImageFormat format = [NSData sd_imageFormatForImageData:data];
if (format == SDImageFormatSVG || format == SDImageFormatPDF) {
return nil;
}
id<SDAnimatedImageCoder> animatedCoder = nil; id<SDAnimatedImageCoder> animatedCoder = nil;
SDImageCoderMutableOptions *mutableCoderOptions; SDImageCoderMutableOptions *mutableCoderOptions;
if (options != nil) { if (options != nil) {
@ -167,6 +173,10 @@ static CGFloat SDImageScaleFromPath(NSString *string) {
if (!image) { if (!image) {
return nil; return nil;
} }
// Vector image does not supported, guard secondly
if (image.sd_isVector) {
return nil;
}
#if SD_MAC #if SD_MAC
self = [super initWithCGImage:image.CGImage scale:MAX(scale, 1) orientation:kCGImagePropertyOrientationUp]; self = [super initWithCGImage:image.CGImage scale:MAX(scale, 1) orientation:kCGImagePropertyOrientationUp];
#else #else