Skip to content

Commit

Permalink
Update examples to use latest rive-react
Browse files Browse the repository at this point in the history
  • Loading branch information
avivian committed Sep 10, 2021
1 parent 1c3cc69 commit 5d08228
Show file tree
Hide file tree
Showing 38 changed files with 353 additions and 120 deletions.
2 changes: 1 addition & 1 deletion .release-it.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
"releaseName": "${version}"
},
"hooks": {
"after:bump": "npx auto-changelog -p"
"after:bump": ["npx auto-changelog -p", "git add ./CHANGELOG.md"]
}
}
20 changes: 15 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export default Example;

#### Parameters

- `riveParams`: Set of parameters that are passed to the Rive.js `Rive` class constructor. `null` and `undefined` can be passed to conditionally display the .rive file.
- `riveParams`: Set of parameters that are passed to the Rive.js `Rive` class constructor. `null` and `undefined` can be passed to conditionally display the .riv file.
- `opts`: Rive React specific options.

#### Return Values
Expand Down Expand Up @@ -115,20 +115,30 @@ The `useStateMachineInput` hook is provided to make it easier to interact with s
import { useRive, useStateMachineInput } from 'rive-react';

function Example() {
const STATE_MACHINE_NAME = 'button';
const INPUT_NAME = 'onClick';

const { RiveComponent, rive } = useRive({
src: 'button.riv',
stateMachines: 'button',
stateMachines: STATE_MACHINE_NAME,
autoplay: true,
});

const onClickInput = useStateMachineInput(rive, 'button', 'onClick');
const onClickInput = useStateMachineInput(
rive,
STATE_MACHINE_NAME,
INPUT_NAME
);

return <RiveComponent onClick={() => onClickInput && onClickInput.fire())} />;
// This example is using a state machine with a trigger input.
return <RiveComponent onClick={() => onClickInput.fire()} />;
}

export default Example;
```

See our [examples](examples) folder for working examples of [Boolean](examples/state-machine-boolean-input) and [Number](examples/state-machine-number-input) inputs.

#### Parameters

- `rive`: A `Rive` object. This is returned by the `useRive` hook.
Expand All @@ -141,4 +151,4 @@ A Rive.js `stateMachineInput` object.

## Examples

The `examples` shows a number of different ways to use Rive React. See the instructions for each example to run locally.
The [examples](examples) shows a number of different ways to use Rive React. See the instructions for each example to run locally.
2 changes: 1 addition & 1 deletion examples/basic-typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "4.0.3",
"rive-react": "0.0.1",
"rive-react": "latest",
"typescript": "^4.3.2",
"web-vitals": "^1.1.2"
},
Expand Down
6 changes: 3 additions & 3 deletions examples/basic-typescript/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { useRive, UseRiveParameters } from "rive-react";
import { useRive, UseRiveParameters } from 'rive-react';

function App() {
const params: UseRiveParameters = {
src: "poison-loader.riv",
src: 'poison-loader.riv',
autoplay: true,
};

const { RiveComponent } = useRive(params);

return (
// The animation will fit to the parent element.
<div style={{ height: "500px", width: "500px" }}>
<div style={{ height: '500px', width: '500px' }}>
<RiveComponent />
</div>
);
Expand Down
8 changes: 4 additions & 4 deletions examples/basic-typescript/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from "react";
import ReactDOM from "react-dom";
import App from "./App";
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';

ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById("root")
document.getElementById('root')
);
2 changes: 1 addition & 1 deletion examples/basic-with-hook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "4.0.3",
"rive-react": "0.0.1",
"rive-react": "latest",
"web-vitals": "^1.1.2"
},
"scripts": {
Expand Down
6 changes: 3 additions & 3 deletions examples/basic-with-hook/src/App.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { useRive } from "rive-react";
import { useRive } from 'rive-react';

function App() {
const params = {
src: "poison-loader.riv",
src: 'poison-loader.riv',
autoplay: true,
};

const { RiveComponent } = useRive(params);

return (
// The animation will fit to the parent element.
<div style={{ height: "500px", width: "500px" }}>
<div style={{ height: '500px', width: '500px' }}>
<RiveComponent />
</div>
);
Expand Down
8 changes: 4 additions & 4 deletions examples/basic-with-hook/src/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from "react";
import ReactDOM from "react-dom";
import App from "./App";
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';

ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById("root")
document.getElementById('root')
);
2 changes: 1 addition & 1 deletion examples/basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "4.0.3",
"rive-react": "0.0.1",
"rive-react": "latest",
"web-vitals": "^1.1.2"
},
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions examples/basic/src/App.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Rive from "rive-react";
import Rive from 'rive-react';

function App() {
return (
// The animation will fit to the parent element.
<div style={{ height: "500px", width: "500px" }}>
<div style={{ height: '500px', width: '500px' }}>
<Rive src="poison-loader.riv" autoplay />
</div>
);
Expand Down
8 changes: 4 additions & 4 deletions examples/basic/src/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from "react";
import ReactDOM from "react-dom";
import App from "./App";
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';

ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById("root")
document.getElementById('root')
);
2 changes: 1 addition & 1 deletion examples/play-on-hover/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "4.0.3",
"rive-react": "0.0.1",
"rive-react": "latest",
"web-vitals": "^1.1.2"
},
"scripts": {
Expand Down
6 changes: 3 additions & 3 deletions examples/play-on-hover/src/App.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useRive } from "rive-react";
import { useRive } from 'rive-react';

function App() {
const params = {
src: "poison-loader.riv",
src: 'poison-loader.riv',
autoplay: false,
};

Expand All @@ -23,7 +23,7 @@ function App() {
}

return (
<div style={{ height: "600px", width: "600px" }}>
<div style={{ height: '600px', width: '600px' }}>
<RiveComponent onMouseEnter={onMouseEnter} onMouseLeave={onMouseLeave} />
</div>
);
Expand Down
8 changes: 4 additions & 4 deletions examples/play-on-hover/src/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from "react";
import ReactDOM from "react-dom";
import App from "./App";
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';

ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById("root")
document.getElementById('root')
);
2 changes: 1 addition & 1 deletion examples/play-pause-button/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "4.0.3",
"rive-react": "0.0.1",
"rive-react": "latest",
"web-vitals": "^1.1.2"
},
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion examples/play-pause-button/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
name="description"
content="Web site created using create-react-app"
/>
<title>Rive React - Basic with Hook</title>
<title>Rive React - Play/Pause Button</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
Expand Down
18 changes: 9 additions & 9 deletions examples/play-pause-button/src/App.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import { useEffect, useState } from "react";
import { useRive } from "rive-react";
import { useEffect, useState } from 'react';
import { useRive } from 'rive-react';

function App() {
const [buttonText, setButtonText] = useState("Pause");
const [buttonText, setButtonText] = useState('Pause');
const { RiveComponent, rive } = useRive({
src: "poison-loader.riv",
src: 'poison-loader.riv',
autoplay: true,
});

useEffect(() => {
if (rive) {
// "play" event is fired when the animation starts to play, so we update
// button text on this event.
rive.on("play", () => {
setButtonText("Pause");
rive.on('play', () => {
setButtonText('Pause');
});

// As above, the "pause" event is fired when the animation pauses.
rive.on("pause", () => {
setButtonText("Play");
rive.on('pause', () => {
setButtonText('Play');
});
}
// We listen for changes to the rive object. The rive object will be null
Expand All @@ -40,7 +40,7 @@ function App() {
return (
// The animation will fit to the parent element, so we set a large height
// and width for this example.
<div style={{ height: "500px", width: "500px" }}>
<div style={{ height: '500px', width: '500px' }}>
<RiveComponent />
<button onClick={onButtonClick}>{buttonText}</button>
</div>
Expand Down
8 changes: 4 additions & 4 deletions examples/play-pause-button/src/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from "react";
import ReactDOM from "react-dom";
import App from "./App";
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';

ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById("root")
document.getElementById('root')
);
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# State Machine Button
# State Machine Boolean Input

This example shows how to interact with a state machine, using various onMouse\* callbacks to trigger transations.

Expand Down
36 changes: 36 additions & 0 deletions examples/state-machine-boolean-input/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "state-machine-boolean-input",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.13.0",
"@testing-library/react": "^11.2.7",
"@testing-library/user-event": "^12.8.3",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "4.0.3",
"rive-react": "latest",
"web-vitals": "^1.1.2"
},
"scripts": {
"start": "SKIP_PREFLIGHT_CHECK=true react-scripts start"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
17 changes: 17 additions & 0 deletions examples/state-machine-boolean-input/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<title>Rive React - State Machine Boolean Input</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
</body>
</html>

0 comments on commit 5d08228

Please sign in to comment.