From 7de82b0b5b170c7c6a986cfd01e587ae29c9e882 Mon Sep 17 00:00:00 2001 From: Eric Jensen Date: Wed, 8 Jun 2016 11:10:01 -0700 Subject: [PATCH] Support loading animated images from the local filesystem --- AsyncDisplayKit/ASNetworkImageNode.mm | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/AsyncDisplayKit/ASNetworkImageNode.mm b/AsyncDisplayKit/ASNetworkImageNode.mm index b9f6514fb7..e24e380868 100755 --- a/AsyncDisplayKit/ASNetworkImageNode.mm +++ b/AsyncDisplayKit/ASNetworkImageNode.mm @@ -457,15 +457,27 @@ 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) { + NSData *data = [NSData dataWithContentsOfURL:_URL]; + if (data == 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) { + data = [NSData dataWithContentsOfFile:filename]; } } + + // If the file may be an animated gif and then created an animated image. + id animatedImage = nil; + if (_downloaderImplementsAnimatedImage && data != nil && [_URL.pathExtension isEqualToString:@"gif"]) { + animatedImage = [_downloader animatedImageWithData:data]; + } + + if (animatedImage != nil) { + self.animatedImage = animatedImage; + } else { + self.image = [UIImage imageWithData:data]; + } } _imageLoaded = YES;