Skip to content
Tutorials Center
My learning

Topics

Lesson 17 of 71 ยท Components and Interaction

Images, Icons and Media

Show local and remote images in React Native, choose resizeMode or contentFit, cache with expo-image, draw SVG, use vector icons and blurhash placeholders.

Pictures carry a lot of an app's personality: product photos, avatars, logos and icons. React Native has an Image component for the basics, and the Expo ecosystem adds expo-image for caching and placeholders, plus packages for SVG graphics and icon fonts. Images are also where beginners hit two classic surprises: a remote image that does not appear at all, and a photo that is stretched out of shape.

This lesson covers where an image can come from, how it is fitted into its box, and how to make loading feel smooth.

What runs on this site. Images are decoded and cached by the native side, so the real React Native code is read-only here. The runnable examples are stand-ins: they use HTML img elements and an inline SVG to imitate resizeMode, aspect ratios and a loading placeholder. Native image caches, formats and decoding speed cannot be shown in a browser tab.

Local and remote images

There are two kinds of sources, and they behave differently.

JSX
import { Image } from 'react-native';

// 1. Local file bundled with the app: the size is known automatically.
<Image source={require('./assets/logo.png')} />

// 2. Remote URL: you MUST give a width and a height.
<Image
  source={{ uri: 'https://example.com/photo.jpg' }}
  style={{ width: 200, height: 120 }}
/>

A local image is bundled into the app by the build tool, so React Native knows its dimensions before it renders. A remote image has no known size until it downloads, so with no width and height in the style, it takes zero size and you see nothing. That is the first surprise.

Local assets can have density variants: logo.png, [email protected] and [email protected]. You write require('./logo.png') once and the platform picks the sharpest file for the screen. Remote images do not get this, so ask your server for a size suited to the display (see Responsive Layouts and Screen Sizes for PixelRatio).

Two details for remote images: use HTTPS (plain HTTP is blocked by default on current iOS and Android), and pass headers inside the source object if the image needs an authorization header.

Fitting an image into its box

When the box and the image have different proportions, resizeMode decides what happens:

  • cover scales the image until it fills the box, cropping the overflow (the default).
  • contain scales the image down to fit entirely inside, leaving empty space.
  • stretch distorts the image to fill the box exactly.
  • center keeps the size but centers the image, scaling down only if it is too big.
  • repeat tiles the image.

expo-image uses the web's naming instead: contentFit with cover, contain, fill, none and scale-down, plus contentPosition to choose which part stays visible.

Where images come from

Local Bundled with require(). Size is known.
Remote A uri. Needs width and height.
Vector SVG or icon fonts. Sharp at any size.
1 / 2
resizeMode playground (stand-in)

Sizing with aspectRatio

You often know the width (full screen width, or half of it in a grid) and want the height to follow the picture's proportions. Use aspectRatio, which is width divided by height:

JSX
<Image
  source={{ uri: product.photoUrl }}
  style={{ width: '100%', aspectRatio: 16 / 9 }}
  resizeMode="cover"
/>

If you know the real size from your API, use it (aspectRatio: photo.width / photo.height). The box then has the right height before the image loads, so the layout does not jump when it arrives.

expo-image: caching and placeholders

The built-in Image is fine for simple cases, but Expo apps usually switch to expo-image, which adds a faster image pipeline and features the core component lacks:

JSX
import { Image } from 'expo-image';

const blurhash = 'LEHV6nWB2yk8pyo0adR*.7kCMdnj';

export function Avatar({ url }) {
  return (
    <Image
      source={{ uri: url }}
      placeholder={{ blurhash }}
      contentFit="cover"
      transition={200}
      cachePolicy="memory-disk"
      style={{ width: 64, height: 64, borderRadius: 32 }}
    />
  );
}
  • cachePolicy keeps downloaded images in memory and on disk (none, disk, memory or memory-disk), so a revisited screen does not download them again.
  • placeholder shows something while the real image loads. A blurhash (or its cousin thumbhash) is a very short string, about 20 to 30 characters, that decodes to a blurred preview with the right colors. Your backend can store it next to each image URL.
  • transition cross-fades from the placeholder to the final image.
  • recyclingKey helps in lists, where the same component is reused for different pictures.
  • Image.prefetch(url) warms the cache before the person reaches a screen.

Remember to also describe the image for screen readers with the alt prop (or accessibilityLabel), and to mark purely decorative images as not important for accessibility.

Aspect ratio and a loading placeholder

SVG graphics

Raster formats (PNG, JPEG, WebP) are made of pixels. SVG describes shapes with math, so a logo or illustration stays sharp at any size and is tiny to ship. React Native has no built-in SVG support, but there are two common routes:

  • react-native-svg lets you draw with components: Svg, Circle, Rect, Path, LinearGradient. It is also what chart libraries build on.
  • expo-image can display an SVG file as a source, which is the simplest option for static illustrations.
JSX
import Svg, { Circle, Path } from 'react-native-svg';

export function Badge() {
  return (
    <Svg width={48} height={48} viewBox="0 0 48 48">
      <Circle cx="24" cy="24" r="22" fill="#16a34a" />
      <Path d="M14 25l7 7 13-14" stroke="white" strokeWidth="4" fill="none" />
    </Svg>
  );
}

Icons

For UI icons, use an icon font package instead of image files. Expo ships @expo/vector-icons, which bundles popular sets (Ionicons, MaterialIcons, FontAwesome and more):

JSX
import { Ionicons } from '@expo/vector-icons';

<Ionicons name="heart" size={24} color="#dc2626" />

An icon is just a glyph in a font, so size and color work like text, it never blurs, and it adds little to the bundle. The name prop is type-checked in TypeScript, which catches typos. For custom icons you design yourself, convert your SVGs into a font or use react-native-svg.

Beyond images

Video and audio are separate native capabilities. Expo provides expo-video and expo-audio as packages with the same pattern: install the package, create a player, render a view. Camera and photo-library access are covered in Camera, Location and Sensors.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Why does a remote image with no width and height in its style not appear?

    Local images are bundled, so their size is known. A remote image has no dimensions until it downloads, so you must provide width and height (or an aspectRatio with one dimension).
  2. 2. Which resizeMode fills the box completely and crops whatever does not fit?

    cover scales the image until it fills the box and crops the overflow. contain leaves empty space, and stretch fills the box but distorts the picture.
  3. 3. What is a blurhash used for?

    A blurhash is a short encoded string that decodes into a blurred preview. expo-image can show it through the placeholder prop and fade to the real image.
  4. 4. Why use aspectRatio together with a known width?

    aspectRatio is width divided by height. With a known width, React Native can compute the height up front, so the layout is stable while the image downloads.
  5. 5. What is a good way to show many small UI icons that stay sharp at any size?

    An icon font renders glyphs like text, so size and color are plain props, the icons never blur, and the bundle stays small.

Summary

  • Local images (require) have a known size; remote images ({ uri }) need width and height, ideally via HTTPS.
  • resizeMode (cover, contain, stretch, center, repeat) decides how the image fits its box; expo-image calls it contentFit.
  • Use aspectRatio with a known width so the layout does not jump while the image loads.
  • expo-image adds disk and memory caching, blurhash placeholders, transitions and prefetching.
  • Use react-native-svg or expo-image for SVG, and @expo/vector-icons for UI icons; always give meaningful images an alt text.
  • On this site the real components are read-only; the TryIts are HTML stand-ins for fitting, sizing and placeholders.

Next, handle long content and the on-screen keyboard in ScrollView and Keyboard Handling.