Using Reanimated (Recommended)
The easiest way to display animated images is with theuseAnimatedImageValue hook, which integrates seamlessly with React Native Reanimated.
Basic Usage
useAnimatedImageValue hook returns a shared value that:
- Starts as
nullwhile loading - Updates with a new
SkImageon every frame once loaded - Automatically loops the animation
Controlling Playback
Use a shared value to pause and resume the animation:Complete Example with State
Manual API
For advanced control, use theuseAnimatedImage hook which returns an SkAnimatedImage instance.
Loading Animated Images
SkAnimatedImage Methods
TheSkAnimatedImage instance provides several methods:
| Method | Returns | Description |
|---|---|---|
getCurrentFrame() | SkImage | Returns the current frame as a regular SkImage |
decodeNextFrame() | number | Decodes and advances to the next frame. Returns -1 if finished |
currentFrameDuration() | number | Returns the duration of the current frame in milliseconds |
getFrameCount() | number | Returns the total number of frames in the animation |
Manual Frame Control
Custom Animation Loop
Frame-by-Frame Control
Supported Formats
React Native Skia supports:- GIF - Animated GIF images
- WebP - Animated WebP images
- Variable frame durations
- Looping
- Transparency
Loading Animated Images
From Bundle
From Network
From Native Resources
Performance Considerations
Frame Rate
- Animations decode one frame at a time
- Heavy animations may impact performance
- Consider reducing frame count for better performance
- Use lower resolution animations when possible
Memory Usage
- Each frame is decoded on demand
- Large animations consume more memory
- Consider using video for long animations
- Monitor memory usage on lower-end devices
Optimization Tips
Common Patterns
Loading State
Multiple Animations
Conditional Playback
Troubleshooting
Animation Not Playing
- Ensure the image loaded successfully (check if not
null) - Verify the shared value for pausing is set correctly
- Check that the file is a valid animated format
Poor Performance
- Reduce animation dimensions
- Decrease frame count
- Lower frame rate
- Consider using video instead
- Use smaller file sizes
Memory Issues
- Unload animations when not visible
- Use conditional rendering
- Limit number of simultaneous animations
- Monitor device memory usage
See Also
- Images Overview - Loading and displaying static images
- Video - Video playback for longer animations
- Image Shaders - Using animated images as shaders