mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-28 12:15:37 +08:00
[Image] Support loading images from application home directory.
Summary:
Image source uri's prefixed with ~ are expanded into a full path to
the app directory.
For example: `~/Documents/foo.png` is expanded into `Users/arbesfeld/Library/Developer/CoreSimulator/Devices/977988DF-A8BC-4CE5-A27A-75807A6DF085/data/Containers/Data/Application/CBEFC261-5900-4EF9-8646-603BC57B094A/Documents/foo.png`.
This lets us store and use images from the application home directory with the `Image` component:
```
<Image source={{uri: '~/Documents/foo.png', width: 300, height: 300}} />
```
Resolves #1178
Closes https://github.com/facebook/react-native/pull/1740
Github Author: Matthew Arbesfeld <arbesfeld@gmail.com>
This commit is contained in:
@@ -671,8 +671,8 @@ RCT_CGSTRUCT_CONVERTER(CGAffineTransform, (@[
|
||||
NSURL *url = [NSURL URLWithString:path];
|
||||
NSData *imageData = [NSData dataWithContentsOfURL:url];
|
||||
image = [UIImage imageWithData:imageData];
|
||||
} else if ([path isAbsolutePath]) {
|
||||
image = [UIImage imageWithContentsOfFile:path];
|
||||
} else if ([path isAbsolutePath] || [path hasPrefix:@"~"]) {
|
||||
image = [UIImage imageWithContentsOfFile:path.stringByExpandingTildeInPath];
|
||||
} else {
|
||||
image = [UIImage imageNamed:path];
|
||||
if (!image) {
|
||||
|
||||
Reference in New Issue
Block a user