diff --git a/releases/next/docs/image.html b/releases/next/docs/image.html index 82c4dd46078..1dcf48f3a25 100644 --- a/releases/next/docs/image.html +++ b/releases/next/docs/image.html @@ -74,7 +74,8 @@ aspect ratio of the src.

  • repeat: Repeat the image to image will keep it's size and aspect ratio. (iOS only)

  • source ImageSourcePropType #

    The image source (either a remote URL or a local file resource).

    This prop can also contain several remote URLs, specified together with their width and height and potentially with scale/other URI arguments. The native side will then choose the best uri to display based on the -measured size of the image container.

    style style #

    backfaceVisibility enum('visible', 'hidden')
    backgroundColor color
    borderBottomLeftRadius number
    borderBottomRightRadius number
    borderColor color
    borderRadius number
    borderTopLeftRadius number
    borderTopRightRadius number
    borderWidth number
    opacity number
    overflow enum('visible', 'hidden')
    resizeMode Object.keys(ImageResizeMode)
    tintColor color

    Changes the color of all the non-transparent pixels to the tintColor.

    androidoverlayColor string

    When the image has rounded corners, specifying an overlayColor will +measured size of the image container. A cache property can be added to +control how networked request interacts with the local cache.

    style style #

    backfaceVisibility enum('visible', 'hidden')
    backgroundColor color
    borderBottomLeftRadius number
    borderBottomRightRadius number
    borderColor color
    borderRadius number
    borderTopLeftRadius number
    borderTopRightRadius number
    borderWidth number
    opacity number
    overflow enum('visible', 'hidden')
    resizeMode Object.keys(ImageResizeMode)
    tintColor color

    Changes the color of all the non-transparent pixels to the tintColor.

    androidoverlayColor string

    When the image has rounded corners, specifying an overlayColor will cause the remaining space in the corners to be filled with a solid color. This is useful in cases which are not supported by the Android implementation of rounded corners: @@ -395,6 +396,35 @@ exports.examples }, platform: 'ios', }, + { + title: 'Cache Policy', + description: 'First image has never been loaded before and is instructed not to load unless in cache.' + + 'Placeholder image from above will stay. Second image is the same but forced to load regardless of' + + ' local cache state.', + render: function () { + return ( + <View style={styles.horizontal}> + <Image + defaultSource={require('./bunny.png')} + source={{ + uri: smallImage.uri + '?cacheBust=notinCache' + Date.now(), + cache: 'only-if-cached' + }} + style={styles.base} + /> + <Image + defaultSource={require('./bunny.png')} + source={{ + uri: smallImage.uri + '?cacheBust=notinCache' + Date.now(), + cache: 'reload' + }} + style={styles.base} + /> + </View> + ); + }, + platform: 'ios', + }, { title: 'Border Color', render: function() { diff --git a/releases/next/docs/images.html b/releases/next/docs/images.html index c32662fa00f..b1390d45230 100644 --- a/releases/next/docs/images.html +++ b/releases/next/docs/images.html @@ -16,7 +16,15 @@ style={{width: 400, height: 400}} /> // BAD -<Image source={{uri: 'https://facebook.github.io/react/img/logo_og.png'}} />

    Local Filesystem Images #

    See CameraRoll for an example of +<Image source={{uri: 'https://facebook.github.io/react/img/logo_og.png'}} />

    Cache Control (iOS Only) #

    In some cases you might only want to display an image if it is already in the local cache, i.e. a low resolution placeholder until a higher resolution is available. In other cases you do not care if the image is outdated and are willing to display an outdated image to save bandwidth. The cache source property gives you control over how the network layer interacts with the cache.

    • default: Use the native platforms default strategy.
    • reload: The data for the URL will be loaded from the originating source. +No existing cache data should be used to satisfy a URL load request.
    • force-cache: The existing cached data will be used to satisfy the request, +regardless of its age or expiration date. If there is no existing data in the cache +corresponding the request, the data is loaded from the originating source.
    • only-if-cached: The existing cache data will be used to satisfy a request, regardless of +its age or expiration date. If there is no existing data in the cache corresponding +to a URL load request, no attempt is made to load the data from the originating source, +and the load is considered to have failed.
    <Image source={{uri: 'https://facebook.github.io/react/img/logo_og.png', cache: 'only-if-cached'}} + style={{width: 400, height: 400}} /> +`

    Local Filesystem Images #

    See CameraRoll for an example of using local resources that are outside of Images.xcassets.

    Best Camera Roll Image #

    iOS saves multiple sizes for the same image in your Camera Roll, it is very important to pick the one that's as close as possible for performance reasons. You wouldn't want to use the full quality 3264x2448 image as source when displaying a 200x200 thumbnail. If there's an exact match, React Native will pick it, otherwise it's going to use the first one that's at least 50% bigger in order to avoid blur when resizing from a close size. All of this is done by default so you don't have to worry about writing the tedious (and error prone) code to do it yourself.

    Why Not Automatically Size Everything? #

    In the browser if you don't give a size to an image, the browser is going to render a 0x0 element, download the image, and then render the image based with the correct size. The big issue with this behavior is that your UI is going to jump all around as images load, this makes for a very bad user experience.

    In React Native this behavior is intentionally not implemented. It is more work for the developer to know the dimensions (or aspect ratio) of the remote image in advance, but we believe that it leads to a better user experience. Static images loaded from the app bundle via the require('./my-icon.png') syntax can be automatically sized because their dimensions are available immediately at the time of mounting.

    For example, the result of require('./my-icon.png') might be:

    {"__packager_asset":true,"uri":"my-icon.png","width":591,"height":573}

    Source as an object #

    In React Native, one interesting decision is that the src attribute is named source and doesn't take a string but an object with a uri attribute.

    <Image source={{uri: 'something.jpg'}} />

    On the infrastructure side, the reason is that it allows us to attach metadata to this object. For example if you are using require('./my-icon.png'), then we add information about its actual location and size (don't rely on this fact, it might change in the future!). This is also future proofing, for example we may want to support sprites at some point, instead of outputting {uri: ...}, we can output {uri: ..., crop: {left: 10, top: 50, width: 20, height: 40}} and transparently support spriting on all the existing call sites.

    On the user side, this lets you annotate the object with useful attributes such as the dimension of the image in order to compute the size it's going to be displayed in. Feel free to use it as your data structure to store more information about your image.

    Background Image via Nesting #

    A common feature request from developers familiar with the web is background-image. To handle this use case, simply create a normal <Image> component and add whatever children to it you would like to layer on top of it.

    return ( <Image source={...}> <Text>Inside</Text>