mirror of
https://github.com/rive-app/rive-react.git
synced 2026-03-13 08:22:30 +08:00
Update animations on param change
This commit is contained in:
committed by
Arthur Vivian
parent
881e38fe6a
commit
b13413ba8b
@@ -165,7 +165,7 @@ export default function useRive(
|
||||
const setCanvasRef: RefCallback<HTMLCanvasElement> = useCallback(
|
||||
(canvas: HTMLCanvasElement | null) => {
|
||||
if (canvas && riveParams) {
|
||||
const {useOffscreenRenderer} = options;
|
||||
const { useOffscreenRenderer } = options;
|
||||
const r = new Rive({
|
||||
useOffscreenRenderer,
|
||||
...riveParams,
|
||||
@@ -224,6 +224,17 @@ export default function useRive(
|
||||
};
|
||||
}, [rive]);
|
||||
|
||||
/**
|
||||
* Listen for changes in the animations params
|
||||
*/
|
||||
const animations = riveParams?.animations;
|
||||
useEffect(() => {
|
||||
if (rive && animations) {
|
||||
rive.stop(rive.animationNames);
|
||||
rive.play(animations);
|
||||
}
|
||||
}, [animations, rive]);
|
||||
|
||||
const Component = useCallback((props: ComponentProps<'div'>): JSX.Element => {
|
||||
return (
|
||||
<RiveComponent
|
||||
|
||||
Reference in New Issue
Block a user