One Logo Pool Ball
wwwwwwwwwwwwwwwwwww

Image

Shared images through the native image loader

One.UI.Image on iOS and Android: a photo grid loaded from remote URLs

One.UI.Image shows local and remote images through Nitro Image on iOS and Android, and an img element on web.

Usage

Give the image a size. cover is the default resize mode.

import { One } from 'one'
<One.UI.Image
source={{ uri: photo.url }}
style={{ width: 240, height: 160 }}
onError={({ nativeEvent }) => console.warn(nativeEvent.error)}
/>

In long lists, set recyclingKey to the image’s URL so a reused cell shows nothing until its new image loads.

<One.UI.Image source={item.url} recyclingKey={item.url} style={styles.thumb} />

API reference

Image also accepts React Native ImageProps other than the four below, including style, onLoadStart, and onLoadEnd.

PropsTypeDescription
source (required)string | number | { uri: string }A URL, a { uri } object, or a bundled image from require().
string | number | { uri: string }A URL, a { uri } object, or a bundled image from require().
resizeMode"cover" | "contain" | "center" | "stretch" = "cover"How the image fits the view when their shapes differ.
"cover" | "contain" | "center" | "stretch" = "cover"How the image fits the view when their shapes differ.
recyclingKeystringWhen it changes, the view clears until the new image loads.
stringWhen it changes, the view clears until the new image loads.
EventsTypeDescription
onLoad(event: { nativeEvent: { source: { uri: string; width: number; height: number } } }) => voidThe image loaded. Width and height are its pixel size.
(event: { nativeEvent: { source: { uri: string; width: number; height: number } } }) => voidThe image loaded. Width and height are its pixel size.
onError(event: { nativeEvent: { error: string } }) => voidThe image failed to load.
(event: { nativeEvent: { error: string } }) => voidThe image failed to load.

Behavior

iOSAndroidWeb
RendererNitro ImageNitro Imageimg
Bundled imagesYesYesThrows; use a URL
centerCentered at natural sizeCentered at natural sizeobject-fit: none

Edit this page on GitHub.