Remove the `SDWebImageForceTransitionAsync`, change the default behavior because it's most suitable for UI rendering and common use case. No need this hack. If user want, we may produce a `setTransitionBlock` in the future

This commit is contained in:
DreamPiggy 2020-08-27 10:49:57 +08:00
parent 6f61b7e37e
commit 2c9eaccf23
4 changed files with 17 additions and 27 deletions

View File

@ -47,7 +47,7 @@
self.imageView4.sd_imageTransition = SDWebImageTransition.fadeTransition;
self.imageView4.imageScaling = NSImageScaleProportionallyUpOrDown;
self.imageView4.imageAlignment = NSImageAlignLeft; // supports NSImageView's layout properties
[self.imageView4 sd_setImageWithURL:[NSURL URLWithString:@"http://littlesvr.ca/apng/images/SteamEngine.webp"] placeholderImage:nil options:SDWebImageForceTransition];
[self.imageView4 sd_setImageWithURL:[NSURL URLWithString:@"http://littlesvr.ca/apng/images/SteamEngine.webp"]];
NSMenu *menu2 = [[NSMenu alloc] initWithTitle:@"Toggle Animation"];
NSMenuItem *item2 = [menu2 addItemWithTitle:@"Toggle Animation" action:@selector(toggleAnimation:) keyEquivalent:@""];
item2.tag = 2;

View File

@ -160,8 +160,8 @@ typedef NS_OPTIONS(NSUInteger, SDWebImageOptions) {
SDWebImageFromLoaderOnly = 1 << 16,
/**
* 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 memory and disk cache as well.
* @note This options naming may be `SDWebImageForceTransitionAlways` in the furture. Which does not check any condition, just do transition even we query the cache immediately from memory. See related `SDWebImageForceTransitionAsync`.
* By default, when you use `SDWebImageTransition` to do some view transition after the image load finished, this transition is only applied for image when the callback from manager is asynchronous (from network, or disk cache query)
* This mask can force to apply view transition for any cases, like memory cache query, or sync disk cache query.
*/
SDWebImageForceTransition = 1 << 17,
@ -201,14 +201,7 @@ typedef NS_OPTIONS(NSUInteger, SDWebImageOptions) {
* We usually don't apply transform on vector images, because vector images supports dynamically changing to any size, rasterize to a fixed size will loss details. To modify vector images, you can process the vector data at runtime (such as modifying PDF tag / SVG element).
* Use this flag to transform them anyway.
*/
SDWebImageTransformVectorImage = 1 << 23,
/**
* 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 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
SDWebImageTransformVectorImage = 1 << 23
};

View File

@ -179,11 +179,10 @@ const int64_t SDWebImageProgressUnitCountUnknown = 1LL;
// Always
shouldUseTransition = YES;
} else if (cacheType == SDImageCacheTypeNone) {
// Default, from network
// From network
shouldUseTransition = YES;
} else {
// Async, from disk (and, user don't use sync query)
if (options & SDWebImageForceTransitionAsync) {
// From disk (and, user don't use sync query)
if (cacheType == SDImageCacheTypeMemory) {
shouldUseTransition = NO;
} else if (cacheType == SDImageCacheTypeDisk) {
@ -193,9 +192,7 @@ const int64_t SDWebImageProgressUnitCountUnknown = 1LL;
shouldUseTransition = YES;
}
} else {
shouldUseTransition = NO;
}
} else {
// Not valid cache type, fallback
shouldUseTransition = NO;
}
}

View File

@ -253,8 +253,8 @@
[self waitForExpectationsWithCommonTimeout];
}
- (void)testUIViewTransitionWork {
XCTestExpectation *expectation = [self expectationWithDescription:@"UIView transition does not work"];
- (void)testUIViewTransitionFromNetworkWork {
XCTestExpectation *expectation = [self expectationWithDescription:@"UIView transition from network does not work"];
// Attach a window, or CALayer will not submit drawing
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
@ -296,8 +296,8 @@
[self waitForExpectationsWithCommonTimeout];
}
- (void)testUIViewTransitionAsyncWork {
XCTestExpectation *expectation = [self expectationWithDescription:@"UIView transition async does not work"];
- (void)testUIViewTransitionFromDiskWork {
XCTestExpectation *expectation = [self expectationWithDescription:@"UIView transition from disk does not work"];
// Attach a window, or CALayer will not submit drawing
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
@ -323,7 +323,7 @@
__weak typeof(imageView) wimageView = imageView;
[imageView sd_setImageWithURL:originalImageURL
placeholderImage:placeholder
options:SDWebImageForceTransitionAsync | SDWebImageFromCacheOnly // Ensure we queired from disk cache
options: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];