Skip to content

Commit

Permalink
Fix: Intake JS runtime patches for starting animation frames
Browse files Browse the repository at this point in the history
  • Loading branch information
zplata committed Jun 27, 2022
1 parent 8b43a82 commit 3477afd
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
40 changes: 39 additions & 1 deletion examples/stories/AnimationPlayback.stories.mdx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState } from 'react';
import { useEffect, useRef, useState } from 'react';

import { Canvas, Meta, Story, ArgsTable } from '@storybook/addon-docs';

Expand Down Expand Up @@ -54,6 +54,44 @@ The example below shows how to start with a Rive instance that does not autoplay
</Story>
</Canvas>

<Canvas withSource="open">
<Story name="Play/pause with intersection observer">
{() => {
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 (
<div ref={ref} className="center">
<RiveComponent className="base-canvas-size" />
</div>
);
}}
</Story>
</Canvas>

## 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.
Expand Down
Binary file added examples/stories/assets/baseball.riv
Binary file not shown.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 3477afd

Please sign in to comment.