A cross-platform image loader with stunning gradient loading patterns, smooth animations, and graceful error handling. Available for both Web and React Native with platform-specific optimizations.
Installation
npx shadcn@latest add https://rigidui.com/r/image-loader.json
Prerequisites First, ensure you have React Native Reusables properly set up. Follow the React Native Reusables Installation guide. Install required dependencies: npx expo install react-native-svg
Install Component npx shadcn@latest add https://rigidui.com/r/image-loader-rn.json
Usage
Web - Basic
Web - Advanced
React Native
Custom Colors
import { ImageLoader } from "@/components/image-loader"
export default function Gallery () {
return (
< ImageLoader
src = "https://example.com/image.jpg"
alt = "Description of the image"
width = { 400 }
height = { 300 }
/>
)
}
import { ImageLoader } from "@/components/image-loader"
function ProductImage () {
return (
< ImageLoader
src = "https://example.com/product.jpg"
alt = "Product showcase"
width = { 600 }
height = { 400 }
objectFit = "contain"
loading = "eager"
onLoad = { () => console . log ( 'Image loaded' ) }
onError = { ( e ) => console . error ( 'Image failed' , e ) }
fallbackComponent = {
< div className = "flex flex-col items-center justify-center" >
< p > Image unavailable </ p >
< button > Retry </ button >
</ div >
}
/>
)
}
import { ImageLoader } from "@/components/image-loader-rn"
import { View } from "react-native"
export default function ProfileScreen () {
return (
< View >
< ImageLoader
src = "https://example.com/avatar.jpg"
alt = "User avatar"
width = { 200 }
height = { 200 }
resizeMode = "cover"
className = "rounded-full"
/>
</ View >
)
}
import { ImageLoader } from "@/components/image-loader"
const brandColors = [
{
start: 'hsl(280, 100%, 70%)' ,
middle: 'hsl(230, 100%, 77%)' ,
end: 'hsl(180, 100%, 70%)'
},
{
start: 'hsl(43, 100%, 70%)' ,
middle: 'hsl(23, 100%, 77%)' ,
end: 'hsl(3, 100%, 70%)'
}
]
function BrandedGallery () {
return (
< ImageLoader
src = "/image.jpg"
alt = "Branded image"
width = { 400 }
height = { 300 }
customColors = { brandColors }
seed = { 42 } // Consistent pattern
/>
)
}
Features
Beautiful Loading States Dynamic gradient patterns with smooth animations provide visually appealing loading experiences.
Cross-Platform Available for both Web and React Native with platform-specific optimizations and native rendering.
Optimized Performance Lazy loading for web, native animations for React Native, and efficient pattern generation.
Responsive Design Automatically adapts to different screen sizes and container dimensions on all platforms.
Error Handling Graceful fallback states with customizable error components for failed image loads.
Smooth Animations Native Animated API for React Native and CSS transitions for web ensure buttery smooth fade-ins.
API Reference
ImageLoader (Web)
The source URL of the image to load
Alternative text for the image (required for accessibility)
Additional class names for styling
blurIntensity
string
default: "'blur(50px)'"
CSS blur filter intensity for the loading state
width
number | string
default: "400"
Width of the image container in pixels or CSS units
height
number | string
default: "300"
Height of the image container in pixels or CSS units
Custom component to display when image fails to load
Callback function called when image successfully loads
Callback function called when image fails to load
loading
'lazy' | 'eager'
default: "'lazy'"
Native browser loading behavior for the image
objectFit
'cover' | 'contain' | 'fill' | 'none' | 'scale-down'
default: "'cover'"
How the image should be resized to fit its container
Custom color combinations for the loading pattern type ColorCombination = {
start : string
middle ?: string
end : string
}
Seed value for generating consistent loading patterns
ImageLoader (React Native)
The source URL of the image to load
Alternative text for the image (required for accessibility)
NativeWind classes for styling
Width of the image container in pixels
Height of the image container in pixels
Custom component to display when image fails to load
Callback function called when image successfully loads
Callback function called when image fails to load
resizeMode
'cover' | 'contain' | 'stretch' | 'center'
default: "'cover'"
How the image should be resized to fit its container
Custom color combinations for the gradient loading pattern (uses hex colors)
Seed value for generating consistent loading patterns
Examples
Image Gallery
import { ImageLoader } from "@/components/image-loader"
function Gallery ({ images }) {
return (
< div className = "grid grid-cols-3 gap-4" >
{ images . map (( image , index ) => (
< ImageLoader
key = { image . id }
src = { image . url }
alt = { image . title }
width = { 300 }
height = { 300 }
objectFit = "cover"
seed = { index }
/>
)) }
</ div >
)
}
Hero Image
import { ImageLoader } from "@/components/image-loader"
function Hero () {
return (
< div className = "relative h-screen" >
< ImageLoader
src = "/hero-image.jpg"
alt = "Hero banner"
width = "100%"
height = "100vh"
objectFit = "cover"
loading = "eager"
className = "absolute inset-0"
/>
< div className = "relative z-10" >
< h1 > Welcome </ h1 >
</ div >
</ div >
)
}
Product Card
import { ImageLoader } from "@/components/image-loader"
import { Card } from "@/components/ui/card"
function ProductCard ({ product }) {
return (
< Card >
< ImageLoader
src = { product . imageUrl }
alt = { product . name }
width = { 300 }
height = { 200 }
objectFit = "contain"
fallbackComponent = {
< div className = "flex items-center justify-center h-full" >
< p > Image not available </ p >
</ div >
}
onError = { () => analytics . track ( 'image_load_failed' ) }
/>
< div className = "p-4" >
< h3 > { product . name } </ h3 >
< p > { product . price } </ p >
</ div >
</ Card >
)
}
Use the seed prop to ensure consistent loading patterns for the same image across page reloads, or leave it undefined for random patterns.
The loading pattern is generated using SVG gradients with fractal noise, creating a unique and visually appealing effect that’s different from traditional skeleton loaders.