RiveFile class is the entry point for loading Rive animations in iOS. It represents a compiled .riv file containing artboards, animations, state machines, and assets.
Overview
A Rive file (.riv) is a binary format that contains all the graphics, animations, state machines, and interactive elements designed in the Rive editor. The RiveFile class provides methods to load these files from various sources and access their contents.
Loading a Rive File
From Bundle Resources
Load a.riv file from your app’s bundle:
From Raw Data
From HTTP URL
Load files asynchronously from a remote URL:Accessing Artboards
Once loaded, you can access artboards from the file:Version Information
Custom Asset Loading
Provide a custom asset loader for fonts, images, and audio:Using with RiveModel
For a higher-level interface, useRiveModel which wraps RiveFile:
Best Practices
Enable CDN loading for assets
Enable CDN loading for assets
Set
loadCdn: true when loading files to automatically fetch hosted assets like images and fonts from Rive’s CDN.Handle errors gracefully
Handle errors gracefully
Always use do-catch blocks when loading Rive files to handle potential errors like missing files or malformed data.
Reuse RiveFile instances
Reuse RiveFile instances
A single
RiveFile instance can create multiple artboard instances, reducing memory usage and load times.Related Classes
- RiveArtboard - Access artboards from a RiveFile
- RiveModel - Higher-level wrapper around RiveFile
- RiveViewModel - SwiftUI integration with automatic file loading