Added the test case about the doing transition when async callback
This commit is contained in:
parent
df0f6008fc
commit
6f61b7e37e
|
@ -205,8 +205,8 @@ typedef NS_OPTIONS(NSUInteger, SDWebImageOptions) {
|
|||
|
||||
/**
|
||||
* By default, when you use `SDWebImageTransition` to do some view transition after the image load finished, this transition is only applied for image download from the network. This mask can force to apply view transition for condition when the callback from manager is asynchronous.
|
||||
* For example, when memory cache hit, or disk cache who using `queryDiskDataSync`, this will trigger transition. The default behavior (without any options) only do transition when network query successed.
|
||||
* @note This is used for UI rendering which relay the same runloop to avoid flashing, suitable for common use case cases. Which means, if user can see any waiting, do transition. else not.
|
||||
* For example, when disk cache hit (and you don't use `queryDiskDataSync`), this will trigger transition because disk query is asynchronous. The default behavior (without any options) only do transition when network query successed.
|
||||
* @note This is best used for UI rendering common cases, because even the cache is from disk, we may see a quick flashing of placeholder. In summary, if user can see any waiting (whether it takes 10 milliseconds or 10 minutes), do transition. else not.
|
||||
*/
|
||||
SDWebImageForceTransitionAsync = 1 << 24
|
||||
};
|
||||
|
|
|
@ -296,6 +296,50 @@
|
|||
[self waitForExpectationsWithCommonTimeout];
|
||||
}
|
||||
|
||||
- (void)testUIViewTransitionAsyncWork {
|
||||
XCTestExpectation *expectation = [self expectationWithDescription:@"UIView transition async does not work"];
|
||||
|
||||
// Attach a window, or CALayer will not submit drawing
|
||||
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
|
||||
imageView.sd_imageTransition = SDWebImageTransition.fadeTransition;
|
||||
imageView.sd_imageTransition.duration = 1;
|
||||
|
||||
#if SD_UIKIT
|
||||
[self.window addSubview:imageView];
|
||||
#else
|
||||
imageView.wantsLayer = YES;
|
||||
[self.window.contentView addSubview:imageView];
|
||||
#endif
|
||||
|
||||
NSData *imageData = [NSData dataWithContentsOfFile:[self testJPEGPath]];
|
||||
UIImage *placeholder = [[UIImage alloc] initWithData:imageData];
|
||||
|
||||
// Ensure the image is cached in disk but not memory
|
||||
[SDImageCache.sharedImageCache removeImageFromMemoryForKey:kTestJPEGURL];
|
||||
[SDImageCache.sharedImageCache removeImageFromDiskForKey:kTestJPEGURL];
|
||||
[SDImageCache.sharedImageCache storeImageDataToDisk:imageData forKey:kTestJPEGURL];
|
||||
|
||||
NSURL *originalImageURL = [NSURL URLWithString:kTestJPEGURL];
|
||||
__weak typeof(imageView) wimageView = imageView;
|
||||
[imageView sd_setImageWithURL:originalImageURL
|
||||
placeholderImage:placeholder
|
||||
options:SDWebImageForceTransitionAsync | SDWebImageFromCacheOnly // Ensure we queired from disk cache
|
||||
completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
|
||||
[SDImageCache.sharedImageCache removeImageFromMemoryForKey:kTestJPEGURL];
|
||||
[SDImageCache.sharedImageCache removeImageFromDiskForKey:kTestJPEGURL];
|
||||
__strong typeof(wimageView) simageView = imageView;
|
||||
// Delay to let CALayer commit the transition in next runloop
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, kMinDelayNanosecond), dispatch_get_main_queue(), ^{
|
||||
// Check current view contains layer animation
|
||||
NSArray *animationKeys = simageView.layer.animationKeys;
|
||||
expect(animationKeys.count).beGreaterThan(0);
|
||||
[expectation fulfill];
|
||||
});
|
||||
}];
|
||||
|
||||
[self waitForExpectationsWithCommonTimeout];
|
||||
}
|
||||
|
||||
- (void)testUIViewIndicatorWork {
|
||||
XCTestExpectation *expectation = [self expectationWithDescription:@"UIView indicator does not work"];
|
||||
|
||||
|
|
Loading…
Reference in New Issue