🎥 Make videos programmatically with React
add artboard and animation field
Jonny Burger46bc07eafc10
diff --git a/packages/docs/docs/rive/remotionrivecanvas.md b/packages/docs/docs/rive/remotionrivecanvas.mdindex c7b92b91c9..ebb4310be8 100644--- a/packages/docs/docs/rive/remotionrivecanvas.md+++ b/packages/docs/docs/rive/remotionrivecanvas.md@@ -17,21 +17,25 @@ a valid URL of the rive file to load. Can be a local file loaded using [`staticFOne of: `"contain" | "cover" | "fill" | "fit-height" | "none" | "scale-down" | "fit-width"`. Default is `"contain"`.-### `alignment`+### `alignment?`One of: `"center" | "bottom-center" | "bottom-left" | "bottom-right" | "center-left" | "center-right" | "top-center" | "top-left" | "top-right"`. Default is `"center"`.+### `artboard?`++Either a `string` specifying the artboard name, a `number` specifying the artboard index, otherwise the default artboard is being used.++### `animation?`++Either a `string` specifying the animation name, a `number` specifying the animation index, otherwise the default animation is being used.+## Example```tsx twoslashimport { RemotionRiveCanvas } from "@remotion/rive";function App() {- return (- <div>- <RemotionRiveCanvas src="https://example.com/myAnimation.riv" />- </div>- );+ return <RemotionRiveCanvas src="https://example.com/myAnimation.riv" />;}```diff --git a/packages/rive/package.json b/packages/rive/package.jsonindex fda4649a2c..9ae644b6bf 100644--- a/packages/rive/package.json+++ b/packages/rive/package.json@@ -6,7 +6,6 @@"types": "dist/cjs/index.d.ts","module": "dist/esm/index.mjs","scripts": {- "test": "echo \"Error: no test specified\" && exit 1","build": "rollup --config rollup.config.js && tsc -d","watch": "tsc -w"},diff --git a/packages/rive/src/RemotionRiveCanvas.tsx b/packages/rive/src/RemotionRiveCanvas.tsxindex 86173fc785..e55d20fcdc 100644--- a/packages/rive/src/RemotionRiveCanvas.tsx+++ b/packages/rive/src/RemotionRiveCanvas.tsx@@ -18,12 +18,16 @@ interface RiveProps {src: string;fit?: RemotionRiveCanvasFit;alignment?: RemotionRiveCanvasAlignment;+ artboard?: string | number;+ animation?: string | number;}export const RemotionRiveCanvas: React.FC<RiveProps> = ({src,fit = "contain",alignment = "center",+ artboard: artboardName,+ animation: animationIndex,}) => {const { width, fps, height } = useVideoConfig();const frame = useCurrentFrame();@@ -67,9 +71,18 @@ export const RemotionRiveCanvas: React.FC<RiveProps> = ({.then((f) => f.arrayBuffer()).then((b) => {riveCanvasInstance.load(new Uint8Array(b)).then((file) => {- const artboard = file.defaultArtboard();+ const artboard =+ typeof artboardName === "string"+ ? file.artboardByName(artboardName)+ : typeof artboardName === "number"+ ? file.artboardByIndex(artboardName)+ : file.defaultArtboard();const animation = new riveCanvasInstance.LinearAnimationInstance(- artboard.animationByIndex(0),+ typeof animationIndex === "number"+ ? artboard.animationByIndex(animationIndex)+ : typeof animationIndex === "string"+ ? artboard.animationByName(animationIndex)+ : artboard.animationByIndex(0),artboard);setRive({@@ -82,7 +95,7 @@ export const RemotionRiveCanvas: React.FC<RiveProps> = ({.catch((newErr) => {setError(newErr);});- }, [riveCanvasInstance, src]);+ }, [animationIndex, artboardName, riveCanvasInstance, src]);React.useEffect(() => {if (!riveCanvasInstance) {