Introduction
Components
- Accordion
- Action Sheet
- Alert
- Audio Player
- Audio Recorder
- Audio Waveform
- Avatar
- AvoidKeyboard
- Badge
- BottomSheet
- Button
- Camera
- Camera Preview
- Card
- Carousel
- Checkbox
- Collapsible
- Color Picker
- Combobox
- Date Picker
- File Picker
- Gallery
- Hello Wave
- Icon
- Image
- Input
- Input OTP
- Link
- MediaPicker
- Mode Toggle
- Onboarding
- ParallaxScrollView
- Picker
- Popover
- Progress
- Radio
- ScrollView
- SearchBar
- Separator
- Share
- Sheet
- Skeleton
- Spinner
- Switch
- Table
- Tabs
- Text
- Toast
- Toggle
- Video
- View
Charts
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
Gallery
Responsive
Content Fit
API Reference
Image
A responsive image component with loading states and error handling.
Prop | Type | Default | Description |
---|---|---|---|
source | ImageSource | - | The image source (required). |
full | boolean | true | Whether the image should fill its container. |
variant | 'rounded' | 'circle' | 'rounded' | The border radius variant. |
width | number | string | - | The width of the image. |
height | number | string | - | The height of the image. |
aspectRatio | number | - | The aspect ratio of the image. |
contentFit | ContentFit | 'cover' | How the image should fit within its bounds. |
showLoadingIndicator | boolean | true | Whether to show loading indicator. |
showErrorFallback | boolean | true | Whether to show error fallback. |
errorFallbackText | string | 'Failed to load image' | The error fallback text. |
loadingIndicatorSize | 'small' | 'large' | 'small' | The size of the loading indicator. |
loadingIndicatorColor | string | - | The color of the loading indicator. |
transition | number | 200 | The transition duration in milliseconds. |
style | ImageProps['style'] | - | Additional styles to apply to the image. |
containerStyle | ViewStyle | - | 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