View Model Data Binding Not Available in Export when used with State Machine
According to https://rive.app/docs/editor/data-binding/overview, the way to separate data and design in Rive is by using View Models for the data.
I have a Card Component with multiple instances that are used in a Grid Component, then the Grid is imported into an artboard and animated on a timeline, then added to a State Machine where there are multinple timelines (used as segments of an overall animation).
All the view models are connected up into the layout in cascading fashion as detailed in this video:
The animation plays as it was intended in Rive app, however, when I export and embed using:
import { useRive, useViewModel } from '@rive-app/react-canvas'
export function ReactComponentForRive() {
const { rive, RiveComponent } = useRive({
src: '/actual_animation_v5.riv',
stateMachines: 'SM',
autoplay: true,
autoBind: true,
});
return (
<YStack
width="100%"
height={600}
backgroundColor="$background"
borderRadius="$4"
overflow="hidden"
>
<RiveComponent />
</YStack>
)
}
The animation plays, but the component instances do not render the view model data. The strings, images, and numbers converted to strings all appear as the placeholder text from the layout items in the base component.
I have been able to access all the data from all the view models used in the animation programatically inside the Rive file from inside React, so the data has been exported, 100%.
It just isn’t binded when played in React. I have even tried setting the data fetched from the Rive file, but that was just out of curiosity and it didn’t have any effect.
If anyone has solved this problem previously or has caught wind of something that may work, let me know.
Otherwise, I’m going to have to ignore the advice in the article and animate a flat file or not use the state machine to tie together the animation segments and try to salvage the view model component approach.
I have a feeling it may be related to combining view models with the state machine, but this is my first time using Rive, so I’m still building a mental model.
Any help is appreciated.
Brian McDonough