Merge pull request #2449 from dreampiggy/feature_set_image_block_extra_args
Feature set image block extra args
This commit is contained in:
commit
2bb336bc12
|
@ -59,7 +59,7 @@
|
|||
placeholderImage:placeholder
|
||||
options:options
|
||||
context:context
|
||||
setImageBlock:^(UIImage *image, NSData *imageData) {
|
||||
setImageBlock:^(UIImage * _Nullable image, NSData * _Nullable imageData, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
|
||||
weakSelf.image = image;
|
||||
}
|
||||
progress:progressBlock
|
||||
|
|
|
@ -126,7 +126,7 @@ static NSString * const SDAlternateImageOperationKey = @"NSButtonAlternateImageO
|
|||
placeholderImage:placeholder
|
||||
options:options
|
||||
context:mutableContext
|
||||
setImageBlock:^(NSImage * _Nullable image, NSData * _Nullable imageData) {
|
||||
setImageBlock:^(NSImage * _Nullable image, NSData * _Nullable imageData, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
|
||||
weakSelf.alternateImage = image;
|
||||
}
|
||||
progress:progressBlock
|
||||
|
|
|
@ -109,7 +109,7 @@ static inline NSString * backgroundImageOperationKeyForState(UIControlState stat
|
|||
placeholderImage:placeholder
|
||||
options:options
|
||||
context:mutableContext
|
||||
setImageBlock:^(UIImage *image, NSData *imageData) {
|
||||
setImageBlock:^(UIImage * _Nullable image, NSData * _Nullable imageData, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
|
||||
[weakSelf setImage:image forState:state];
|
||||
}
|
||||
progress:progressBlock
|
||||
|
@ -193,7 +193,7 @@ static inline NSString * backgroundImageOperationKeyForState(UIControlState stat
|
|||
placeholderImage:placeholder
|
||||
options:options
|
||||
context:mutableContext
|
||||
setImageBlock:^(UIImage *image, NSData *imageData) {
|
||||
setImageBlock:^(UIImage * _Nullable image, NSData * _Nullable imageData, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
|
||||
[weakSelf setBackgroundImage:image forState:state];
|
||||
}
|
||||
progress:progressBlock
|
||||
|
|
|
@ -58,7 +58,7 @@ static NSString * const SDHighlightedImageOperationKey = @"UIImageViewImageOpera
|
|||
placeholderImage:nil
|
||||
options:options
|
||||
context:mutableContext
|
||||
setImageBlock:^(UIImage *image, NSData *imageData) {
|
||||
setImageBlock:^(UIImage * _Nullable image, NSData * _Nullable imageData, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
|
||||
weakSelf.highlightedImage = image;
|
||||
}
|
||||
progress:progressBlock
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
*/
|
||||
FOUNDATION_EXPORT const int64_t SDWebImageProgressUnitCountUnknown; /* 1LL */
|
||||
|
||||
typedef void(^SDSetImageBlock)(UIImage * _Nullable image, NSData * _Nullable imageData);
|
||||
typedef void(^SDSetImageBlock)(UIImage * _Nullable image, NSData * _Nullable imageData, SDImageCacheType cacheType, NSURL * _Nullable imageURL);
|
||||
|
||||
@interface UIView (WebCache)
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ const int64_t SDWebImageProgressUnitCountUnknown = 1LL;
|
|||
|
||||
if (!(options & SDWebImageDelayPlaceholder)) {
|
||||
dispatch_main_async_safe(^{
|
||||
[self sd_setImage:placeholder imageData:nil basedOnClassOrViaCustomSetImageBlock:setImageBlock];
|
||||
[self sd_setImage:placeholder imageData:nil basedOnClassOrViaCustomSetImageBlock:setImageBlock cacheType:SDImageCacheTypeNone imageURL:url];
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -151,7 +151,7 @@ const int64_t SDWebImageProgressUnitCountUnknown = 1LL;
|
|||
#if SD_UIKIT || SD_MAC
|
||||
[sself sd_setImage:targetImage imageData:targetData basedOnClassOrViaCustomSetImageBlock:setImageBlock transition:transition cacheType:cacheType imageURL:imageURL];
|
||||
#else
|
||||
[sself sd_setImage:targetImage imageData:targetData basedOnClassOrViaCustomSetImageBlock:setImageBlock];
|
||||
[sself sd_setImage:targetImage imageData:targetData basedOnClassOrViaCustomSetImageBlock:setImageBlock cacheType:cacheType imageURL:imageURL];
|
||||
#endif
|
||||
callCompletedBlockClojure();
|
||||
});
|
||||
|
@ -174,13 +174,13 @@ const int64_t SDWebImageProgressUnitCountUnknown = 1LL;
|
|||
[self sd_cancelImageLoadOperationWithKey:NSStringFromClass([self class])];
|
||||
}
|
||||
|
||||
- (void)sd_setImage:(UIImage *)image imageData:(NSData *)imageData basedOnClassOrViaCustomSetImageBlock:(SDSetImageBlock)setImageBlock {
|
||||
- (void)sd_setImage:(UIImage *)image imageData:(NSData *)imageData basedOnClassOrViaCustomSetImageBlock:(SDSetImageBlock)setImageBlock cacheType:(SDImageCacheType)cacheType imageURL:(NSURL *)imageURL {
|
||||
#if SD_UIKIT || SD_MAC
|
||||
[self sd_setImage:image imageData:imageData basedOnClassOrViaCustomSetImageBlock:setImageBlock transition:nil cacheType:0 imageURL:nil];
|
||||
[self sd_setImage:image imageData:imageData basedOnClassOrViaCustomSetImageBlock:setImageBlock transition:nil cacheType:cacheType imageURL:imageURL];
|
||||
#else
|
||||
// watchOS does not support view transition. Simplify the logic
|
||||
if (setImageBlock) {
|
||||
setImageBlock(image, imageData);
|
||||
setImageBlock(image, imageData, cacheType, imageURL);
|
||||
} else if ([self isKindOfClass:[UIImageView class]]) {
|
||||
UIImageView *imageView = (UIImageView *)self;
|
||||
[imageView setImage:image];
|
||||
|
@ -196,14 +196,14 @@ const int64_t SDWebImageProgressUnitCountUnknown = 1LL;
|
|||
finalSetImageBlock = setImageBlock;
|
||||
} else if ([view isKindOfClass:[UIImageView class]]) {
|
||||
UIImageView *imageView = (UIImageView *)view;
|
||||
finalSetImageBlock = ^(UIImage *setImage, NSData *setImageData) {
|
||||
finalSetImageBlock = ^(UIImage *setImage, NSData *setImageData, SDImageCacheType setCacheType, NSURL *setImageURL) {
|
||||
imageView.image = setImage;
|
||||
};
|
||||
}
|
||||
#if SD_UIKIT
|
||||
else if ([view isKindOfClass:[UIButton class]]) {
|
||||
UIButton *button = (UIButton *)view;
|
||||
finalSetImageBlock = ^(UIImage *setImage, NSData *setImageData){
|
||||
finalSetImageBlock = ^(UIImage *setImage, NSData *setImageData, SDImageCacheType setCacheType, NSURL *setImageURL) {
|
||||
[button setImage:setImage forState:UIControlStateNormal];
|
||||
};
|
||||
}
|
||||
|
@ -211,7 +211,7 @@ const int64_t SDWebImageProgressUnitCountUnknown = 1LL;
|
|||
#if SD_MAC
|
||||
else if ([view isKindOfClass:[NSButton class]]) {
|
||||
NSButton *button = (NSButton *)view;
|
||||
finalSetImageBlock = ^(UIImage *setImage, NSData *setImageData){
|
||||
finalSetImageBlock = ^(UIImage *setImage, NSData *setImageData, SDImageCacheType setCacheType, NSURL *setImageURL) {
|
||||
button.image = setImage;
|
||||
};
|
||||
}
|
||||
|
@ -227,7 +227,7 @@ const int64_t SDWebImageProgressUnitCountUnknown = 1LL;
|
|||
} completion:^(BOOL finished) {
|
||||
[UIView transitionWithView:view duration:transition.duration options:transition.animationOptions animations:^{
|
||||
if (finalSetImageBlock && !transition.avoidAutoSetImage) {
|
||||
finalSetImageBlock(image, imageData);
|
||||
finalSetImageBlock(image, imageData, cacheType, imageURL);
|
||||
}
|
||||
if (transition.animations) {
|
||||
transition.animations(view, image);
|
||||
|
@ -247,7 +247,7 @@ const int64_t SDWebImageProgressUnitCountUnknown = 1LL;
|
|||
context.timingFunction = transition.timingFunction;
|
||||
context.allowsImplicitAnimation = (transition.animationOptions & SDWebImageAnimationOptionAllowsImplicitAnimation);
|
||||
if (finalSetImageBlock && !transition.avoidAutoSetImage) {
|
||||
finalSetImageBlock(image, imageData);
|
||||
finalSetImageBlock(image, imageData, cacheType, imageURL);
|
||||
}
|
||||
if (transition.animations) {
|
||||
transition.animations(view, image);
|
||||
|
@ -261,7 +261,7 @@ const int64_t SDWebImageProgressUnitCountUnknown = 1LL;
|
|||
#endif
|
||||
} else {
|
||||
if (finalSetImageBlock) {
|
||||
finalSetImageBlock(image, imageData);
|
||||
finalSetImageBlock(image, imageData, cacheType, imageURL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -155,6 +155,40 @@
|
|||
}
|
||||
#endif
|
||||
|
||||
- (void)testUIViewInternalSetImageWithURL {
|
||||
XCTestExpectation *expectation = [self expectationWithDescription:@"UIView internalSetImageWithURL"];
|
||||
|
||||
UIView *view = [[UIView alloc] init];
|
||||
#if SD_MAC
|
||||
view.wantsLayer = YES;
|
||||
#endif
|
||||
NSURL *originalImageURL = [NSURL URLWithString:kTestJPEGURL];
|
||||
UIImage *placeholder = [[UIImage alloc] initWithContentsOfFile:[self testJPEGPath]];
|
||||
[view sd_internalSetImageWithURL:originalImageURL
|
||||
placeholderImage:placeholder
|
||||
options:0
|
||||
context:nil
|
||||
setImageBlock:^(UIImage * _Nullable image, NSData * _Nullable imageData, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
|
||||
if (!imageData && cacheType == SDImageCacheTypeNone) {
|
||||
// placeholder
|
||||
expect(image).to.equal(placeholder);
|
||||
} else {
|
||||
// cache or download
|
||||
expect(image).toNot.beNil();
|
||||
}
|
||||
view.layer.contents = (__bridge id _Nullable)(image.CGImage);
|
||||
}
|
||||
progress:nil
|
||||
completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, SDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) {
|
||||
expect(image).toNot.beNil();
|
||||
expect(error).to.beNil();
|
||||
expect(originalImageURL).to.equal(imageURL);
|
||||
expect((__bridge CGImageRef)view.layer.contents == image.CGImage).to.beTruthy();
|
||||
[expectation fulfill];
|
||||
}];
|
||||
[self waitForExpectationsWithCommonTimeout];
|
||||
}
|
||||
|
||||
- (void)testUIViewImageProgressKVOWork {
|
||||
XCTestExpectation *expectation = [self expectationWithDescription:@"UIView imageProgressKVO failed"];
|
||||
UIView *view = [[UIView alloc] init];
|
||||
|
|
Loading…
Reference in New Issue