From 6ba68fab9e5482a3ab2a92410ebb1b422db9ff9e Mon Sep 17 00:00:00 2001 From: Zach Plata Date: Tue, 12 Sep 2023 23:06:36 -0500 Subject: [PATCH] feature: Bump WASM dependency to support Rive Events --- examples/stories/StateMachineDocs.stories.mdx | 40 +++++++++++++++++- examples/stories/assets/rating_animation.riv | Bin 0 -> 16099 bytes package.json | 4 +- src/components/Rive.tsx | 14 ++++++ 4 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 examples/stories/assets/rating_animation.riv diff --git a/examples/stories/StateMachineDocs.stories.mdx b/examples/stories/StateMachineDocs.stories.mdx index b48d504..ab480eb 100644 --- a/examples/stories/StateMachineDocs.stories.mdx +++ b/examples/stories/StateMachineDocs.stories.mdx @@ -1,10 +1,14 @@ -import { useState } from 'react'; +import { useState, useEffect } from 'react'; import { Canvas, Meta, Story, ArgsTable } from '@storybook/addon-docs'; -import RiveComponent, { useRive, useStateMachineInput } from '../../src'; +import RiveComponent, { + EventType, + useRive, + useStateMachineInput, +} from '../../src'; import { Button } from './components/Button'; import './rive-overview.css'; @@ -160,3 +164,35 @@ Unlike the boolean and number inputs, you invoke the `.fire()` method on a trigg }} + +## Rive Events + +To listen for Rive Events reported during state machine play, use the `on` API to add an event listener. + + + + {() => { + const STATE_MACHINE_NAME = 'State Machine 1'; + const { rive, RiveComponent } = useRive({ + src: 'rating_animation.riv', + stateMachines: STATE_MACHINE_NAME, + autoplay: true, + automaticallyHandleEvents: true, + }); + useEffect(() => { + if (rive) { + rive.on(EventType.RiveEvent, onRiveEventReceived); + } + }, [rive]); + const onRiveEventReceived = (riveEvent) => { + console.log('Rive Event Fired', riveEvent); + }; + return ( +
+ +

Click on the 5 star!

+
+ ); + }} +
+
diff --git a/examples/stories/assets/rating_animation.riv b/examples/stories/assets/rating_animation.riv new file mode 100644 index 0000000000000000000000000000000000000000..36ac38020475c86bf7132d1b1eaf30c866c61457 GIT binary patch literal 16099 zcmeHOdyJIT6~Eu?4(kgR(9#`3ml1>5vV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