Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.

Commit 4c4f0c8

Browse files
committed
Merge pull request #1006 from facebook/ASNetworkImageFileURLs
[ASNetworkImageNode] Improve handling of file URLs for images.
2 parents 9264496 + b75b72c commit 4c4f0c8

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

AsyncDisplayKit/ASNetworkImageNode.mm

100644100755
Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,14 +188,23 @@ - (void)_lazilyLoadImageIfNecessary
188188
ASDN::MutexLocker l(_lock);
189189

190190
dispatch_async(dispatch_get_main_queue(), ^{
191-
_imageLoaded = YES;
192-
193191
if (self.shouldCacheImage) {
194-
self.image = [UIImage imageNamed:_URL.path];
192+
self.image = [UIImage imageNamed:_URL.path.lastPathComponent];
195193
} else {
194+
// First try to load the path directly, for efficiency assuming a developer who
195+
// doesn't want caching is trying to be as minimal as possible.
196196
self.image = [UIImage imageWithContentsOfFile:_URL.path];
197+
if (!self.image) {
198+
// If we couldn't find it, execute an -imageNamed:-like search so we can find resources even if the
199+
// extension is not provided in the path. This allows the same path to work regardless of shouldCacheImage.
200+
NSString *filename = [[NSBundle mainBundle] pathForResource:_URL.path.lastPathComponent ofType:nil];
201+
if (filename) {
202+
self.image = [UIImage imageWithContentsOfFile:filename];
203+
}
204+
}
197205
}
198-
206+
207+
_imageLoaded = YES;
199208
[_delegate imageNode:self didLoadImage:self.image];
200209
});
201210
}

0 commit comments

Comments
 (0)