mirror of
https://github.com/rive-app/rive-react.git
synced 2026-03-13 08:22:30 +08:00
use getBoundingClientRect to account for decimals in container size
This commit is contained in:
@@ -95,8 +95,9 @@ export default function useResizeCanvas({
|
||||
const { maxX, maxY } = artboardBounds ?? {};
|
||||
|
||||
const getContainerDimensions = useCallback(() => {
|
||||
const width = containerRef.current?.clientWidth ?? 0;
|
||||
const height = containerRef.current?.clientHeight ?? 0;
|
||||
const boundingBox = containerRef.current?.getBoundingClientRect();
|
||||
const width = Math.ceil(boundingBox?.width ?? 0);
|
||||
const height = Math.ceil(boundingBox?.height ?? 0);
|
||||
if (fitCanvasToArtboardHeight && artboardBounds) {
|
||||
const { maxY, maxX } = artboardBounds;
|
||||
return { width, height: width * (maxY / maxX) };
|
||||
|
||||
Reference in New Issue
Block a user