Add support for SDAnimatedImage imageNamed:bundle: for macOS, enable SDAnimatedImageTest for macOS
This commit is contained in:
parent
d19311e08c
commit
dd2e71c99d
|
@ -54,6 +54,8 @@
|
|||
+ (nullable instancetype)imageNamed:(nonnull NSString *)name; // Cache in memory, no Asset Catalog support
|
||||
#if __has_include(<UIKit/UITraitCollection.h>)
|
||||
+ (nullable instancetype)imageNamed:(nonnull NSString *)name inBundle:(nullable NSBundle *)bundle compatibleWithTraitCollection:(nullable UITraitCollection *)traitCollection; // Cache in memory, no Asset Catalog support
|
||||
#else
|
||||
+ (nullable instancetype)imageNamed:(nonnull NSString *)name inBundle:(nullable NSBundle *)bundle; // Cache in memory, no Asset Catalog support
|
||||
#endif
|
||||
+ (nullable instancetype)imageWithContentsOfFile:(nonnull NSString *)path;
|
||||
+ (nullable instancetype)imageWithData:(nonnull NSData *)data;
|
||||
|
|
|
@ -212,7 +212,7 @@ static NSArray *SDBundlePreferredScales() {
|
|||
#if __has_include(<UIKit/UITraitCollection.h>)
|
||||
return [self imageNamed:name inBundle:nil compatibleWithTraitCollection:nil];
|
||||
#else
|
||||
return [self imageNamed:name inBundle:nil scale:0];
|
||||
return [self imageNamed:name inBundle:nil];
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -224,6 +224,10 @@ static NSArray *SDBundlePreferredScales() {
|
|||
CGFloat scale = traitCollection.displayScale;
|
||||
return [self imageNamed:name inBundle:bundle scale:scale];
|
||||
}
|
||||
#else
|
||||
+ (instancetype)imageNamed:(NSString *)name inBundle:(NSBundle *)bundle {
|
||||
return [self imageNamed:name inBundle:bundle scale:0];
|
||||
}
|
||||
#endif
|
||||
|
||||
// 0 scale means automatically check
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
0314594336AFF15E5BB7F0E6 /* Pods_Tests_Mac.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C140E5ED8501C2ABBFD97A24 /* Pods_Tests_Mac.framework */; };
|
||||
1E3C51E919B46E370092B5E6 /* SDWebImageDownloaderTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 1E3C51E819B46E370092B5E6 /* SDWebImageDownloaderTests.m */; };
|
||||
2D7AF0601F329763000083C2 /* SDTestCase.m in Sources */ = {isa = PBXBuildFile; fileRef = 2D7AF05F1F329763000083C2 /* SDTestCase.m */; };
|
||||
320630412085A37C006E0FA4 /* SDAnimatedImageTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 32A571552037DB2D002EDAAE /* SDAnimatedImageTest.m */; };
|
||||
321259EC1F39E3240096FE0E /* TestImageStatic.webp in Resources */ = {isa = PBXBuildFile; fileRef = 321259EB1F39E3240096FE0E /* TestImageStatic.webp */; };
|
||||
321259EE1F39E4110096FE0E /* TestImageAnimated.webp in Resources */ = {isa = PBXBuildFile; fileRef = 321259ED1F39E4110096FE0E /* TestImageAnimated.webp */; };
|
||||
3226ECBB20754F7700FAFACF /* SDWebImageTestDownloadOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = 3226ECBA20754F7700FAFACF /* SDWebImageTestDownloadOperation.m */; };
|
||||
|
@ -474,6 +475,7 @@
|
|||
32B99EAB203B36620017FD66 /* SDWebImageManagerTests.m in Sources */,
|
||||
32B99EA9203B34B60017FD66 /* SDWebImageDecoderTests.m in Sources */,
|
||||
3264FF30205D42CB00F6BD48 /* SDWebImageTestTransformer.m in Sources */,
|
||||
320630412085A37C006E0FA4 /* SDAnimatedImageTest.m in Sources */,
|
||||
32B99E9B203B2EDD0017FD66 /* SDTestCase.m in Sources */,
|
||||
3226ECBC20754F7700FAFACF /* SDWebImageTestDownloadOperation.m in Sources */,
|
||||
);
|
||||
|
|
|
@ -15,6 +15,11 @@
|
|||
#import <SDWebImage/SDAnimatedImageView+WebCache.h>
|
||||
#import <KVOController/KVOController.h>
|
||||
|
||||
#if SD_MAC
|
||||
#define UIWindow NSWindow
|
||||
#define UIScreen NSScreen
|
||||
#endif
|
||||
|
||||
static const NSUInteger kTestGIFFrameCount = 5; // local TestImage.gif loop count
|
||||
|
||||
// Internal header
|
||||
|
@ -69,7 +74,12 @@ static const NSUInteger kTestGIFFrameCount = 5; // local TestImage.gif loop coun
|
|||
}
|
||||
|
||||
- (void)test04AnimatedImageImageNamed {
|
||||
SDAnimatedImage *image = [SDAnimatedImage imageNamed:@"TestImage.gif" inBundle:[NSBundle bundleForClass:[self class]] compatibleWithTraitCollection:nil];
|
||||
NSBundle *bundle = [NSBundle bundleForClass:[self class]];
|
||||
#if SD_UIKIT
|
||||
SDAnimatedImage *image = [SDAnimatedImage imageNamed:@"TestImage.gif" inBundle:bundle compatibleWithTraitCollection:nil];
|
||||
#else
|
||||
SDAnimatedImage *image = [SDAnimatedImage imageNamed:@"TestImage.gif" inBundle:bundle];
|
||||
#endif
|
||||
expect(image).notTo.beNil();
|
||||
expect([image.animatedImageData isEqualToData:[self testGIFData]]).beTruthy();
|
||||
}
|
||||
|
@ -91,7 +101,7 @@ static const NSUInteger kTestGIFFrameCount = 5; // local TestImage.gif loop coun
|
|||
|
||||
- (void)test06AnimatedImageViewSetImage {
|
||||
SDAnimatedImageView *imageView = [SDAnimatedImageView new];
|
||||
UIImage *image = [UIImage imageWithData:[self testJPEGData]];
|
||||
UIImage *image = [[UIImage alloc] initWithData:[self testJPEGData]];
|
||||
imageView.image = image;
|
||||
expect(imageView.image).notTo.beNil();
|
||||
expect(imageView.currentFrame).beNil(); // current frame
|
||||
|
@ -108,7 +118,11 @@ static const NSUInteger kTestGIFFrameCount = 5; // local TestImage.gif loop coun
|
|||
- (void)test08AnimatedImageViewRendering {
|
||||
XCTestExpectation *expectation = [self expectationWithDescription:@"test SDAnimatedImageView rendering"];
|
||||
SDAnimatedImageView *imageView = [[SDAnimatedImageView alloc] init];
|
||||
#if SD_UIKIT
|
||||
[self.window addSubview:imageView];
|
||||
#else
|
||||
[self.window.contentView addSubview:imageView];
|
||||
#endif
|
||||
|
||||
NSMutableDictionary *frames = [NSMutableDictionary dictionaryWithCapacity:kTestGIFFrameCount];
|
||||
|
||||
|
@ -128,7 +142,11 @@ static const NSUInteger kTestGIFFrameCount = 5; // local TestImage.gif loop coun
|
|||
loopFinished = YES;
|
||||
}
|
||||
if (framesRendered && loopFinished) {
|
||||
#if SD_UIKIT
|
||||
[imageView stopAnimating];
|
||||
#else
|
||||
imageView.animates = NO;
|
||||
#endif
|
||||
[expectation fulfill];
|
||||
}
|
||||
}];
|
||||
|
@ -205,7 +223,12 @@ static const NSUInteger kTestGIFFrameCount = 5; // local TestImage.gif loop coun
|
|||
#pragma mark - Helper
|
||||
- (UIWindow *)window {
|
||||
if (!_window) {
|
||||
_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
|
||||
UIScreen *mainScreen = [UIScreen mainScreen];
|
||||
#if SD_UIKIT
|
||||
_window = [[UIWindow alloc] initWithFrame:mainScreen.bounds];
|
||||
#else
|
||||
_window = [[NSWindow alloc] initWithContentRect:mainScreen.frame styleMask:0 backing:NSBackingStoreBuffered defer:NO screen:mainScreen];
|
||||
#endif
|
||||
}
|
||||
return _window;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue