mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-03-06 22:37:14 +08:00
Enhance search of directories when load local asset image (#23857)
Summary: Currently, `RCTLocalAssetImageLoader` only support directory of `Library` and `App bundle`, actually, we need to support other directories like `tmp` or `Documents`. Otherwise, the local image load in `tmp` or `Documents` would be handled by `NSURLSession`, we don't need that. <img width="405" alt="image" src="https://user-images.githubusercontent.com/5061845/54188126-0ba66100-44ea-11e9-9a7b-0f721100e9be.png"> [iOS] [Fixed] - Enhance search of directories when load local asset image Pull Request resolved: https://github.com/facebook/react-native/pull/23857 Differential Revision: D14894136 Pulled By: shergin fbshipit-source-id: 26361cd952a423467be9af9a84a80100d868776b
This commit is contained in:
committed by
Facebook Github Bot
parent
9b80560715
commit
1da1e8c6f3
@@ -22,6 +22,16 @@
|
||||
|
||||
NSString *const RCTErrorUnspecified = @"EUNSPECIFIED";
|
||||
|
||||
// Returns the Path of Home directory
|
||||
NSString *__nullable RCTHomePath(void);
|
||||
|
||||
// Returns the relative path within the Home for an absolute URL
|
||||
// (or nil, if the URL does not specify a path within the Home directory)
|
||||
NSString *__nullable RCTHomePathForURL(NSURL *__nullable URL);
|
||||
|
||||
// Determines if a given image URL refers to a image in Home directory (~)
|
||||
BOOL RCTIsHomeAssetURL(NSURL *__nullable imageURL);
|
||||
|
||||
static NSString *__nullable _RCTJSONStringifyNoRetry(id __nullable jsonObject, NSError **error)
|
||||
{
|
||||
if (!jsonObject) {
|
||||
@@ -624,6 +634,16 @@ NSString *__nullable RCTLibraryPath(void)
|
||||
return libraryPath;
|
||||
}
|
||||
|
||||
NSString *__nullable RCTHomePath(void)
|
||||
{
|
||||
static NSString *homePath = nil;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
homePath = NSHomeDirectory();
|
||||
});
|
||||
return homePath;
|
||||
}
|
||||
|
||||
NSString *__nullable RCTBundlePathForURL(NSURL *__nullable URL)
|
||||
{
|
||||
return RCTRelativePathForURL([[NSBundle mainBundle] resourcePath], URL);
|
||||
@@ -635,6 +655,11 @@ NSString *__nullable RCTLibraryPathForURL(NSURL *__nullable URL)
|
||||
return RCTRelativePathForURL(RCTLibraryPath(), URL);
|
||||
}
|
||||
|
||||
NSString *__nullable RCTHomePathForURL(NSURL *__nullable URL)
|
||||
{
|
||||
return RCTRelativePathForURL(RCTHomePath(), URL);
|
||||
}
|
||||
|
||||
static BOOL RCTIsImageAssetsPath(NSString *path)
|
||||
{
|
||||
NSString *extension = [path pathExtension];
|
||||
@@ -651,9 +676,14 @@ BOOL RCTIsLibraryAssetURL(NSURL *__nullable imageURL)
|
||||
return RCTIsImageAssetsPath(RCTLibraryPathForURL(imageURL));
|
||||
}
|
||||
|
||||
BOOL RCTIsHomeAssetURL(NSURL *__nullable imageURL)
|
||||
{
|
||||
return RCTIsImageAssetsPath(RCTHomePathForURL(imageURL));
|
||||
}
|
||||
|
||||
BOOL RCTIsLocalAssetURL(NSURL *__nullable imageURL)
|
||||
{
|
||||
return RCTIsBundleAssetURL(imageURL) || RCTIsLibraryAssetURL(imageURL);
|
||||
return RCTIsBundleAssetURL(imageURL) || RCTIsHomeAssetURL(imageURL);
|
||||
}
|
||||
|
||||
static NSString *bundleName(NSBundle *bundle)
|
||||
|
||||
Reference in New Issue
Block a user