RiveViewModel is the main class for controlling a RiveView. For most common Rive files, you should only need to interact with a RiveViewModel object.
Usage Guidelines
- Initialize with either an Animation name or a StateMachine name, but not both
- Only one will be used; if both are given, the StateMachine takes precedence
- Default StateMachine or Animation from the file can be used by leaving their parameters
nil
Initializers
Initialize with RiveModel and State Machine
The RiveModel instance containing the Rive file data
The name of the state machine to use. Pass
nil to use the default state machineHow the Rive content should fit within the view bounds
How the Rive content should align within the view bounds
Whether the animation or state machine should start playing automatically
The name of the artboard to use. Pass
nil to use the default artboardInitialize with RiveModel and Animation
The RiveModel instance containing the Rive file data
The name of the animation to play. Pass
nil to use the default animationHow the Rive content should fit within the view bounds
How the Rive content should align within the view bounds
Whether the animation should start playing automatically
The name of the artboard to use. Pass
nil to use the default artboardInitialize with File Name and State Machine
The name of the Rive file (without extension)
The file extension
The bundle containing the Rive file
The name of the state machine to use. Pass
nil to use the default state machineHow the Rive content should fit within the view bounds
How the Rive content should align within the view bounds
Whether the state machine should start playing automatically
The name of the artboard to use. Pass
nil to use the default artboardWhether to load assets from CDN
Custom asset loader for loading external assets
Initialize with File Name and Animation
The name of the Rive file (without extension)
The file extension
The bundle containing the Rive file
The name of the animation to play. Pass
nil to use the default animationHow the Rive content should fit within the view bounds
How the Rive content should align within the view bounds
Whether the animation should start playing automatically
The name of the artboard to use. Pass
nil to use the default artboardPreferred frames per second for the animation
Whether to load assets from CDN
Custom asset loader for loading external assets
Initialize with Web URL and State Machine
The URL of the Rive file to load from the web
The name of the state machine to use. Pass
nil to use the default state machineHow the Rive content should fit within the view bounds
How the Rive content should align within the view bounds
Whether the state machine should start playing automatically
Whether to load assets from CDN
The name of the artboard to use. Pass
nil to use the default artboardInitialize with Web URL and Animation
The URL of the Rive file to load from the web
The name of the animation to play. Pass
nil to use the default animationHow the Rive content should fit within the view bounds
How the Rive content should align within the view bounds
Whether the animation should start playing automatically
Whether to load assets from CDN
The name of the artboard to use. Pass
nil to use the default artboardProperties
riveModel
isPlaying
true if the animation or state machine is currently playing.
autoPlay
fit
.contain.
alignment
.center.
layoutScaleFactor
layout fit. By default, this value is -1, where Rive will determine the correct scale for your device. To override this default behavior, set this value to a value greater than 0.
If the scale factor is less than or equal to 0, nothing will be drawn.
forwardsListenerEvents
true, touch/click events will be forwarded to any next responder(s). When false, only the Rive view will handle touch/click events. Defaults to false.
On iOS, this is handled separately from
isExclusiveTouch.layoutScaleFactorAutomatic
Methods
play
The name of a new Animation to play on the current Artboard
The loop mode for the active Animation
The playback direction for the active Animation
pause
stop
reset
configureModel
RiveView.
The name of the artboard to configure. Pass
nil to use the current or default artboardThe name of the state machine to configure. Pass
nil to use defaultThe name of the animation to configure. Pass
nil to use defaultresetToDefaultModel
triggerInput
Trigger input.
The name of a
Trigger input on the active StateMachinetriggerInput (with path)
Trigger input.
The name of a
Trigger input on the active StateMachineA String representing the path to the nested artboard delimited by ”/” (e.g., “Nested” or “Level1/Level2/Level3”)
setInput (Boolean)
Boolean input.
The name of a
Boolean input on the active StateMachineA Bool value for the input
setInput (Boolean with path)
Boolean input.
The name of a
Boolean input on the active StateMachineA Bool value for the input
A String representing the path to the nested artboard delimited by ”/”
setInput (Float)
Number input.
The name of a
Number input on the active StateMachineA Float value for the input
setInput (Float with path)
Number input.
The name of a
Number input on the active StateMachineA Float value for the input
A String representing the path to the nested artboard delimited by ”/”
setInput (Double)
Number input.
The name of a
Number input on the active StateMachineA Double value for the input
setInput (Double with path)
Number input.
The name of a
Number input on the active StateMachineA Double value for the input
A String representing the path to the nested artboard delimited by ”/”
boolInput
.value on the returned object.
The name of the input
nil if the input cannot be found.
Example:
numberInput
.value on the returned object.
The name of the input
nil if the input cannot be found.
Example:
getTextRunValue
The name of a
Text Run on the active ArtboardgetTextRunValue (with path)
The name of a
Text Run on the active ArtboardThe path to the nested text run
setTextRunValue
The name of a
Text Run on the active ArtboardA String value for the text run
setTextRunValue (with path)
The name of a
Text Run on the active ArtboardThe path to the nested text run
A String value for the text run
If the specified path is empty, the parent artboard will be used to find the text run.
artboardNames
setPreferredFramesPerSecond
Integer number of seconds to set preferred FPS at
setPreferredFrameRateRange
Frame rate range to set
createRiveView
RiveView for the instance property with data from model which will replace any previous RiveView. This is called when first drawing a RiveViewRepresentable.
Returns: Reference to the new view that the RiveViewModel will be maintaining.
Example:
setRiveView
The RiveView to register
update
RiveView. This is called in the process of re-displaying RiveViewRepresentable.
The
RiveView that will be updatedderegisterView
RiveView.
Example:
view
View.
Returns: A SwiftUI AnyView wrapping the RiveView.
Example:
setView
RiveView that was created elsewhere. Does not need to be called when updating an already configured RiveView. Useful for attaching views created in a UIViewController or Storyboard.
The
RiveView that this RiveViewModel will maintainDelegate Methods
The following delegate methods can be implemented by conforming toRiveFileDelegate, RiveStateMachineDelegate, and RivePlayerDelegate: