diff --git a/AsyncDisplayKit/ASNetworkImageNode.mm b/AsyncDisplayKit/ASNetworkImageNode.mm index b9f6514fb7..eaf9882f5e 100755 --- a/AsyncDisplayKit/ASNetworkImageNode.mm +++ b/AsyncDisplayKit/ASNetworkImageNode.mm @@ -457,15 +457,32 @@ static const CGSize kMinReleaseImageOnBackgroundSize = {20.0, 20.0}; } else { // First try to load the path directly, for efficiency assuming a developer who // doesn't want caching is trying to be as minimal as possible. - self.image = [UIImage imageWithContentsOfFile:_URL.path]; - if (!self.image) { + UIImage *nonAnimatedImage = [UIImage imageWithContentsOfFile:_URL.path]; + if (nonAnimatedImage == nil) { // If we couldn't find it, execute an -imageNamed:-like search so we can find resources even if the // extension is not provided in the path. This allows the same path to work regardless of shouldCacheImage. NSString *filename = [[NSBundle mainBundle] pathForResource:_URL.path.lastPathComponent ofType:nil]; - if (filename) { - self.image = [UIImage imageWithContentsOfFile:filename]; + if (filename != nil) { + nonAnimatedImage = [UIImage imageWithContentsOfFile:filename]; } } + + // If the file may be an animated gif and then created an animated image. + id animatedImage = nil; + if (_downloaderImplementsAnimatedImage) { + NSData *data = [NSData dataWithContentsOfURL:_URL]; + animatedImage = [_downloader animatedImageWithData:data]; + + if ([animatedImage respondsToSelector:@selector(isDataSupported:)] && [animatedImage isDataSupported:data] == NO) { + animatedImage = nil; + } + } + + if (animatedImage != nil) { + self.animatedImage = animatedImage; + } else { + self.image = nonAnimatedImage; + } } _imageLoaded = YES; diff --git a/AsyncDisplayKit/Details/ASImageProtocols.h b/AsyncDisplayKit/Details/ASImageProtocols.h index ff6803bd8d..f7f8337a6b 100644 --- a/AsyncDisplayKit/Details/ASImageProtocols.h +++ b/AsyncDisplayKit/Details/ASImageProtocols.h @@ -142,12 +142,21 @@ withDownloadIdentifier:(id)downloadIdentifier; @protocol ASAnimatedImageProtocol +@optional + /** @abstract Should be called when the objects cover image is ready. @param coverImageReadyCallback a block which receives the cover image. */ @property (nonatomic, strong, readwrite) void (^coverImageReadyCallback)(UIImage *coverImage); +/** + @abstract Returns whether the supplied data contains a supported animated image format. + @param data the data to check if contains a supported animated image. + */ +- (BOOL)isDataSupported:(NSData *)data; + + @required /** diff --git a/AsyncDisplayKit/Details/ASPINRemoteImageDownloader.m b/AsyncDisplayKit/Details/ASPINRemoteImageDownloader.m index 4ace07c87b..6eea964b34 100644 --- a/AsyncDisplayKit/Details/ASPINRemoteImageDownloader.m +++ b/AsyncDisplayKit/Details/ASPINRemoteImageDownloader.m @@ -56,6 +56,11 @@ return self.fileReady; } +- (BOOL)isDataSupported:(NSData *)data +{ + return [data pin_isGIF]; +} + @end #endif