rive-app / rive-react

React runtime for Rive
https://rive-app.github.io/rive-react
MIT License
808 stars 32 forks source link

Move sizing logic into useResizeCanvas hook and clean up utils file #182

Closed zplata closed 1 year ago

zplata commented 1 year ago

Currently, the resizing logic for scaling the canvas with its parent container size is encapsulated in the useRive hook. This change would allow that utility logic to be broken out into its own hook (exportable from this runtime package) for folks that are looking to use this logic with perhaps the plain JS runtime (in a React component), or consumers using the low-level JS runtime that need this kind of utility.

Also adding an optional shouldResizeCanvasToContainer flag in options (defaulted to true) to allow users to specify whether they want the canvas to use the resizing logic we have on the canvas. Useful if folks want to resize according to their own logic

This change also moves out all other hooks baked into our utils.ts file into their own hook files so things are a little more organized in source.