From bb078296d0d694e5b6db0271bac52b207c5094ec Mon Sep 17 00:00:00 2001 From: CI Date: Wed, 30 Oct 2024 22:17:29 +0100 Subject: [PATCH] fix: account for scale factor in layout resizing --- src/hooks/useRive.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/hooks/useRive.tsx b/src/hooks/useRive.tsx index b2dfd5f..e430fc5 100644 --- a/src/hooks/useRive.tsx +++ b/src/hooks/useRive.tsx @@ -85,10 +85,11 @@ export default function useRive( if (rive) { if (rive.layout && rive.layout.fit === Fit.Layout) { if (canvasElem) { + const resizeFactor = devicePixelRatio * rive.layout.layoutScaleFactor; // TODO (Gordon): expose these are properties on JS runtime (rive as any)._devicePixelRatioUsed = devicePixelRatio; - (rive as any).artboard.width = canvasElem?.width / devicePixelRatio; - (rive as any).artboard.height = canvasElem?.height / devicePixelRatio; + (rive as any).artboard.width = canvasElem?.width / resizeFactor; + (rive as any).artboard.height = canvasElem?.height / resizeFactor; } }