[ASMultiplexImageNode] Copy recent changes made to ASNetworkImageNode for progress image handling

This commit is contained in:
Adlai Holler
2016-04-12 14:34:11 -07:00
parent 362c41ae80
commit 0022cad000
2 changed files with 33 additions and 29 deletions

View File

@@ -22,6 +22,7 @@
#import "ASPhotosFrameworkImageRequest.h"
#import "ASEqualityHelpers.h"
#import "ASInternalHelpers.h"
#import "ASDisplayNodeExtras.h"
#if !AS_IOS8_SDK_OR_LATER
#error ASMultiplexImageNode can be used on iOS 7, but must be linked against the iOS 8 SDK.
@@ -293,9 +294,8 @@ typedef void(^ASMultiplexImageLoadCompletionBlock)(UIImage *image, id imageIdent
- (void)visibilityDidChange:(BOOL)isVisible
{
[super visibilityDidChange:isVisible];
if (_downloaderImplementsSetPriority) {
ASDN::MutexLocker l(_downloadIdentifierLock);
if (_downloaderImplementsSetPriority) {
if (_downloadIdentifier != nil) {
if (isVisible) {
[_downloader setPriority:ASImageDownloaderPriorityVisible withDownloadIdentifier:_downloadIdentifier];
@@ -305,32 +305,7 @@ typedef void(^ASMultiplexImageLoadCompletionBlock)(UIImage *image, id imageIdent
}
}
if (_downloaderImplementsSetProgress) {
ASDN::MutexLocker l(_downloadIdentifierLock);
if (_downloadIdentifier != nil) {
__weak __typeof__(self) weakSelf = self;
ASImageDownloaderProgressImage progress = nil;
if (isVisible) {
progress = ^(UIImage * _Nonnull progressImage, id _Nullable downloadIdentifier) {
__typeof__(self) strongSelf = weakSelf;
if (strongSelf == nil) {
return;
}
ASDN::MutexLocker l(strongSelf->_downloadIdentifierLock);
//Getting a result back for a different download identifier, download must not have been successfully canceled
if (ASObjectIsEqual(strongSelf->_downloadIdentifier, downloadIdentifier) == NO && downloadIdentifier != nil) {
return;
}
strongSelf.image = progressImage;
};
}
[_downloader setProgressImageBlock:progress callbackQueue:dispatch_get_main_queue() withDownloadIdentifier:_downloadIdentifier];
}
}
[self _updateProgressImageBlockOnDownloaderIfNeeded];
}
#pragma mark - Core
@@ -478,6 +453,33 @@ typedef void(^ASMultiplexImageLoadCompletionBlock)(UIImage *image, id imageIdent
}
#pragma mark -
- (void)_updateProgressImageBlockOnDownloaderIfNeeded
{
if (!_downloaderImplementsSetProgress || _downloadIdentifier == nil) {
return;
}
ASImageDownloaderProgressImage progress = nil;
if (ASInterfaceStateIncludesVisible(self.interfaceState)) {
__weak __typeof__(self) weakSelf = self;
progress = ^(UIImage * _Nonnull progressImage, id _Nullable downloadIdentifier) {
__typeof__(self) strongSelf = weakSelf;
if (strongSelf == nil) {
return;
}
ASDN::MutexLocker l(strongSelf->_downloadIdentifierLock);
//Getting a result back for a different download identifier, download must not have been successfully canceled
if (ASObjectIsEqual(strongSelf->_downloadIdentifier, downloadIdentifier) == NO && downloadIdentifier != nil) {
return;
}
strongSelf.image = progressImage;
};
}
[_downloader setProgressImageBlock:progress callbackQueue:dispatch_get_main_queue() withDownloadIdentifier:_downloadIdentifier];
}
- (void)_clearImage
{
// Destruction of bigger images on the main thread can be expensive
@@ -823,6 +825,7 @@ typedef void(^ASMultiplexImageLoadCompletionBlock)(UIImage *image, id imageIdent
}]];
#pragma clang diagnostic pop
}
[self _updateProgressImageBlockOnDownloaderIfNeeded];
});
}

View File

@@ -212,6 +212,7 @@ static const CGSize kMinReleaseImageOnBackgroundSize = {20.0, 20.0};
- (void)visibilityDidChange:(BOOL)isVisible
{
[super visibilityDidChange:isVisible];
ASDN::MutexLocker l(_lock);
if (_downloaderImplementsSetPriority) {
if (_downloadIdentifier != nil) {
@@ -388,7 +389,7 @@ static const CGSize kMinReleaseImageOnBackgroundSize = {20.0, 20.0};
ASDN::MutexLocker l(strongSelf->_lock);
//Getting a result back for a different download identifier, download must not have been successfully canceled
if (downloadIdentifier != nil && !ASObjectIsEqual(strongSelf->_downloadIdentifier, downloadIdentifier)) {
if (ASObjectIsEqual(strongSelf->_downloadIdentifier, downloadIdentifier) == NO && downloadIdentifier != nil) {
return;
}