Image
The Image component provides a performant image loading experience with built-in placeholder effects and smooth fade-in animations powered by Reanimated 3.
import { Image } from '@truongdq01/ui';
<Image source={{ uri: 'https://example.com/image.jpg' }} style={{ width: 200, height: 200 }} showPlaceholder/>;| Prop | Type | Default | Description |
|---|---|---|---|
source | ImageSourcePropType | — | Required. Image source (URI, require, or bundle) |
showPlaceholder | boolean | true | Show skeleton loading effect while fetching |
style | StyleProp<ImageStyle> | — | Container and image style |
onLoad | (e: ImageLoadEventData) => void | — | Callback when image loads successfully |
onError | (e: ImageErrorEventData) => void | — | Callback when image fails to load |
resizeMode | "cover" | "contain" | "stretch" | "repeat" | "center" | "cover" | How to resize the image |
accessibilityLabel | string | — | Alt text for screen readers |
accessibilityHint | string | — | Additional screen reader context |
testID | string | — | Test identifier for automation |
All other props from React Native’s ImageProps are supported.
Examples
Section titled “Examples”Basic Image
Section titled “Basic Image”<Image source={{ uri: 'https://picsum.photos/400/300' }} style={{ width: 400, height: 300 }}/>With Placeholder Disabled
Section titled “With Placeholder Disabled”<Image source={{ uri: 'https://picsum.photos/400/300' }} style={{ width: 400, height: 300 }} showPlaceholder={false}/>Circular Avatar
Section titled “Circular Avatar”<Image source={{ uri: 'https://example.com/avatar.jpg' }} style={{ width: 80, height: 80, borderRadius: 40 }}/>Responsive Image
Section titled “Responsive Image”<Image source={{ uri: 'https://example.com/hero.jpg' }} style={{ width: '100%', height: 200 }} resizeMode="cover"/>With Error Handling
Section titled “With Error Handling”<Image source={{ uri: 'https://invalid-url.com/image.jpg' }} style={{ width: 200, height: 200 }} onError={(e) => console.log('Image failed to load', e.nativeEvent.error)}/>Features
Section titled “Features”✨ Automatic Fade-In
Section titled “✨ Automatic Fade-In”Images smoothly fade in over 300ms when loaded, creating a polished user experience.
🦴 Skeleton Placeholder
Section titled “🦴 Skeleton Placeholder”When showPlaceholder is enabled (default), a skeleton effect shows while the image is fetching.
⚡ Performance Optimized
Section titled “⚡ Performance Optimized”- Uses Reanimated 3 for 60fps animations
- Animations run on the UI thread
- No jank or frame drops
Best Practices
Section titled “Best Practices”Always Provide Accessibility Labels
Section titled “Always Provide Accessibility Labels”<Image source={{ uri: product.image }} style={{ width: 200, height: 200 }} accessibilityLabel={`Product: ${product.name}`} accessibilityHint="Tap to view product details"/>Use Appropriate Resize Modes
Section titled “Use Appropriate Resize Modes”| Use Case | Resize Mode |
|---|---|
| Product cards, avatars | cover (default) |
| Full image display | contain |
| Background patterns | repeat |
| Thumbnails | cover |
Optimize Image Sources
Section titled “Optimize Image Sources”// ✅ Good: Use appropriately sized images<Image source={{ uri: "https://example.com/image-400x300.jpg" }} style={{ width: 200, height: 150 }}/>
// ❌ Avoid: Loading large images for small displays<Image source={{ uri: "https://example.com/image-2000x1500.jpg" }} style={{ width: 200, height: 150 }}/>Troubleshooting
Section titled “Troubleshooting”Image Not Showing
Section titled “Image Not Showing”- Check that
sourceis properly formatted - Verify the image URL is accessible
- Ensure width and height are set (or parent has dimensions)
- Check
onErrorcallback for loading failures
Placeholder Not Working
Section titled “Placeholder Not Working”- Ensure
showPlaceholderistrue(default) - Check that the image is actually loading (network request)
- Verify the component has a defined size