'data:' uri scheme.
Examples
style to an image:
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 inandroid/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.
accessibilityLabel
The text that’s read by the screen reader when the user interacts with the image.
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.
blurRadius
blurRadius: the blur radius of the blur filter added to the image.
capInsets iOS Vega
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.
crossOrigin
A string of a keyword specifying the CORS mode to use when fetching the image resource. It works similar to crossorigin attribute in HTML.
anonymous: No exchange of user credentials in the image request.use-credentials: SetsAccess-Control-Allow-Credentialsheader value totruein the image request.
defaultSource
A static image to display while loading the image source.
defaultFillColor Vega
A color used as a placeholder background until the image source fully loads.
defaultColor Vega
Deprecated. Use defaultFillColor instead.
A color used as a placeholder background until the image source fully loads.
fadeDuration Android Vega
Fade animation duration in milliseconds.
height
Height of the image component.
loadingIndicatorSource
Similarly to source, this property represents the resource used to render the loading indicator for the image. The loading indicator is displayed until image is ready to be displayed, typically after the image is downloaded.
onError
Invoked on load error.
onLayout
Invoked on mount and on layout changes.
onLoad
Invoked when load completes successfully.
Example: onLoad={({nativeEvent: {source: {width, height}}}) => setImageRealSize({width, height})}
onLoadEnd
Invoked when load either succeeds or fails.
onLoadStart
Invoked on load start.
Example: onLoadStart={() => this.setState({loading: true})}
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.
onProgress iOS Vega
Invoked on download progress.
progressiveRenderingEnabled Android Vega
When set to true, enables progressive JPEG streaming. On Android, this is implemented using the Fresco library https://frescolib.org/docs/progressive-jpegs, whereas on Vega, it is supported by the lower system layers.
referrerPolicy
A string indicating which referrer to use when fetching the resource. Sets the value for Referrer-Policy header in the image request. Works similar to referrerpolicy attribute in HTML.
ref
A ref setter that will be assigned an element node when mounted.
resizeMethod Android Vega
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 betweenresizeandscale. -
resize: A software operation which changes the encoded image in memory before it gets decoded. This should be used instead ofscalewhen the image is much larger than the view. -
scale: The image gets drawn downscaled or upscaled. Compared toresize,scaleis 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. -
none: No sampling is performed and the image is displayed in its full resolution. This should only be used in rare circumstances because it is considered unsafe as Android will throw a runtime exception when trying to render images that consume too much memory.
resize and scale can be found at https://frescolib.org/docs/resizing.
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.
resizeMultiplier Android
When the resizeMethod is set to resize, the destination dimensions are multiplied by this value. The scale method is used to perform the remainder of the resize. A default of 1.0 means the bitmap size is designed to fit the destination dimensions. A multiplier greater than 1.0 will set the resize options larger than that of the destination dimensions, and the resulting bitmap will be scaled down from the hardware size. Defaults to 1.0.
This prop is most useful in cases where the destination dimensions are quite small and the source image is significantly larger. The resize resize method performs downsampling and significant image quality is lost between the source and destination image sizes, often resulting in a blurry image. By using a multiplier, the decoded image is slightly larger than the target size but smaller than the source image (if the source image is large enough). This allows aliasing artifacts to produce faux quality through scaling operations on the multiplied image.
If you have a source image with dimensions 200x200 and destination dimensions of 24x24, a resizeMultiplier of 2.0 will tell Fresco to downsample the image to 48x48. Fresco picks the closest power of 2 (so, 50x50) and decodes the image into a bitmap of that size. Without the multiplier, the closest power of 2 would be 25x25. The resultant image is scaled down by the system.
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 png, jpg, jpeg, bmp, gif, webp, psd (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).
Please note that the webp format is supported on iOS only when bundled with the JavaScript code.
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'}
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](https://reactnative.dev/img/header_logo.svg) 2x'}
style
testID
A unique identifier for this element to be used in UI Automation testing scripts.
tintColor
Changes the color of all non-transparent pixels to the tintColor.
width
Width of the image component.
Methods
abortPrefetch() Android Vega
getSize()
getSizeWithHeaders()
prefetch()
queryCache()
resolveAssetSource()
uri, scale, width, and height.
Parameters:
Type Definitions
ImageCacheEnum iOS Vega
Enum which can be used to set the cache handling or strategy for the potentially cached responses.
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.
ImageLoadEvent
Object returned in theonLoad callback.
Source Object
Properties:ImageSource
number- opaque type returned by something likerequire('./image.jpg').

