A responsive image component with loading states, error handling, and flexible styling options.

Installation

pnpm dlx bna-ui add image

Usage

import { Image } from '@/components/ui/image';
<Image
  source={{ uri: 'https://picsum.photos/400/300' }}
  width={400}
  height={300}
/>

Examples

Default

Variants

Sizes

Loading States

Error Handling

Responsive

Content Fit

API Reference

Image

A responsive image component with loading states and error handling.

PropTypeDefaultDescription
sourceImageSource-The image source (required).
fullbooleantrueWhether the image should fill its container.
variant'rounded' | 'circle''rounded'The border radius variant.
widthnumber | string-The width of the image.
heightnumber | string-The height of the image.
aspectRationumber-The aspect ratio of the image.
contentFitContentFit'cover'How the image should fit within its bounds.
showLoadingIndicatorbooleantrueWhether to show loading indicator.
showErrorFallbackbooleantrueWhether to show error fallback.
errorFallbackTextstring'Failed to load image'The error fallback text.
loadingIndicatorSize'small' | 'large''small'The size of the loading indicator.
loadingIndicatorColorstring-The color of the loading indicator.
transitionnumber200The transition duration in milliseconds.
styleImageProps['style']-Additional styles to apply to the image.
containerStyleViewStyle-Additional styles to apply to the container.
onLoadStart() => void-Callback when image starts loading.
onLoadEnd() => void-Callback when image finishes loading.
onError() => void-Callback when image fails to load.

Content Fit Options

The contentFit prop accepts the following values:

  • 'cover' - Scale the image to cover the entire container
  • 'contain' - Scale the image to fit within the container
  • 'fill' - Stretch the image to fill the container
  • 'none' - Display the image at its natural size
  • 'scale-down' - Scale down the image if it's larger than the container

Accessibility

The Image component is built with accessibility in mind:

  • Supports accessibilityLabel for screen readers
  • Error fallback provides alternative content when images fail to load
  • Loading indicators communicate loading state to assistive technologies
  • Proper semantic structure for better navigation

Performance

The Image component uses Expo Image under the hood, which provides:

  • Automatic image caching
  • Optimized memory usage
  • Support for various image formats
  • Smooth transitions and loading states
  • Network-aware loading strategies