SkeletonLoader
A customizable loading placeholder component with various variants for different UI patterns.
SkeletonLoader
The SkeletonLoader component provides animated placeholders that can be used during content loading states. It supports different variants to match common UI patterns like lists, grids, articles, and chat interfaces.
Features
- Multiple Variants: Predefined layouts for list, grid, article, and chat interfaces
- Animated Opacity: Smooth opacity animation creates a pulsing effect
- Customizable Count: Render multiple skeleton items for list and grid variants
- Theming Support: Automatically adapts to light/dark mode
- Styling Control: Accepts additional Tailwind classes
Import
Props
Prop | Type | Default | Description |
---|---|---|---|
variant | 'list' | 'grid' | 'article' | 'chat' | Required | Type of skeleton layout to render |
count | number | 1 | Number of skeleton items to render (for list and grid variants) |
className | string | '' | Additional Tailwind classes |
Usage Examples
List Skeleton
Grid Skeleton
Article Skeleton
Chat Skeleton
Integration Examples
Product List Loading State
Image Gallery Loading State
Article Detail Loading State
Chat Screen Loading State
Variant Showcase
List Variant
The list variant creates a series of rows with a thumbnail on the left and text placeholders on the right, perfect for content lists:
This creates a skeleton that resembles:
- A square thumbnail (16x16)
- Two lines of text beside it (title and subtitle)
- Repeated for the number specified in
count
Grid Variant
The grid variant creates a grid of cards with image placeholders and text below, ideal for galleries or product grids:
This creates a skeleton that resembles:
- Square image placeholders arranged in a grid
- Two lines of text below each image
- Items fill 50% width (2 columns)
- Repeated for the number specified in
count
Article Variant
The article variant creates a single full-width image placeholder with text blocks below, perfect for article or product detail views:
This creates a skeleton that resembles:
- A large image placeholder at the top (full width)
- A title and subtitle placeholder
- Multiple paragraph text placeholders below
Chat Variant
The chat variant creates message bubbles alternating between left and right alignment, ideal for messaging interfaces:
This creates a skeleton that resembles:
- A message bubble aligned to the left
- A message bubble aligned to the right
- Another message bubble aligned to the left
Best Practices
Match Skeleton to Content
Choose a skeleton variant that closely resembles your actual content:
Control Loading States
Make sure to handle loading states and errors properly:
Combine with Pull-to-Refresh
Use the skeleton loader with pull-to-refresh functionality:
Implementation Details
The SkeletonLoader component uses React Native's Animated API to create a pulsing effect by interpolating opacity values. It renders different placeholder layouts based on the selected variant.
Each variant uses a combination of Animated.View components with specific dimensions and styles to mimic the appearance of actual content. The component adapts to the current theme using the useThemeColors
hook.
For list and grid variants, the component generates multiple placeholder items based on the count
prop. The article and chat variants ignore this prop as they represent single-view layouts.
Notes
- The skeleton animation automatically starts when the component mounts and stops when it unmounts
- For list and grid variants, each skeleton item has its own animation, creating a unified pulsing effect
- The component's background color automatically adapts to the current theme
- The size of grid items is fixed at 50% width (2 columns), but you can customize this with your own styling