From 69a7e7e9acbf4c3dfdf14bba4e2e7ca7aab3d657 Mon Sep 17 00:00:00 2001 From: Qijia Liu Date: Tue, 2 Apr 2024 21:46:51 -0400 Subject: [PATCH] try fixing intermittent narrower window --- page/ux.ts | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/page/ux.ts b/page/ux.ts index 8f15348..f34708b 100644 --- a/page/ux.ts +++ b/page/ux.ts @@ -18,15 +18,22 @@ type ShadowBox = { } export function resize (dx: number, dy: number, dragging: boolean) { - const { - shadowTop, - shadowRight, - shadowBottom, - shadowLeft, - fullWidth, - fullHeight - } = getBoundingRectWithShadow(panel) - window._resize(dx, dy, shadowTop, shadowRight, shadowBottom, shadowLeft, fullWidth, fullHeight, dragging) + function adaptWindowSize () { + const { + shadowTop, + shadowRight, + shadowBottom, + shadowLeft, + fullWidth, + fullHeight + } = getBoundingRectWithShadow(panel) + window._resize(dx, dy, shadowTop, shadowRight, shadowBottom, shadowLeft, fullWidth, fullHeight, dragging) + } + adaptWindowSize() + if (!dragging) { + // Sometimes getBoundingClientRect is called when the element is not fully rendered. + window.requestAnimationFrame(adaptWindowSize) + } } function getBoundingRectWithShadow (element: Element): ShadowBox {