Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add new networking image delegate method when image does not load from cache #1590

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Source/ASNetworkImageNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,15 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (void)imageNodeDidLoadImageFromCache:(ASNetworkImageNode *)imageNode;

/**
* Notification that the image node is not able to load image from cache
ernestmama marked this conversation as resolved.
Show resolved Hide resolved
*
* @param imageNode The sender.
*
* @discussion Called on the main thread.
*/
- (void)imageNodeDidFailToLoadImageFromCache:(ASNetworkImageNode *)imageNode;

/**
* Notification that the image node will load image from network
*
Expand Down
6 changes: 6 additions & 0 deletions Source/ASNetworkImageNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ @interface ASNetworkImageNode ()
unsigned int delegateDidLoadImage:1;
unsigned int delegateDidLoadImageFromCache:1;
unsigned int delegateDidLoadImageWithInfo:1;
unsigned int delegateDidFailToLoadImageFromCache:1;

unsigned int downloaderImplementsSetProgress:1;
unsigned int downloaderImplementsSetPriority:1;
Expand Down Expand Up @@ -298,6 +299,7 @@ - (void)setDelegate:(id<ASNetworkImageNodeDelegate>)delegate
_networkImageNodeFlags.delegateDidLoadImage = [delegate respondsToSelector:@selector(imageNode:didLoadImage:)];
_networkImageNodeFlags.delegateDidLoadImageFromCache = [delegate respondsToSelector:@selector(imageNodeDidLoadImageFromCache:)];
_networkImageNodeFlags.delegateDidLoadImageWithInfo = [delegate respondsToSelector:@selector(imageNode:didLoadImage:info:)];
_networkImageNodeFlags.delegateDidFailToLoadImageFromCache = [delegate respondsToSelector:@selector(imageNodeDidFailToLoadImageFromCache:)];
}

- (id<ASNetworkImageNodeDelegate>)delegate
Expand Down Expand Up @@ -665,6 +667,7 @@ - (void)_lazilyLoadImageIfNecessary
BOOL delegateWillLoadImageFromCache = _networkImageNodeFlags.delegateWillLoadImageFromCache;
BOOL delegateWillLoadImageFromNetwork = _networkImageNodeFlags.delegateWillLoadImageFromNetwork;
BOOL delegateDidLoadImageFromCache = _networkImageNodeFlags.delegateDidLoadImageFromCache;
BOOL delegateDidFailToLoadImageFromCache = _networkImageNodeFlags.delegateDidFailToLoadImageFromCache;
BOOL isImageLoaded = _networkImageNodeFlags.imageLoaded;
__block NSURL *URL = _URL;
id currentDownloadIdentifier = _downloadIdentifier;
Expand Down Expand Up @@ -824,6 +827,9 @@ - (void)_lazilyLoadImageIfNecessary
}

if ([imageContainer asdk_image] == nil && [imageContainer asdk_animatedImageData] == nil && self->_downloader != nil) {
if (delegateDidFailToLoadImageFromCache) {
[delegate imageNodeDidFailToLoadImageFromCache:self];
}
if (delegateWillLoadImageFromNetwork) {
[delegate imageNodeWillLoadImageFromNetwork:self];
}
Expand Down