RiveViewModel
will automatically play the animation or state machine you've given it.riveAnimation
propertyplay
, pause
and stop
methods, either passing in the names of the animations you want to affect or passing in nothing which will affect all instanced animations.onLoad
when a rive file has been loaded and initialized; it's now ready for playbackonPlay
when one or more animations play; provides a list of animationsonPause
when one or more animations pause; provides a list of animationsonStop
when one or more animations are stopped; provides a list of animationsonLoop
when an animation loops; provides the animation namerive
object returned from the useRive
hook to invoke playback controls.
See the example below here: https://codesandbox.io/s/animation-playback-controls-rive-react-7yo76i
riv-animation
directive:speed
is negative, the animation goes in reverse.riv-player
directive:time
input will let you specify a moment in ms in the animation.mode
input will force the mode "one-shot", "loop" or "ping-pong" (if undefined, default mode is used).riv-node
, riv-bone
& riv-root-bone
directives :ref
on the Rive component rendered. Once the ref
is populated, you can trigger functions such as play
, pause
, etc. See the ref
method docs for React Native here.
RiveAnimation
widget, it creates and manages controllers for each.RiveAnimationController
for each animation and pass the controller to the RiveAnimation
widget instead of its name. You can mix and match passing in controllers and names, but avoid passing in both for the same animation.isActive
property of SimpleAnimation
is used to play and pause a single animation.onStart
and onStop
that will fire when the animation starts and stops playing respectively.idle
and curves
animations are managed by the runtime and their looping animations will play continuously. bounce
is a one-shot and is triggered when the button is tapped. The runtime will then play the bounce
animation, mixing it cleanly with the looping animations.RiveViewModel
to display, you can invoke animation playback control methods on a reference to this view model.play(animationName: String? = nil, loop: Loop = .autoLoop, direction: Direction = .autoDirection)
animationName
- Name of the animation to playloop
- Loop mode to play the animation in. Possible values listed below:oneShot
- plays animation through onceloop
- plays through animation and repeats from the set starting timepingPong
- plays animation from start -> end, then end -> start on repeatautoLoop
(default) - plays through the loop setting set on the animationdirection
- Direction to play the animation inbackwards
- plays through animation timeline backwardforwards
- plays through animation timeline forwardsautoDirection
- plays through direction set on the animationpause()
stop()
reset()
RiveViewModel
. You can use delegates to define functions that hook into when certain playback events are invoked. See the below class for how you can hook into the following playback events: