update canvas dimensions to use clientWidth and Height as opposed to BoundingClient, to avoid getting scaled information

This commit is contained in:
Maxwell Talbot
2022-07-14 13:08:11 +01:00
parent 45aec2db1c
commit fd1c00a995
2 changed files with 12 additions and 14 deletions

View File

@@ -104,8 +104,12 @@ export default function useRive(
* @returns Dimensions object.
*/
function getCanvasDimensions() {
const { width, height } =
containerRef.current?.getBoundingClientRect() ?? new DOMRect(0, 0, 0, 0);
// getBoundingClientRect returns the scaled width and height
// this will result in double scaling
// https://developer.mozilla.org/en-US/docs/Web/API/CSS_Object_Model/Determining_the_dimensions_of_elements
const width = containerRef.current?.clientWidth ?? 0;
const height = containerRef.current?.clientHeight ?? 0;
if (rive && options.fitCanvasToArtboardHeight) {
const { maxY, maxX } = rive.bounds;