import { Meta, Story, Preview } from '@storybook/addon-docs/blocks'; import * as Stories from './examples';
An accessible and responsive image component.
| Name | Type | Default |
|---|---|---|
| ...ViewProps | ||
| blurRadius | ?number | |
| defaultSource | ?Source | |
| draggable | ?boolean | false |
| onError | ?Function | |
| onLoad | ?Function | false |
| onLoadEnd | ?Function | false |
| onLoadStart | ?Function | false |
| onProgress | ?Function | false |
| resizeMode | ?ResizeMode | 'cover' |
| source | Source | false |
| style | ?Style |
The blur radius of the blur filter added to the image.
The source uri is a string representing a placeholder to display while the main image is being loaded.
type Source = { uri: string, width: number, height: number }This is a web-only prop that indicates whether the image can be dragged with
native browser behavior. The default is false.
Called on load error with {nativeEvent: {error}}.
Called when load completes successfully.
Invoked on download progress.
Determines how to resize the image when the frame doesn't match the raw image dimensions.
type ResizeMode = 'center' | 'contain' | 'cover' | 'none' | 'repeat' | 'stretch';The source uri is a string representing the resource identifier for the image, which could be an http address or a base64 encoded image.
type Source = { uri: string, width: number, height: number, method?: string, headers?: object }{
...ViewProps.style
resizeMode: ResizeMode
tintColor: Color
}Image shadows are derived exactly from the pixels.
Tint color is applied to all opaque pixels.
type GetSize = (url: string, success: (width, height) => {}, failure: function) => voidRetrieve 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.)
const uri = 'https://www.domain.com/img-1.jpg';
Image.getSize(uri, ((width, height) => {
// image size is available
});type Prefetch = (url: string) => PromisePrefetches a remote image for later use by downloading it. Once an image has been prefetched it is assumed to be in native browser caches and available for immediate rendering.
const uri = 'https://www.domain.com/img-1.jpg';
Image.prefetch(uri).then(() => {
// image is now prefetched
});Performs cache interrogation. Returns a mapping from URL to cache status: "disk", "memory", "disk/memory". If a requested URL is not in the mapping, it means it's not in the cache.
Image.queryCache([
'https://www.domain.com/img-1.jpg',
'https://www.domain.com/img-2.missing',
'https://www.domain.com/img-3.jpg'
]).then(res => {
expect(res).toEqual({
'https://www.domain.com/img-1.jpg': 'disk/memory',
'https://www.domain.com/img-3.jpg': 'disk/memory'
});
});