Compare commits

...

26 Commits

Author SHA1 Message Date
Arthur Vivian
c3a061f8b0 some improvements 2021-09-10 12:01:04 +01:00
avivian
1c3cc69f40 chore: release 0.0.20 2021-09-07 14:15:50 +00:00
Arthur Vivian
44056eb565 rive-0.7.30: Fix ghosting where aspect ratio of canvas is different to that of artboard 2021-09-07 16:14:51 +02:00
avivian
a9c3233452 chore: release 0.0.19 2021-09-07 09:44:52 +00:00
Arthur Vivian
ce2c7065f5 Update rive-js to 0.7.29 2021-09-07 11:43:21 +02:00
avivian
203faf9ce2 chore: release 0.0.18 2021-08-12 12:40:56 +00:00
Arthur Vivian
fd0efb1b81 Update rive-js version to 0.7.25 2021-08-12 13:40:11 +01:00
avivian
11b6f2e879 chore: release 0.0.17 2021-08-12 08:26:20 +00:00
Arthur Vivian
8a1adf147d Update rive-js version to 0.7.24 2021-08-12 09:25:34 +01:00
avivian
80ffb5ee2d chore: release 0.0.16 2021-08-11 15:26:22 +00:00
Arthur Vivian
cf1baa6661 Update rive-js version to 0.7.23 2021-08-11 16:25:30 +01:00
avivian
f0b1aeb7d8 chore: release 0.0.15 2021-07-30 09:32:03 +00:00
Arthur Vivian
8612e0b15f update rive-js with support for distance and transform constraints 2021-07-30 10:31:19 +01:00
avivian
d7f7eab655 chore: release 0.0.14 2021-07-21 08:47:12 +00:00
Arthur Vivian
29bd502208 chore: bump to 0.0.13 2021-07-21 09:46:24 +01:00
Arthur Vivian
7266fc5d2f chore: bump to 0.0.12 2021-07-21 09:25:36 +01:00
Arthur Vivian
6c80c5311e Bump rive-js to 0.7.19 with support for IK constraints 2021-07-21 09:03:37 +01:00
umberto-sonnino
9db4ee52bf chore: release 0.0.11 2021-07-14 15:57:41 +00:00
Umberto Sonnino
67a955e11b Merge pull request #26 from rive-app/camelCaseParams
Update README with camelCase params
2021-07-14 16:56:50 +01:00
Umberto Sonnino
14b774676b Update README with camel case params 2021-07-12 12:03:04 +01:00
avivian
0b14c4cd4c chore: release 0.0.10 2021-06-28 15:10:18 +00:00
Arthur Vivian
59e8855f51 Merge pull request #23 from rive-app/build-fix
Include types in npm publish
2021-06-28 16:09:34 +01:00
Arthur Vivian
7bd5178ab4 Include types in npm publish 2021-06-28 16:07:50 +01:00
avivian
2ec726cf12 chore: release 0.0.9 2021-06-28 14:55:14 +00:00
Arthur Vivian
4285908928 Merge pull request #22 from rive-app/build-fix
Fix build automation and only include dist files
2021-06-28 15:54:27 +01:00
Arthur Vivian
35bf459ea5 Fix build automation and only include dist files 2021-06-28 15:53:41 +01:00
11 changed files with 79 additions and 39 deletions

View File

@@ -22,7 +22,7 @@ jobs:
- name: Run Tests
run: npm test
- name: Build
run: npm build
run: npm run build
- name: Git config
run: |
git config --local user.email 'hello@rive.app'

View File

@@ -9,7 +9,7 @@
},
"github": {
"release": true,
"releaseName": "Release ${version}"
"releaseName": "${version}"
},
"hooks": {
"after:bump": "npx auto-changelog -p"

View File

@@ -4,6 +4,6 @@ All notable changes to this project will be documented in this file. Dates are d
Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
#### 0.0.8
#### 0.0.20
- Add release it dependency [`#21`](https://github.com/rive-app/rive-react/pull/21)
- rive-0.7.30: Fix ghosting where aspect ratio of canvas is different to that of artboard [`44056eb`](https://github.com/rive-app/rive-react/commit/44056eb5654e90de6ba10ed4892a4e2a5ebf6716)

View File

@@ -94,13 +94,13 @@ export default Example;
- `stateMachines?`: _(optional)_ Name of list of names of state machines to load.
- `layout?`: _(optional)_ Layout object to define how animations are displayed on the canvas. See [Rive.js](https://github.com/rive-app/rive-wasm#layout) for more details.
- `autoplay?`: _(optional)_ If `true`, the animation will automatically start playing when loaded. Defaults to false.
- `onload?`: _(optional)_ Callback that get's fired when the .rive file loads .
- `onloaderror?`: _(optional)_ Callback that get's fired when an error occurs loading the .riv file.
- `onplay?`: _(optional)_ Callback that get's fired when the animation starts playing.
- `onpause?`: _(optional)_ Callback that get's fired when the animation pauses.
- `onstop?`: _(optional)_ Callback that get's fired when the animation stops playing.
- `onloop?`: _(optional)_ Callback that get's fired when the animation completes a loop.
- `onstatechange?`: _(optional)_ Callback that get's fired when a state change occurs.
- `onLoad?`: _(optional)_ Callback that get's fired when the .rive file loads .
- `onLoadError?`: _(optional)_ Callback that get's fired when an error occurs loading the .riv file.
- `onPlay?`: _(optional)_ Callback that get's fired when the animation starts playing.
- `onPause?`: _(optional)_ Callback that get's fired when the animation pauses.
- `onStop?`: _(optional)_ Callback that get's fired when the animation stops playing.
- `onLoop?`: _(optional)_ Callback that get's fired when the animation completes a loop.
- `onStateChange?`: _(optional)_ Callback that get's fired when a state change occurs.
#### opts
@@ -121,15 +121,19 @@ function Example() {
autoplay: true,
});
const onClickInput = useStateMachineInput(rive, 'button', 'onClick');
const onClickInput = useStateMachineInput({
rive: rive,
stateMachineName: 'button',
inputName: 'onClick',
});
return <RiveComponent onClick={() => onClickInput && onClickInput.fire())} />;
return <RiveComponent onClick={() => onClickInput && onClickInput.fire()} />;
}
export default Example;
```
#### Parameters
#### params
- `rive`: A `Rive` object. This is returned by the `useRive` hook.
- `stateMachineName`: Name of the state machine.

View File

@@ -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": "file:../..",
"web-vitals": "^1.1.2"
},
"scripts": {

View File

@@ -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>
);

16
package-lock.json generated
View File

@@ -1,6 +1,6 @@
{
"name": "rive-react",
"version": "0.0.8",
"version": "0.0.20",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@@ -6912,18 +6912,10 @@
"glob": "^7.1.3"
}
},
"rive-canvas": {
"version": "0.7.6",
"resolved": "https://registry.npmjs.org/rive-canvas/-/rive-canvas-0.7.6.tgz",
"integrity": "sha512-RoZocagAmHs3lhD8nYrpxMtNObMREqdL4kSk63dkQOrKRdtby/N8S9bWFXxPo1kMCZBQz50JiTy4+Ink7QpRLA=="
},
"rive-js": {
"version": "0.7.15",
"resolved": "https://registry.npmjs.org/rive-js/-/rive-js-0.7.15.tgz",
"integrity": "sha512-LM2/JCdwHu33SmAtPpKq3M6AiO7v5iK6h9TQTeT2Hpk1MB4JfWz1jceXhSSJwZ6Vj9zbDeuFJamOdHx5PpVQpA==",
"requires": {
"rive-canvas": "0.7.6"
}
"version": "0.7.30",
"resolved": "https://registry.npmjs.org/rive-js/-/rive-js-0.7.30.tgz",
"integrity": "sha512-9UqrpwqoaXCwEeLblfsnEZocf+s/OswJm10pjYI50uxYmFgKpbuyllIjW0XkQxJuWETXkhhUW+ESdhJ5lc1POA=="
},
"rollup": {
"version": "1.32.0",

View File

@@ -1,9 +1,12 @@
{
"name": "rive-react",
"version": "0.0.8",
"version": "0.0.20",
"description": "React wrapper around the rive-js library",
"main": "dist/index.js",
"typings": "dist/types/index.d.ts",
"files": [
"dist/**"
],
"scripts": {
"test": "jest",
"build": "bunchee src/index.ts -m --no-sourcemap",
@@ -23,7 +26,7 @@
},
"homepage": "https://github.com/rive-app/rive-react#readme",
"dependencies": {
"rive-js": "0.7.15"
"rive-js": "0.7.30"
},
"peerDependencies": {
"react": "^16.8.0 || ^17.0.0"

View File

@@ -6,7 +6,7 @@ import React, {
ComponentProps,
RefCallback,
} from 'react';
import { Rive, EventType } from 'rive-js';
import { Rive, EventType, StateMachineInputType } from 'rive-js';
import {
UseRiveParameters,
UseRiveOptions,
@@ -228,7 +228,34 @@ export default function useRive(
);
}, []);
const debug = useCallback(() => {
if (!rive) {
console.log({
loaded: false,
});
return;
}
const stateMachines = rive.stateMachineNames.map((stateMachineName) => ({
stateMachineName,
stateMachineInputs: (rive.stateMachineInputs(stateMachineName) ?? []).map(
(stateMachineInput) => ({
name: stateMachineInput.name,
value: stateMachineInput.value,
type: StateMachineInputType[stateMachineInput.type],
})
),
}));
console.log({
activeArtboard: rive.activeArtboard,
animationsNames: rive.animationNames,
stateMachines,
});
}, [rive]);
return {
debug,
canvas: canvasRef.current,
setCanvasRef,
setContainerRef,

View File

@@ -1,28 +1,29 @@
import { useState, useEffect } from 'react';
import { Rive, StateMachineInput } from 'rive-js';
import { UseStateMachineInputParameters } from '../types';
/**
* Custom hook for fetching a stateMachine input from a rive file.
*
* @param rive - Rive instance
* @param stateMachineName - Name of the state machine
* @param inputName - Name of the input
* @param params.rive - Rive Instance
* @param params.stateMachineName - Name of the state machine
* @param params.inputName - Name of the state machine input
* @returns
*/
export default function useStateMachineInput(
rive: Rive | null,
stateMachineName?: string,
inputName?: string
params: UseStateMachineInputParameters
) {
const [input, setInput] = useState<StateMachineInput | null>(null);
const { rive, stateMachineName, inputName } = params;
useEffect(() => {
if (!rive || !stateMachineName || !inputName) {
setInput(null);
}
if (rive && stateMachineName && inputName) {
const inputs = rive.stateMachineInputs(stateMachineName);
const inputs = (rive as Rive).stateMachineInputs(stateMachineName);
if (inputs) {
const selectedInput = inputs.find((input) => input.name === inputName);
setInput(selectedInput || null);

View File

@@ -1,6 +1,18 @@
import { RefCallback, ComponentProps } from 'react';
import { Rive, RiveParameters } from 'rive-js';
/**
* @typedef UseStateMachineInputParameters
* @property rive - Rive Instance
* @property stateMachineName - Name of the state machine
* @property inputName - Name of the input
*/
export type UseStateMachineInputParameters = {
rive: Rive | null;
stateMachineName?: string;
inputName?: string;
};
export type UseRiveParameters = Partial<Omit<RiveParameters, 'canvas'>> | null;
export type UseRiveOptions = {
@@ -24,6 +36,7 @@ export type Dimensions = {
* @property rive - The loaded Rive Animation
*/
export type RiveState = {
debug: () => void;
canvas: HTMLCanvasElement | null;
setCanvasRef: RefCallback<HTMLCanvasElement>;
setContainerRef: RefCallback<HTMLElement>;