as

Settings
Sign out
Notifications
Alexa
Amazonアプリストア
AWS
ドキュメント
Support
Contact Us
My Cases
開発
設計と開発
公開
リファレンス
サポート
アクセスいただきありがとうございます。こちらのページは現在英語のみのご用意となっております。順次日本語化を進めてまいりますので、ご理解のほどよろしくお願いいたします。

Image

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!

Examples


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

const styles = StyleSheet.create({
  container: {
    paddingTop: 50,
  },
  tinyLogo: {
    width: 50,
    height: 50,
  },
  logo: {
    width: 66,
    height: 58,
  },
});

const DisplayAnImage = () => {
  return (
    <View style={styles.container}>
      <Image
        style={styles.tinyLogo}
        source={require('@expo/snack-static/react-native-logo.png')}
      />
      <Image
        style={styles.tinyLogo}
        source={{
          uri: 'https://reactnative.dev/img/tiny_logo.png',
        }}
      />
      <Image
        style={styles.logo}
        source={{
          uri: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADMAAAAzCAYAAAA6oTAqAAAAEXRFWHRTb2Z0d2FyZQBwbmdjcnVzaEB1SfMAAABQSURBVGje7dSxCQBACARB+2/ab8BEeQNhFi6WSYzYLYudDQYGBgYGBgYGBgYGBgYGBgZmcvDqYGBgmhivGQYGBgYGBgYGBgYGBgYGBgbmQw+P/eMrC5UTVAAAAABJRU5ErkJggg==',
        }}
      />
    </View>
  );
};

export default DisplayAnImage;

You can also add style to an image:


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 (
    <View style={styles.container}>
      <Image
        style={styles.stretch}
        source={require('@expo/snack-static/react-native-logo.png')}
      />
    </View>
  );
};

export default DisplayAnImageWithStyle;

Reference

Props

View Props

Inherits View Props.


accessible

When true, indicates the image is an accessibility element.

Type Default
bool false

accessibilityLabel

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

Type
string

alt

A string that defines an alternative text description of the image, which will be read by the screen reader when the user interacts with it. Using this will automatically mark this element as accessible.

Type
string

blurRadius

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

Type
number

crossOrigin

A string of a keywords specifying the CORS mode to use when fetching the image resource. The crossOrigin prop functions in a similar manner to the crossorigin attribute in HTML.

  • anonymous: No exchange of user credentials in the image request.
  • use-credentials: Sets the Access-Control-Allow-Credentials header value to true in the image request.
Type Default
enum('anonymous', 'use-credentials') 'anonymous'

defaultSource

A static image to display while loading the image source.

Type
ImageSource

capInsets

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

defaultColor

A color to display while loading the image source.

Type
color

defaultSource

A static image to display while loading the image source.

Type
ImageSource

fadeDuration

Fade animation duration in milliseconds.

Type Default
number 0

height

Height of the image component.

Type
number

loadingIndicatorSource

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

Type
ImageSource (uri only), number

Note: This property only supports a local static image.


onError

Invoked on load error.

Type
({nativeEvent: {error} }) => void

onLayout

Invoked on mount and on layout changes.

Type
({nativeEvent: [LayoutEvent](layoutevent)} => void

onLoad

Invoked when load completes successfully.

Example: onLoad={({nativeEvent: {source: {width, height}}}) => setImageRealSize({width, height})}

Type
({nativeEvent: [ImageLoadEvent](image#imageloadevent)} => void

onLoadEnd

Invoked when load either succeeds or fails.

Type
() => void

onLoadStart

Invoked on load start.

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

Type
() => void

onProgress

Invoked on download progress.

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

progressiveRenderingEnabled

When set to true, enables progressive JPEG streaming.

Type Default
bool false

referrerPolicy

A string indicating which referrer to use when fetching the resource. Sets the value for Referrer-Policy header in the image request. The referrerPolicy prop functions in a similar manner to the referrerpolicy attribute in HTML.

Type Default
enum('no-referrer', 'no-referrer-when-downgrade', 'origin', 'origin-when-cross-origin', 'same-origin', 'strict-origin', 'strict-origin-when-cross-origin', 'unsafe-url') 'strict-origin-when-cross-origin'

resizeMethod

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. Dynamically changing this prop after the image is loaded has no effect.

  • 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.g
  • scale: The image gets drawn downscaled or upscaled. Compared to resize, scale 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.

Type Default
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)
    • at least one dimension of the scaled image will be equal to 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.

Type Default
enum('cover', 'contain', 'stretch', 'repeat', 'center') 'cover'

source

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

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 png, jpg, jpeg, bmp, gif, and webp.

Blob data can be fetched and converted into URI using the createObjectUrl function.

URL.createObjectUrl(blob);.
Type
ImageSource

src

A string representing the remote URL of the image. This prop has precedence over source prop.

Example: src={'https://reactnative.dev/img/tiny_logo.png'}

Type
string

srcSet

A string representing comma separated list of possible candidate image source. Each image source contains a URL of an image and a pixel density descriptor. If no descriptor is specified, it defaults to descriptor of 1x.

If srcSet does not contain a 1x descriptor, the value in src is used as image source with 1x descriptor (if provided).

This prop has precedence over both the src and source props.

Example: srcSet={'https://reactnative.dev/img/tiny_logo.png 1x, https://reactnative.dev/img/header_logo.svg 2x'}

Type
string

style

Type
Image Style Props, Layout Props, Shadow Props, Transforms

testID

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

Type
string

width

Width of the image component.

Type
number

Methods

abortPrefetch

static abortPrefetch(requestId: number);

Abort prefetch request.

Parameters:

Name Type Description
requestId Required number Request id as returned by prefetch().

getSize

static getSize(
  uri: string,
  success: (width: number, height: number) => void,
  failure?: (error: any) => void,
): any;

Retrieve the width and height (in pixels) of an image prior to displaying it. This method can fail if the image cannot be found, or fails to download.

In order to retrieve the image dimensions, the image may first need to be loaded or downloaded, after which it will be cached. This means that in principle you could use this method to preload images, however it is not optimized for that purpose, and may in future be implemented in a way that does not fully load/download the image data. A proper, supported way to preload images will be provided as a separate API.

Parameters:

Name Type Description
uri Required string The location of the image.
success Required function The function that will be called if the image was successfully found and width and height retrieved.
failure function The function that will be called if there was an error, such as failing to retrieve the image.

getSizeWithHeaders

static getSizeWithHeaders(
  uri: string,
  headers: {[index: string]: string},
  success: (width: number, height: number) => void,
  failure?: (error: any) => void,
): any;

Retrieve the width and height (in pixels) of an image prior to displaying it with the ability to provide the headers for the request. This method can fail if the image cannot be found, or fails to download. It also does not work for static image resources.

In order to retrieve the image dimensions, the image may first need to be loaded or downloaded, after which it will be cached. This means that in principle you could use this method to preload images, however it is not optimized for that purpose, and may in future be implemented in a way that does not fully load/download the image data. A proper, supported way to preload images will be provided as a separate API.

Parameters:

Name Type Description
uri Required string The location of the image.
headers Required object The headers for the request.
success Required function The function that will be called if the image was successfully found and width and height retrieved.
failure function The function that will be called if there was an error, such as failing to retrieve the image.

prefetch

await Image.prefetch(url);

Prefetches a remote image for later use by downloading it to the disk cache. Returns a promise which resolves to a boolean.

Parameters:

Name Type Description
url Required string The remote location of the image.
callback function The function that will be called with the requestId.

queryCache

static queryCache(
  urls: string[],
): Promise<Record<string, 'memory' | 'disk' | 'disk/memory'>>;

Perform cache interrogation. Returns a promise which resolves to a mapping from URL to cache status, such as "disk", "memory" or "disk/memory". If a requested URL is not in the mapping, it means it's not in the cache.

Parameters:

Name Type Description
urls Required array List of image URLs to check the cache for.

resolveAssetSource

static resolveAssetSource(source: ImageSourcePropType): {
  height: number;
  width: number;
  scale: number;
  uri: string;
};

Resolves an asset reference into an object which has the properties uri, scale, width, and height.

Parameters:

<div className="wideColumn">Name</div> Type Description
source Required ImageSource, number A number (opaque type returned by require('./foo.png')) or an ImageSource.

Type Definitions

ImageLoadEvent

Object returned in the onLoad callback.

Type
object

Properties:

Name Type Description
source object The source object

Source Object

Properties:

Name Type Description
width number The width of loaded image.
height number The height of loaded image.
uri string A string representing the resource identifier for the image.

ImageSource

Type
object, array of objects, number

Properties (if passing as object or array of objects):

Name Type Description
uri string A string representing the resource identifier for the image, which could be an http address, a local file path, or the name of a static image resource.
width number Can be specified if known at build time, in which case the value will be used to set the default <Image/> component dimension.
height number Can be specified if known at build time, in which case the value will be used to set the default <Image/> component dimension.

Last updated: Sep 30, 2025