From a6a8308c15d73a8b9f3164affea8ff075da6bbe7 Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Thu, 16 Aug 2018 11:32:12 +0800 Subject: [PATCH] Change the View Category setImageBlock with all args like View Transition or CompletedBlock, to make it useful for advanced usage --- SDWebImage/MapKit/MKAnnotationView+WebCache.m | 2 +- SDWebImage/NSButton+WebCache.m | 2 +- SDWebImage/UIButton+WebCache.m | 4 ++-- SDWebImage/UIImageView+HighlightedWebCache.m | 2 +- SDWebImage/UIView+WebCache.h | 2 +- SDWebImage/UIView+WebCache.m | 22 +++++++++---------- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/SDWebImage/MapKit/MKAnnotationView+WebCache.m b/SDWebImage/MapKit/MKAnnotationView+WebCache.m index 15bb528d..a6721a9e 100644 --- a/SDWebImage/MapKit/MKAnnotationView+WebCache.m +++ b/SDWebImage/MapKit/MKAnnotationView+WebCache.m @@ -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 diff --git a/SDWebImage/NSButton+WebCache.m b/SDWebImage/NSButton+WebCache.m index e7f74844..74383054 100644 --- a/SDWebImage/NSButton+WebCache.m +++ b/SDWebImage/NSButton+WebCache.m @@ -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 diff --git a/SDWebImage/UIButton+WebCache.m b/SDWebImage/UIButton+WebCache.m index 8da05c77..54034780 100644 --- a/SDWebImage/UIButton+WebCache.m +++ b/SDWebImage/UIButton+WebCache.m @@ -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 diff --git a/SDWebImage/UIImageView+HighlightedWebCache.m b/SDWebImage/UIImageView+HighlightedWebCache.m index a8803aa3..6560f46f 100644 --- a/SDWebImage/UIImageView+HighlightedWebCache.m +++ b/SDWebImage/UIImageView+HighlightedWebCache.m @@ -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 diff --git a/SDWebImage/UIView+WebCache.h b/SDWebImage/UIView+WebCache.h index 10a383d3..42d83054 100644 --- a/SDWebImage/UIView+WebCache.h +++ b/SDWebImage/UIView+WebCache.h @@ -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) diff --git a/SDWebImage/UIView+WebCache.m b/SDWebImage/UIView+WebCache.m index 34367b1b..69ef9b27 100644 --- a/SDWebImage/UIView+WebCache.m +++ b/SDWebImage/UIView+WebCache.m @@ -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); } } }