Compare commits

..

6 Commits

Author SHA1 Message Date
Arthur Vivian
7c14d23da8 Add example of webgl issues 2021-12-15 17:41:28 +00:00
Arthur Vivian
bfbb8a59ee Update basic example to listen to changes in parent directory 2021-12-15 14:16:46 +00:00
avivian
5a19354ab3 chore: release 0.0.26 2021-11-16 14:15:27 +00:00
Arthur Vivian
c4dc027522 bump rive-js to0.7.33 2021-11-16 14:14:25 +00:00
avivian
e54a0d42d3 chore: release 0.0.25 2021-11-12 13:28:02 +00:00
Arthur Vivian
1a597943cb Update rive-js to 0.7.32 to fixed nested artboard speed 2021-11-12 13:27:17 +00:00
14 changed files with 2053 additions and 1336 deletions

View File

@@ -4,9 +4,9 @@ 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).
#### [v0.0.24](https://github.com/rive-app/rive-react/compare/v0.0.20...v0.0.24)
#### [v0.0.26](https://github.com/rive-app/rive-react/compare/v0.0.20...v0.0.26)
- Update package.json to version 2 [`a4777ec`](https://github.com/rive-app/rive-react/commit/a4777ec7e33ded6a3581c88f2e708f45f7ea1828)
- bump rive-js to0.7.33 [`c4dc027`](https://github.com/rive-app/rive-react/commit/c4dc027522502f6aaa0f85392a5e90396c8b719d)
#### [v0.0.20](https://github.com/rive-app/rive-react/compare/v0.0.19...v0.0.20)

View File

@@ -6,10 +6,10 @@
"@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": "file:../../node_modules/react",
"react-dom": "^17.0.2",
"react-scripts": "4.0.3",
"rive-react": "latest",
"rive-react": "file:../..",
"web-vitals": "^1.1.2"
},
"scripts": {

View File

Binary file not shown.

View File

@@ -1,11 +1,13 @@
import Rive from 'rive-react';
import SizeExample from './SizeExample';
import FlowerExample from './FlowerExample';
function App() {
return (
// The animation will fit to the parent element.
<div style={{ height: '500px', width: '500px' }}>
<Rive src="poison-loader.riv" autoplay />
</div>
<>
<SizeExample />
<FlowerExample />
</>
);
}

View File

@@ -0,0 +1,48 @@
import { useEffect, useState } from 'react';
import { useRive } from 'rive-react';
function FlowerExample() {
const { rive, canvas, RiveComponent } = useRive({
src: 'flower.riv',
artboard: 'Motion',
animations: 'Animation 1',
autoplay: true,
});
useEffect(() => {
console.log('change');
if (canvas) {
canvas.width = 200;
canvas.height = 200;
}
}, [canvas]);
function onLargerClick() {
if (rive && canvas) {
canvas.width = canvas.width + 50;
canvas.height = canvas.height + 50;
rive.resizeToCanvas();
}
}
function onSmallerClick() {
if (rive && canvas && canvas.width > 0) {
canvas.width = canvas.width - 50;
canvas.height = canvas.height - 50;
rive.resizeToCanvas();
}
}
return (
// The animation will fit to the parent element.
<>
<button onClick={onLargerClick}>Larger</button>
<button onClick={onSmallerClick}>Smaller</button>
<div>
<RiveComponent />
</div>
</>
);
}
export default FlowerExample;

View File

@@ -0,0 +1,48 @@
import { useEffect, useState } from 'react';
import { useRive } from 'rive-react';
function SizeExample() {
const { rive, canvas, RiveComponent } = useRive({
src: 'poison-loader.riv',
// artboard: 'Motion',
// animations: 'Animation 1',
autoplay: true,
});
useEffect(() => {
console.log('change');
if (canvas) {
canvas.width = 200;
canvas.height = 200;
}
}, [canvas]);
function onLargerClick() {
if (rive && canvas) {
canvas.width = canvas.width + 50;
canvas.height = canvas.height + 50;
rive.resizeToCanvas();
}
}
function onSmallerClick() {
if (rive && canvas && canvas.width > 0) {
canvas.width = canvas.width - 50;
canvas.height = canvas.height - 50;
rive.resizeToCanvas();
}
}
return (
// The animation will fit to the parent element.
<>
<button onClick={onLargerClick}>Larger</button>
<button onClick={onSmallerClick}>Smaller</button>
<div>
<RiveComponent />
</div>
</>
);
}
export default SizeExample;

3243
package-lock.json generated
View File

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
{
"name": "rive-react",
"version": "0.0.24",
"version": "0.0.26",
"description": "React wrapper around the rive-js library",
"main": "dist/index.js",
"typings": "dist/types/index.d.ts",
@@ -10,6 +10,7 @@
"scripts": {
"test": "jest",
"build": "bunchee src/index.ts -m --no-sourcemap",
"dev": "watch 'npm run build' src",
"lint": "eslint -c .eslintrc.js 'src/**/*{.ts,.tsx}'",
"format": "prettier --write src",
"types:check": "tsc --noEmit",
@@ -26,7 +27,7 @@
},
"homepage": "https://github.com/rive-app/rive-react#readme",
"dependencies": {
"rive-js": "0.7.31"
"@rive/webgl_single": "file:../rive-wasm/js/npm/webgl_single"
},
"peerDependencies": {
"react": "^16.8.0 || ^17.0.0"
@@ -41,7 +42,7 @@
"@typescript-eslint/eslint-plugin": "^4.26.0",
"@typescript-eslint/parser": "^4.26.0",
"auto-changelog": "^2.3.0",
"bunchee": "^1.6.0",
"bunchee": "^1.7.3",
"eslint": "^7.28.0",
"eslint-config-prettier": "^8.3.0",
"eslint-config-standard": "^16.0.3",
@@ -55,6 +56,7 @@
"react": "^17.0.2",
"react-dom": "^17.0.2",
"release-it": "^14.10.0",
"ts-jest": "^27.0.2"
"ts-jest": "^27.0.2",
"watch": "^1.0.2"
}
}

View File

@@ -1,4 +1,4 @@
import { Layout } from 'rive-js';
import { Layout } from '@rive/webgl_single';
import React, { ComponentProps } from 'react';
import useRive from '../hooks/useRive';

View File

@@ -6,7 +6,7 @@ import React, {
ComponentProps,
RefCallback,
} from 'react';
import { Rive, EventType } from 'rive-js';
import { Rive, EventType } from '@rive/webgl_single';
import {
UseRiveParameters,
UseRiveOptions,
@@ -125,11 +125,12 @@ export default function useRive(
containerRef.current.style.height = height + 'px';
}
if (options.useDevicePixelRatio) {
const dpr = window.devicePixelRatio || 1;
canvasRef.current.width = dpr * width;
canvasRef.current.height = dpr * height;
canvasRef.current.style.width = width + 'px';
canvasRef.current.style.height = height + 'px';
console.log('updating canvas width, height');
// const dpr = window.devicePixelRatio || 1;
// canvasRef.current.width = dpr * width;
// canvasRef.current.height = dpr * height;
// canvasRef.current.style.width = width + 'px';
// canvasRef.current.style.height = height + 'px';
} else {
canvasRef.current.width = width;
canvasRef.current.height = height;

View File

@@ -1,5 +1,5 @@
import { useState, useEffect } from 'react';
import { Rive, StateMachineInput } from 'rive-js';
import { Rive, StateMachineInput } from '@rive/webgl_single';
/**
* Custom hook for fetching a stateMachine input from a rive file.

View File

@@ -5,4 +5,4 @@ import useStateMachineInput from './hooks/useStateMachineInput';
export default Rive;
export { useRive, useStateMachineInput };
export { RiveState, UseRiveParameters, UseRiveOptions } from './types';
export * from 'rive-js';
export * from '@rive/webgl_single';

View File

@@ -1,5 +1,5 @@
import { RefCallback, ComponentProps } from 'react';
import { Rive, RiveParameters } from 'rive-js';
import { Rive, RiveParameters } from '@rive/webgl_single';
export type UseRiveParameters = Partial<Omit<RiveParameters, 'canvas'>> | null;

View File

@@ -6,6 +6,7 @@
"lib": ["esnext", "dom"],
"module": "commonjs",
"moduleResolution": "node",
"noImplicitAny": false,
"noFallthroughCasesInSwitch": true,
"noUnusedLocals": true,
"noUnusedParameters": true,