Support loading animated images from the local filesystem

This commit is contained in:
Eric Jensen
2016-06-08 11:10:01 -07:00
parent cb67671f1d
commit 7de82b0b5b

View File

@@ -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<ASAnimatedImageProtocol> 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;