fix: account for scale factor in layout resizing

This commit is contained in:
CI
2024-10-30 22:17:29 +01:00
committed by Gordon
parent f9bad8b62d
commit bb078296d0

View File

@@ -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;
}
}