Skip to content

Commit

Permalink
Add a new networking image delegate method when a network image node …
Browse files Browse the repository at this point in the history
…failed to load from cache (#1590)
  • Loading branch information
ernestmama authored and nguyenhuy committed Jul 19, 2019
1 parent b038299 commit 9c537ea
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
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 failed to load image from cache
*
* @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

0 comments on commit 9c537ea

Please sign in to comment.