-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add runtime layout fit type for ios, android, web
First steps towards supporting artboard resizing in our runtimes. This PR includes: - New Fit type `autoResizeArtboard`. After a bit of back and forth, I think this keeps the API simple. - ScaleFactor which represents a scale value to scale the artboard by in addition to resizing (only applies with `autoResizeArtboard`). This may be useful because an artboard is created at a specific width/height, but it may be deployed to platforms where it is rendered to a much smaller or larger surface/texture. Currently the default is 1.0 (no scale), however, an alternative is to have it default to something like textureSize / artboardSize so we sort of auto normalize it. - Implemented on iOS. Once this is finalzed, we can work with DevRels to implement across all runtimes. - TODO : Bubble up an event when the artboard size is changed internally by the .riv https://github.com/user-attachments/assets/20e9fdda-5c3e-4f3f-b2f5-104ff0291fbe Diffs= e71b4cc081 feat: add runtime layout fit type for ios, android, web (#8341) Co-authored-by: CI <pggordonhayes@gmail.com> Co-authored-by: David Skuza <david@rive.app> Co-authored-by: Philip Chung <philterdesign@gmail.com>
- Loading branch information
1 parent
a2836ae
commit 7e555bb
Showing
25 changed files
with
434 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
c64659be84f36d2855173491d6bcab8255c50950 | ||
e71b4cc081aad43f304589d7233fe2d8065fda85 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Rive Layouts example | ||
|
||
This is an example showing Rive Layout - try adjusting the window size or zooming in/out. It uses the high-level JS/TS API from `rive-wasm` referencing the local build for `@rive-app/canvas`. | ||
|
||
This is accomplished by setting the `fit` to type `Fit.layout`, and updating the artboard size as the window changes. You can also adjust the `scaleFactor` in the `align` method to account for device pixel ratio, or to allow for zooming in/out of your graphics. | ||
|
||
## Install | ||
|
||
Run `npm i` | ||
|
||
## Run | ||
|
||
To run, make sure the `npm/canvas` build is built locally in `js/npm/canvas`. Run `./build.sh` from the `js` folder to build the WASM, and the JS bundler. This should give you a `rive.js` and `rive.wasm` file in the `npm/canvas` folder. | ||
|
||
Then run `npm start` in the root of this folder to run the parcel example and navigate to `http://localhost:1234` in the browser to check it out. |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Canvas Layout</title> | ||
<style> | ||
body { | ||
background: #f0f0f0; | ||
margin: 0; | ||
overflow: hidden; | ||
} | ||
|
||
canvas { | ||
background-color: red; | ||
display: block; | ||
width: 100vw; | ||
height: 100vh; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<canvas id="riveCanvas"></canvas> | ||
<script src="./index.ts"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import "regenerator-runtime"; | ||
import { Rive, Fit, Alignment, Layout } from "@rive-app/canvas"; | ||
import RiveLayoutTest from "/assets/layout_test.riv"; | ||
|
||
async function loadRiveFile() { | ||
return await (await fetch(new Request(RiveLayoutTest))).arrayBuffer(); | ||
} | ||
|
||
async function main() { | ||
setup(); | ||
} | ||
|
||
const riveCanvas = document.getElementById("riveCanvas") as HTMLCanvasElement; | ||
|
||
async function setup() { | ||
const bytes = await loadRiveFile(); | ||
|
||
const rive = new Rive({ | ||
buffer: bytes, | ||
autoplay: true, | ||
canvas: riveCanvas, | ||
layout: new Layout({ | ||
fit: Fit.Layout, | ||
alignment: Alignment.Center, | ||
// layoutScaleFactor: 2, // 2x scale of the layout, when using `Fit.Layout`. This allows you to resize the layout as needed. | ||
}), | ||
stateMachines: ["State Machine 1"], | ||
onLoad: () => { | ||
computeSize(); | ||
}, | ||
}); | ||
|
||
function computeSize() { | ||
rive.resizeDrawingSurfaceToCanvas(); | ||
} | ||
|
||
window.onresize = computeSize; | ||
|
||
window | ||
.matchMedia(`(resolution: ${window.devicePixelRatio}dppx)`) | ||
.addEventListener("change", computeSize); | ||
} | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "parcel_layout_example", | ||
"version": "1.0.0", | ||
"description": "", | ||
"private": true, | ||
"main": "src/index.js", | ||
"scripts": { | ||
"start": "parcel index.html", | ||
"build": "rm -fR docs && parcel build index.html -d docs --public-url ." | ||
}, | ||
"author": "", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"audio-play": "^2.3.1", | ||
"dat.gui": "^0.7.7", | ||
"parcel-bundler": "^1.12.5" | ||
}, | ||
"dependencies": { | ||
"@rive-app/canvas": "file:../../../npm/canvas_single", | ||
"parcel-plugin-asset-copier": "^1.1.0", | ||
"src": "^1.1.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Rive Layouts example | ||
|
||
This example uses the advanced runtime, and is built using parcel. | ||
This is an example showing Rive Layout - try adjusting the window size or zooming in/out. | ||
|
||
This is accomplished by setting the `fit` to type `Fit.layout`, and updating the artboard size as the window changes. You can also adjust the `scaleFactor` in the `align` method to account for device pixel ratio, or to allow for zooming in/out of your graphics. | ||
|
||
To run, at the top of the rive-wasm project: | ||
|
||
``` | ||
cd wasm | ||
./build_all_wasm.sh | ||
cd examples/layout | ||
npm i | ||
npm start | ||
``` | ||
|
||
You should now see the example running on http://localhost:1234. Parcel will pick up any changes made to the example html/css/js automatically, but you will need to rebuild wasm with `./build_all_wasm.sh` anytime you make changes to the wasm runtime. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<body> | ||
<canvas id="rive-canvas"></canvas> | ||
<script src="./index.ts"></script> | ||
</body> | ||
</html> |
Oops, something went wrong.