diff --git a/examples/stories/AnimationPlayback.stories.mdx b/examples/stories/AnimationPlayback.stories.mdx index bd36ad8..c2c4015 100644 --- a/examples/stories/AnimationPlayback.stories.mdx +++ b/examples/stories/AnimationPlayback.stories.mdx @@ -1,4 +1,4 @@ -import { useState } from 'react'; +import { useEffect, useRef, useState } from 'react'; import { Canvas, Meta, Story, ArgsTable } from '@storybook/addon-docs'; @@ -54,6 +54,44 @@ The example below shows how to start with a Rive instance that does not autoplay + + + {() => { + const ref = useRef(null); + const { rive, RiveComponent } = useRive({ + src: 'baseball.riv', + autoplay: false, + animations: "Hover" + }); + useEffect(() => { + const observer = new IntersectionObserver( + ([things]) => { + if (rive) { + if (things.isIntersecting) { + rive.play("Hover"); + } else { + rive.pause("Hover"); + } + } + }, + { + rootMargin: '0px', + threshold: 0.1, + } + ) + if (ref && ref.current) { + observer.observe(ref.current) + } + }, [rive]); + return ( +
+ +
+ ); + }} +
+
+ ## Play/pause with external elements This example shows how you can control Rive elements via user interaction outside of the canvas, such as other buttons. Here, the play/pause button will toggle whether or not to play or pause the Rive animation. diff --git a/examples/stories/assets/baseball.riv b/examples/stories/assets/baseball.riv new file mode 100644 index 0000000..a4f4980 Binary files /dev/null and b/examples/stories/assets/baseball.riv differ diff --git a/package.json b/package.json index 7ee585b..7027a18 100644 --- a/package.json +++ b/package.json @@ -29,8 +29,8 @@ }, "homepage": "https://github.com/rive-app/rive-react#readme", "dependencies": { - "@rive-app/canvas": "1.0.68", - "@rive-app/webgl": "1.0.65" + "@rive-app/canvas": "1.0.70", + "@rive-app/webgl": "1.0.67" }, "peerDependencies": { "react": "^16.8.0 || ^17.0.0 || ^18.0.0"