Add a test case for autoPlayAnimatedImage

This commit is contained in:
刘立超 2020-05-08 23:43:41 +08:00
parent 26a765a71d
commit 992f231f15
2 changed files with 52 additions and 7 deletions

View File

@ -20,13 +20,6 @@
*/ */
@interface SDAnimatedImageView : UIImageView @interface SDAnimatedImageView : UIImageView
/**
If the image has more than one frame, set this value to `YES` will automatically
play/stop the animation when the view become visible/invisible.
The default value is `YES`.
*/
@property (nonatomic) BOOL autoPlayAnimatedImage;
/** /**
Current display frame image. This value is KVO Compliance. Current display frame image. This value is KVO Compliance.
*/ */
@ -88,6 +81,14 @@
*/ */
@property (nonatomic, assign) BOOL resetFrameIndexWhenStopped; @property (nonatomic, assign) BOOL resetFrameIndexWhenStopped;
/**
If the image has more than one frame, set this value to `YES` will automatically
play/stop the animation when the view become visible/invisible.
The default value is `YES`.
*/
@property (nonatomic) BOOL autoPlayAnimatedImage;
/** /**
You can specify a runloop mode to let it rendering. You can specify a runloop mode to let it rendering.
Default is NSRunLoopCommonModes on multi-core device, NSDefaultRunLoopMode on single-core device Default is NSRunLoopCommonModes on multi-core device, NSDefaultRunLoopMode on single-core device

View File

@ -468,6 +468,50 @@ static const NSUInteger kTestGIFFrameCount = 5; // local TestImage.gif loop coun
[self waitForExpectationsWithCommonTimeout]; [self waitForExpectationsWithCommonTimeout];
} }
- (void)test28AnimatedImageAutoPlayAnimatedImage {
XCTestExpectation *expectation = [self expectationWithDescription:@"test SDAnimatedImageView AutoPlayAnimatedImage behavior"];
SDAnimatedImageView *imageView = [SDAnimatedImageView new];
imageView.autoPlayAnimatedImage = NO;
#if SD_UIKIT
[self.window addSubview:imageView];
#else
[self.window.contentView addSubview:imageView];
#endif
// This APNG duration is 2s
SDAnimatedImage *image = [SDAnimatedImage imageWithData:[self testAPNGPData]];
imageView.image = image;
expect(imageView.animating).equal(0);
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
expect(imageView.animating).equal(0);
#if SD_UIKIT
[imageView startAnimating];
#else
imageView.animates = YES;
#endif
expect(imageView.animating).equal(1);
});
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
expect(imageView.animating).equal(1);
#if SD_UIKIT
[imageView stopAnimating];
#else
imageView.animates = NO;
#endif
[imageView removeFromSuperview];
[expectation fulfill];
});
[self waitForExpectationsWithCommonTimeout];
}
#pragma mark - Helper #pragma mark - Helper
- (UIWindow *)window { - (UIWindow *)window {
if (!_window) { if (!_window) {