File

class File(bytes: ByteArray, val rendererType: RendererType = Rive.defaultRendererType, fileAssetLoader: FileAssetLoader? = null) : NativeObject

Files are created in the Rive editor.

This object has a counterpart in C++, which implements much of its functionality. The base class's cppPointer keeps track of this relationship.

You can export .riv from the editor and use this class to load them. Files may contain multiple artboards.

If the given file cannot be loaded this will throw a RiveException. The Rive File format is evolving, and while we attempt to keep backwards (and forwards) compatibility where possible, there are times when this is not possible.

The Rive editor will always export your file in the latest runtime format.

⚠️ Important: If you create a File yourself using this constructor, you are responsible for calling release when you are done with it, otherwise it will leak memory.

Parameters

bytes

The bytes of the .riv file.

rendererType

The RendererType to use when rendering this file. This defaults to Rive.defaultRendererType, which is RendererType.Rive.

fileAssetLoader

An optional FileAssetLoader to use when loading external assets (images, fonts, audio) referenced by this file. If it is not provided you will not be able to load external assets.

Constructors

Link copied to clipboard
constructor(bytes: ByteArray, rendererType: RendererType = Rive.defaultRendererType, fileAssetLoader: FileAssetLoader? = null)

Types

Link copied to clipboard
data class Enum(val name: String, val values: List<String>)

The name and values of an enum, whether system or user defined.

Properties

Link copied to clipboard

Get the number of artboards in the file. Useful for index-based iteration.

Link copied to clipboard

Get the names of the artboards in the file.

Link copied to clipboard

Getter/Setter for the underlying C++ pointer value.

Link copied to clipboard
Link copied to clipboard

The available enums in the file.

Link copied to clipboard

Get the first (i.e. the default) artboard in the file.

Link copied to clipboard

Whether this objects underlying pointer is still valid.

Link copied to clipboard

Public compatibility alias for fileLock.

Link copied to clipboard
open val refCount: Int
Link copied to clipboard
override var refs: AtomicInteger
Link copied to clipboard
Link copied to clipboard

The number of ViewModels in the file. Useful for index-based iteration.

Functions

Link copied to clipboard
open override fun acquire(): Int

Increments the references for this counter. Cannot be used for initialization - use refs.incrementAndGet instead.

Link copied to clipboard
fun artboard(index: Int): Artboard

Get the artboard at a given index in the File.

Get the artboard called name in the file.

Link copied to clipboard
open external override fun cppDelete(pointer: Long)
Link copied to clipboard

Create a BindableArtboard by name. This is can then be bound to a ViewModelArtboardProperty.

Link copied to clipboard

Create the default BindableArtboard, as marked in the Rive file. This is can then be bound to a ViewModelArtboardProperty.

Link copied to clipboard

Get the default ViewModel for an Artboard. Usually this will be the ViewModel intended for use with this artboard.

Link copied to clipboard
fun getViewModelByIndex(viewModelIdx: Int): ViewModel

Get the ViewModel definition from the file.

Link copied to clipboard
fun getViewModelByName(viewModelName: String): ViewModel

Get the ViewModel definition from the file.

Link copied to clipboard
open override fun release(): Int

Decrements the reference counter.