Skip to content

🎥 Make videos programmatically with React

Bump Rive Canvas

Jonny Burger9292bd633bf7
diff --git a/packages/docs/docs/rive/remotionrivecanvas.mdx b/packages/docs/docs/rive/remotionrivecanvas.mdx
index 57fc906ccd..760fb0ed5d 100644
--- a/packages/docs/docs/rive/remotionrivecanvas.mdx
+++ b/packages/docs/docs/rive/remotionrivecanvas.mdx
@@ -45,6 +45,19 @@ Either a `string` specifying the animation name, a `number` specifying the anima
A callback function that will be executed when the Rive Runtime is loaded. The argument callback is an object of type Rive `File`
+### `enableRiveAssetCdn?`<AvailableFrom v="4.0.181" />
+
+Whether to enable the Rive Asset CDN. Default is `true`.
+
+### `assetLoader?`<AvailableFrom v="4.0.181" />
+
+A custom asset loader. See [here](https://rive.app/community/doc/loading-assets/doct4wVHGPgC#handling-assets) for more information.
+
+:::note
+Memoize the assetLoader function using `useCallback`.
+You can type the function using `FileAssetLoader` from `@remotion/rive` (re-exported from `@rive-app/canvas-advanced`).
+:::
+
## Ref<AvailableFrom v="4.0.180" />
You can attach a ref to the component to access the Rive Canvas instance.
diff --git a/packages/rive/package.json b/packages/rive/package.json
index 41a576c05b..3ed9ba9997 100644
--- a/packages/rive/package.json
+++ b/packages/rive/package.json
@@ -20,7 +20,7 @@
"author": "Caleb Ojo, Jonny Burger",
"license": "See LICENSE.md",
"dependencies": {
- "@rive-app/canvas-advanced": "2.3.0",
+ "@rive-app/canvas-advanced": "2.19.3",
"remotion": "workspace:*"
},
"peerDependencies": {
diff --git a/packages/rive/src/RemotionRiveCanvas.tsx b/packages/rive/src/RemotionRiveCanvas.tsx
index c3441631e0..f4296580f9 100644
--- a/packages/rive/src/RemotionRiveCanvas.tsx
+++ b/packages/rive/src/RemotionRiveCanvas.tsx
@@ -2,6 +2,7 @@ import type {
Artboard,
CanvasRenderer,
File,
+ FileAssetLoader,
LinearAnimationInstance,
RiveCanvas,
} from '@rive-app/canvas-advanced';
@@ -35,6 +36,8 @@ interface RiveProps {
readonly artboard?: string | number;
readonly animation?: string | number;
readonly onLoad?: onLoadCallback | null;
+ readonly enableRiveAssetCdn?: boolean;
+ readonly assetLoader?: FileAssetLoader;
}
export type RiveCanvasRef = {
@@ -55,6 +58,8 @@ const RemotionRiveCanvasForwardRefFunction: React.ForwardRefRenderFunction<
artboard: artboardName,
animation: animationIndex,
onLoad = null,
+ assetLoader,
+ enableRiveAssetCdn = true,
},
ref,
) => {
@@ -100,7 +105,7 @@ const RemotionRiveCanvasForwardRefFunction: React.ForwardRefRenderFunction<
useEffect(() => {
riveCanvas({
locateFile: () =>
- 'https://unpkg.com/@rive-app/[email protected]/rive.wasm',
+ 'https://unpkg.com/@rive-app/[email protected]/rive.wasm',
})
.then((riveInstance) => {
setRiveCanvas(riveInstance);
@@ -122,35 +127,45 @@ const RemotionRiveCanvasForwardRefFunction: React.ForwardRefRenderFunction<
fetch(new Request(src))
.then((f) => f.arrayBuffer())
.then((b) => {
- riveCanvasInstance.load(new Uint8Array(b)).then((file) => {
- const artboard =
- typeof artboardName === 'string'
- ? file.artboardByName(artboardName)
- : typeof artboardName === 'number'
- ? file.artboardByIndex(artboardName)
- : file.defaultArtboard();
- const animation = new riveCanvasInstance.LinearAnimationInstance(
- typeof animationIndex === 'number'
- ? artboard.animationByIndex(animationIndex)
- : typeof animationIndex === 'string'
- ? artboard.animationByName(animationIndex)
- : artboard.animationByIndex(0),
- artboard,
- );
- setRive({
- animation,
- artboard,
- renderer,
+ riveCanvasInstance
+ .load(new Uint8Array(b), assetLoader, enableRiveAssetCdn)
+ .then((file) => {
+ const artboard =
+ typeof artboardName === 'string'
+ ? file.artboardByName(artboardName)
+ : typeof artboardName === 'number'
+ ? file.artboardByIndex(artboardName)
+ : file.defaultArtboard();
+ const animation = new riveCanvasInstance.LinearAnimationInstance(
+ typeof animationIndex === 'number'
+ ? artboard.animationByIndex(animationIndex)
+ : typeof animationIndex === 'string'
+ ? artboard.animationByName(animationIndex)
+ : artboard.animationByIndex(0),
+ artboard,
+ );
+ setRive({
+ animation,
+ artboard,
+ renderer,
+ });
+ if (onLoad) {
+ onLoad(file);
+ }
});
- if (onLoad) {
- onLoad(file);
- }
- });
})
.catch((newErr) => {
setError(newErr);
});
- }, [animationIndex, artboardName, riveCanvasInstance, src, onLoad]);
+ }, [
+ animationIndex,
+ artboardName,
+ riveCanvasInstance,
+ src,
+ onLoad,
+ assetLoader,
+ enableRiveAssetCdn,
+ ]);
React.useEffect(() => {
if (!riveCanvasInstance) {
diff --git a/packages/rive/src/index.ts b/packages/rive/src/index.ts
index d43a798929..f6e3093a35 100644
--- a/packages/rive/src/index.ts
+++ b/packages/rive/src/index.ts
@@ -1 +1,2 @@
+export type {FileAssetLoader} from '@rive-app/canvas-advanced';
export {RemotionRiveCanvas, RiveCanvasRef} from './RemotionRiveCanvas.js';
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 900d5b1a69..bf46df8540 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -1291,8 +1291,8 @@ importers:
packages/rive:
dependencies:
'@rive-app/canvas-advanced':
- specifier: 2.3.0
- version: 2.3.0
+ specifier: 2.19.3
+ version: 2.19.3
remotion:
specifier: workspace:*
version: link:../core
@@ -8117,6 +8117,10 @@ packages:
three: 0.158.0
zustand: 3.7.2([email protected])
+ /@rive-app/[email protected]:
+ resolution: {integrity: sha512-AcUsPH8ve7pV6QABN0ekwSpIJN0Fudjp+bqYxFUwbtXnE2wvoA0d2yzAtJeVwNQtFKboyfHovNgPIQ9tEdB4VA==}
+ dev: false
+
/@rive-app/[email protected]:
resolution: {integrity: sha512-JzgY8aSvWbuigoJ+8x1lHW8or0syQz8hxpRdPijkCCp/GJYRPvBstYdJPbHk2nbv5+BV+8Rv4zRw96wKFVsvKQ==}
dev: false