expo-image is a cross-platform React component that loads and renders images, and the default template's screens already draw their bundled pictures with it. Coming from React Native's Image, you get props modeled on CSS: placing a photo inside its box works like object-fit and object-position, and a blurred preview can cross-dissolve into the real photo once it arrives. Those props decide what the user sees while a remote photo is on its way and how it sits in its frame afterward.
Key terms
contentFit: the prop that decides how the image is resized to fit its box, the counterpart of CSSobject-fit.contentPosition: the prop that places the image inside its box, the counterpart of CSSobject-position.placeholder: an image shown while the real one loads and nothing has been displayed yet, or whensourceis unset.transition: the prop that describes how the view animates when the image source switches.
Same name, different package
expo-image exports a component called Image, the same name React Native uses, so the import line decides which one you render: import { Image } from 'expo-image';. The package also exports an ImageBackground component and a useImage hook.
The source prop takes a remote URL, a local file resource, or the number that require() returns. Its type also accepts a plain string, so source="https://..." works without wrapping the URL in an object. An object source can carry more than a uri, for example headers, the HTTP headers sent with the request for a remote image. Pass an array of sources and the component picks the one that best fits the container size and is closest to the screen scale.
Sizing follows the rules you know from React Native. For a require()d image such as require('@/assets/images/logo.png'), the bundler reads the file's metadata and provides its width and height. A remote image is different: the bundler can't know its size, so you set width and height yourself, or the image renders at 0 by 0 pixels.
Image doesn't render children. To lay a title over a photo, use ImageBackground, which takes every Image prop and splits styling between style for the container and imageStyle for the image, or position the overlay absolutely.
contentFit and contentPosition
contentFit accepts five values and defaults to 'cover':
'cover'keeps the aspect ratio and fills the whole box, clipping the image when the two aspect ratios differ.'contain'scales the image up or down, keeping its aspect ratio, until it fits entirely inside the box.'fill'fills the box by stretching or squishing the image, so the aspect ratio is lost.'none'leaves the image at its own size and centers it.'scale-down'sizes the image as'none'or'contain', whichever gives the smaller image.
When 'cover' clips a photo, contentPosition picks the part that stays visible. It defaults to 'center' and accepts edge keywords such as 'top', 'bottom left' or 'right center'. With a single keyword the other axis is centered, so 'top' keeps the top edge and centers the photo horizontally. For finer control, pass an object with one vertical key (top or bottom) and one horizontal key (left or right). A number is a distance in points from that edge and a string is a percentage, with 'center' as an alias for '50%'. The keyword 'top right' equals { top: 0, right: 0 }. An unknown string logs a warning and falls back to the centered position.
React Native's resizeMode still works when contentFit isn't set, but it's deprecated, it logs a deprecation message, and its 'repeat' option isn't supported. Use contentFit and contentPosition in new code.
A trail card with a blurred preview
The TrailCard component below renders a remote trail photo in a fixed-height card. Its data comes with a blurhash string for each photo, and the card uses it as the placeholder.
placeholder accepts the same kinds of values as source: an object, a string, a require() number or an array. A BlurHash goes in an object, { blurhash, width, height }. Set width and height, because both default to 16, and higher values cost performance. A ThumbHash string works the same way through the thumbhash field.
Watch placeholderContentFit="cover" in that card. The placeholder's fit defaults to 'scale-down', unlike the image's 'cover', and a low-resolution placeholder can flicker because of that scaling difference. Setting placeholderContentFit to the same value as contentFit prevents it. Paired with contentPosition="top", the card keeps the summit in view when a tall photo gets cropped.
For transition, a number is shorthand for a cross-dissolve lasting that many milliseconds, so transition={300} fades the photo in over 300 ms. The object form adds options. duration is in milliseconds and defaults to 0, so set it whenever you use an object. timing is 'ease-in-out' (the default), 'ease-in', 'ease-out' or 'linear'. effect defaults to 'cross-dissolve', the only effect Android supports.
Two more React Native props have replacements here: defaultSource is deprecated in favor of placeholder, and fadeDuration in favor of a transition with the same duration. For your own loading or error UI, onLoad fires when the image finishes loading and onError when fetching it fails.
Code Examples
import { Image } from 'expo-image';
import { StyleSheet, Text, View } from 'react-native';
type Trail = {
name: string;
photoUrl: string;
blurhash: string;
};
export function TrailCard({ trail }: { trail: Trail }) {
return (
<View style={styles.card}>
<Image
source={trail.photoUrl}
placeholder={{ blurhash: trail.blurhash, width: 32, height: 32 }}
placeholderContentFit="cover"
contentFit="cover"
contentPosition="top"
transition={{ duration: 300, timing: 'ease-out' }}
style={styles.photo}
/>
<Text style={styles.name}>{trail.name}</Text>
</View>
);
}
const styles = StyleSheet.create({
card: { borderRadius: 12, overflow: 'hidden' },
// A remote image needs an explicit size
photo: { width: '100%', height: 180 },
name: { padding: 12, fontSize: 18, fontWeight: '600' },
});