Merge pull request #2531 from zhongwuzw/fix_reuse_wrong_image

Add image url check when set image
This commit is contained in:
Bogdan Poplauschi 2018-11-16 10:28:40 -06:00 committed by GitHub
commit 4fd0e83521
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 3 deletions

View File

@ -101,7 +101,7 @@ static char TAG_ACTIVITY_SHOW;
};
id <SDWebImageOperation> operation = [manager loadImageWithURL:url options:options progress:combinedProgressBlock completed:^(UIImage *image, NSData *data, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
__strong __typeof (wself) sself = wself;
if (!sself) { return; }
if (!sself || ![imageURL isEqual:sself.sd_imageURL]) { return; }
#if SD_UIKIT
[sself sd_removeActivityIndicator];
#endif
@ -114,9 +114,10 @@ static char TAG_ACTIVITY_SHOW;
BOOL shouldNotSetImage = ((image && (options & SDWebImageAvoidAutoSetImage)) ||
(!image && !(options & SDWebImageDelayPlaceholder)));
SDWebImageNoParamsBlock callCompletedBlockClojure = ^{
if (!sself) { return; }
__strong __typeof(wself) strongSelf = wself;
if (!strongSelf || ![strongSelf.sd_imageURL isEqual:imageURL]) { return; }
if (!shouldNotSetImage) {
[sself sd_setNeedsLayout];
[strongSelf sd_setNeedsLayout];
}
if (completedBlock && shouldCallCompletedBlock) {
completedBlock(image, error, cacheType, url);
@ -154,6 +155,7 @@ static char TAG_ACTIVITY_SHOW;
if (group) {
dispatch_group_enter(group);
}
if (![sself.sd_imageURL isEqual:imageURL]) { return ; }
#if SD_UIKIT || SD_MAC
[sself sd_setImage:targetImage imageData:targetData basedOnClassOrViaCustomSetImageBlock:setImageBlock transition:transition cacheType:cacheType imageURL:imageURL];
#else