A React component for displaying different types of images, including network images, static resources, temporary local images, and images from local disk, such as the camera roll.

This example shows fetching and displaying an image from local storage as well as one from network and even from data provided in the 'data:' uri scheme.

Note that for network and data images, you will need to manually specify the dimensions of your image!

You can also add style to an image:

  • Function Component

import React from ‘react’;
import { View, Image, StyleSheet } from ‘react-native’;

const styles = StyleSheet.create({
container: {
paddingTop: 50,
},
stretch: {
width: 50,
height: 200,
resizeMode: ‘stretch’,
},
});

const DisplayAnImageWithStyle = () => {
return (

);
}

export default DisplayAnImageWithStyle;

GIF and WebP support on Android#

When building your own native code, GIF and WebP are not supported by default on Android.

You will need to add some optional modules in android/app/build.gradle, depending on the needs of your app.

Reference#

Props#

View Props#

Inherits View Props.


accessible#

When true, indicates the image is an accessibility element.

TYPEDEFAULT
boolfalse

accessibilityLabel#

The text that’s read by the screen reader when the user interacts with the image.

TYPE
string

blurRadius#

blurRadius: the blur radius of the blur filter added to the image.

TYPE
number

Tip : IOS you will need to increase blurRadius more than 5


capInsets iOS#

When the image is resized, the corners of the size specified by capInsets will stay a fixed size, but the center content and borders of the image will be stretched. This is useful for creating resizable rounded buttons, shadows, and other resizable assets. More info in the official Apple documentation.

TYPE
Rect

defaultSource#

A static image to display while loading the image source.

TYPE
ImageSource

Note: On Android, the default source prop is ignored on debug builds.


fadeDuration Android#

Fade animation duration in miliseconds.

TYPEDEFAULT
number300

loadingIndicatorSource#

Similarly to source, this property represents the resource used to render the loading indicator for the image, displayed until image is ready to be displayed, typically after when it got downloaded from network.

TYPE
ImageSource (uri only), number

onError#

Invoked on load error.

TYPE
function({ nativeEvent: { error } }) => void

onLayout#

Invoked on mount and on layout changes.

TYPE
function(LayoutEvent) => void

onLoad#

Invoked when load completes successfully.

TYPE
function(ImageLoadEvent) => void

onLoadEnd#

Invoked when load either succeeds or fails.

TYPE
function() => void

onLoadStart#

Invoked on load start.

Example: onLoadStart={() => this.setState({loading: true})}

TYPE
function() => void

onPartialLoad iOS#

Invoked when a partial load of the image is complete. The definition of what constitutes a “partial load” is loader specific though this is meant for progressive JPEG loads.

TYPE
function() => void

onProgress#

Invoked on download progress.

TYPE
function({ nativeEvent: { loaded, total } }) => void

progressiveRenderingEnabled Android#

When true, enables progressive jpeg streaming – https://frescolib.org/docs/progressive-jpegs.

TYPEDEFAULT
boolfalse

resizeMethod Android#

The mechanism that should be used to resize the image when the image’s dimensions differ from the image view’s dimensions. Defaults to auto.

  • auto: Use heuristics to pick between resize and scale.
  • resize: A software operation which changes the encoded image in memory before it gets decoded. This should be used instead of scale when the image is much larger than the view.
  • scale: The image gets drawn downscaled or upscaled. Compared to resizescale is faster (usually hardware accelerated) and produces higher quality images. This should be used if the image is smaller than the view. It should also be used if the image is slightly bigger than the view.

More details about resize and scale can be found at http://frescolib.org/docs/resizing.

TYPEDEFAULT
enum('auto''resize''scale')'auto'

resizeMode#

Determines how to resize the image when the frame doesn’t match the raw image dimensions. Defaults to cover.

  • cover: Scale the image uniformly (maintain the image’s aspect ratio) so that both dimensions (width and height) of the image will be equal to or larger than the corresponding dimension of the view (minus padding).
  • contain: Scale the image uniformly (maintain the image’s aspect ratio) so that both dimensions (width and height) of the image will be equal to or less than the corresponding dimension of the view (minus padding).
  • stretch: Scale width and height independently, This may change the aspect ratio of the src.
  • repeat: Repeat the image to cover the frame of the view. The image will keep its size and aspect ratio, unless it is larger than the view, in which case it will be scaled down uniformly so that it is contained in the view.
  • center: Center the image in the view along both dimensions. If the image is larger than the view, scale it down uniformly so that it is contained in the view.
TYPEDEFAULT
enum('cover''contain''stretch''repeat''center')'cover'

source#

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. A cache property can be added to control how networked request interacts with the local cache. (For more information see Cache Control for Images).

The currently supported formats are pngjpgjpegbmpgifwebppsd (iOS only). In addition, iOS supports several RAW image formats. Refer to Apple’s documentation for the current list of supported camera models (for iOS 12, see https://support.apple.com/en-ca/HT208967).

TYPE
ImageSource

style#

TYPE
Image Style PropsLayout PropsShadow PropsTransforms

testID#

A unique identifier for this element to be used in UI Automation testing scripts.

TYPE
string

Original Source : https://reactnative.dev/docs/image