jptrinh
February 13, 2024, 9:42am
1
Hey!
I was exploring some fun stuff with Rive . I can load the library with the NPM plugin, initialize the animation and interact with it.
But any idea on how I should handle it so that it reflects the state a specific component in a list for instance? (on load and on change)
greg
February 23, 2024, 12:10pm
2
Hi Jean-Philippe,
I’m not able to help you with your question but I think you might be able to help me with mine. I’m trying to get Rive working in WeWeb and I’ve been unsuccessful. Could you send me a loom to show how you got this working?
A RIVE plugin for WeWeb would be pretty awesome.
1 Like
jptrinh
February 25, 2024, 9:26am
4
I’m sure there are way to make it simplier. But here is how I’ve made it work (mostly by reading Rive documentation).
Add the Rive package with NPM plugin
Add an HTML Embed that contains the canvas where the animation will be
<canvas class="like-button" width="80" height="80"></canvas>
Add trigger on page load to initialize Rive instances with custom JS
const buttons = wwLib.getFrontDocument().querySelectorAll('.like-button');
buttons.forEach((button, index) => {
const r = new pluginVariables[/* @rive-app/canvas */ '69d4a5bb-09a3-4f3d-a94e-667c21c057eb']['@rive-app/canvas'].Rive({
src: "your-file.riv",
canvas: button,
autoplay: true,
stateMachines: "State Machine 1",
onLoad: (_) => {
r.resizeDrawingSurfaceToCanvas();
const inputs = r.stateMachineInputs('State Machine 1');
const trigger = inputs.find(i => i.name === 'Like');
button.onclick = () => trigger.value = !trigger.value;
}
});
});
Use the Rive method from the package from the initialization
I’ve looped all the buttons on my page because I wanted to add that to a list of cards
The onLoad callback is to set the triggers, the configuration depends on your animation inputs
greg
March 1, 2024, 1:38pm
5
Thanks so much for this @jptrinh . It’s pretty similar to what I did but there must have been something off in my config.
Thanks!