include information about https for images in documentation

Summary:
Thanks for submitting a pull request! Please provide enough information so that others can review your pull request:

> **Unless you are a React Native release maintainer and cherry-picking an _existing_ commit into a current release, ensure your pull request is targeting the `master` React Native branch.**

Explain the **motivation** for making this change. What existing problem does the pull request solve?

Prefer **small pull requests**. These are much easier to review and more likely to get merged. Make sure the PR does only one thing, otherwise please split it.

**Test plan (required)**

Demonstrate the code is solid. Example: The exact commands you ran and their output, screenshots / videos if the pull request changes UI.

Make sure tests pass on both Travis and Circle CI.

**Code formatting**

Look around. Match the style of the rest of the codebase. See also the simple [style guide](https://github.com/facebook/react-native/blob/master/CONTRIBUTING.md#style-guide).

For more info, see the ["Pull Reques
Closes https://github.com/facebook/react-native/pull/10436

Differential Revision: D4141792

Pulled By: hramos

fbshipit-source-id: b3b460fa2e22a6133865005326b09dddd1c05e29
This commit is contained in:
Héctor Ramos 2016-11-10 18:42:43 -08:00 committed by Facebook Github Bot
parent 07dc35e4ad
commit 98c620c6da
1 changed files with 10 additions and 12 deletions

View File

@ -10,15 +10,15 @@ previous: colors
## Static Image Resources
As of 0.14 release, React Native provides a unified way of managing images in your iOS and Android apps. To add a static image to your app, place it somewhere in your source code tree and reference it like this:
React Native provides a unified way of managing images in your iOS and Android apps. To add a static image to your app, place it somewhere in your source code tree and reference it like this:
```javascript
<Image source={require('./my-icon.png')} />
```
The image name is resolved the same way JS modules are resolved. In the example above the packager will look for `my-icon.png` in the same folder as the component that requires it. Also if you have `my-icon.ios.png` and `my-icon.android.png`, the packager will pick the file depending on the platform you are running on.
The image name is resolved the same way JS modules are resolved. In the example above, the packager will look for `my-icon.png` in the same folder as the component that requires it. Also, if you have `my-icon.ios.png` and `my-icon.android.png`, the packager will pick the correct file for the platform.
You can also use `@2x`, `@3x`, etc. suffix in the file name to provide images for different screen densities. For example, if you have the following file structure:
You can also use the `@2x` and `@3x` suffixes to provide images for different screen densities. If you have the following file structure:
```
.
@ -28,27 +28,27 @@ You can also use `@2x`, `@3x`, etc. suffix in the file name to provide images fo
└── check@3x.png
```
And `button.js` code contains
...and `button.js` code contains:
```javascript
<Image source={require('./img/check.png')} />
```
Packager will bundle and serve the image corresponding to the device's screen density, e.g. on iPhone 5s `check@2x.png` will be used, on Nexus 5 `check@3x.png`. If there is no image matching the screen density, the closest best option will be selected.
...the packager will bundle and serve the image corresponding to device's screen density. For example, `check@2x.png`, will be used on an iPhone 7, while`check@3x.png` will be used on an iPhone 7 Plus or a Nexus 5. If there is no image matching the screen density, the closest best option will be selected.
On Windows, you might need to restart the packager if you add new images to your project.
Here are some benefits that you get:
1. Same system on iOS and Android.
2. Images live in the same folder as your JS code. Components are self-contained.
2. Images live in the same folder as your JavaScript code. Components are self-contained.
3. No global namespace, i.e. you don't have to worry about name collisions.
4. Only the images that are actually used will be packaged into your app.
5. Adding and changing images doesn't require app recompilation, just refresh the simulator as you normally do.
6. The packager knows the image dimensions, no need to duplicate it in the code.
7. Images can be distributed via [npm](https://www.npmjs.com/) packages.
Note that in order for this to work, the image name in `require` has to be known statically.
In order for this to work, the image name in `require` has to be known statically.
```javascript
// GOOD
@ -63,9 +63,7 @@ var icon = this.props.active ? require('./my-icon-active.png') : require('./my-i
<Image source={icon} />
```
Note that image sources required this way include size (width, height) info for the Image. If you need to scale the image dynamically (i.e. via flex), you may need to manually set { width: undefined, height: undefined } on the style attribute.
**Available React Native 0.14+**. If you've generated your project with 0.13 or earlier, read this. The new asset system relies on build hooks for [Xcode](https://github.com/facebook/react-native/pull/3523) and [Gradle](https://github.com/facebook/react-native/commit/9dc036d2b99e6233297c55a3490bfc308e34e75f) that are included in new projects generated with `react-native init`. If you generated your projects before that, you'll have to manually add them to your projects to use the new images asset system. See [Upgrading](/react-native/docs/upgrading.html) for instructions on how to do this.
Note that image sources required this way include size (width, height) info for the Image. If you need to scale the image dynamically (i.e. via flex), you may need to manually set `{ width: undefined, height: undefined }` on the style attribute.
## Images From Hybrid App's Resources
@ -75,12 +73,12 @@ If you are building a hybrid app (some UIs in React Native, some UIs in platform
<Image source={{uri: 'app_icon'}} style={{width: 40, height: 40}} />
```
Note that this approach provides no safety checks. It's up to you to guarantee that those images are available in the application. Also you have to specify image dimensions manually.
This approach provides no safety checks. It's up to you to guarantee that those images are available in the application. Also you have to specify image dimensions manually.
## Network Images
Many of the images you will display in your app will not be available at compile time, or you will want to load some dynamically to keep the binary size down. Unlike with static resources, *you will need to manually specify the dimensions of your image.*
Many of the images you will display in your app will not be available at compile time, or you will want to load some dynamically to keep the binary size down. Unlike with static resources, *you will need to manually specify the dimensions of your image*. It's highly recommended that you use https as well in order to satisfy [App Transport Security](/react-native/docs/running-on-device.html#app-transport-security) requirements on iOS.
```javascript
// GOOD