From 2a614851db236ff489be4c2cf596f17a953f3d61 Mon Sep 17 00:00:00 2001 From: Frudrax Cheng Date: Thu, 28 May 2026 10:39:29 +0800 Subject: [PATCH] Improve Android signature orientation detection --- src/components/SignatureOverlay.tsx | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/components/SignatureOverlay.tsx b/src/components/SignatureOverlay.tsx index ef7c1b1..c0b96bc 100644 --- a/src/components/SignatureOverlay.tsx +++ b/src/components/SignatureOverlay.tsx @@ -12,7 +12,10 @@ interface SignatureOverlayProps { const isLandscapeNow = () => typeof window !== 'undefined' && - (window.matchMedia('(orientation: landscape)').matches || window.innerWidth > window.innerHeight); + (window.matchMedia('(orientation: landscape)').matches || + window.innerWidth > window.innerHeight || + ((window.visualViewport?.width ?? 0) > (window.visualViewport?.height ?? 0)) || + Math.abs(window.screen.orientation?.angle ?? 0) % 180 === 90); function SignatureOverlay({ open, onCancel, onConfirm }: SignatureOverlayProps) { const padRef = useRef(null); @@ -32,10 +35,17 @@ function SignatureOverlay({ open, onCancel, onConfirm }: SignatureOverlayProps) } window.addEventListener('resize', update); window.addEventListener('orientationchange', update); + window.visualViewport?.addEventListener('resize', update); const orientation = (screen as Screen & { - orientation?: { lock?: (o: string) => Promise; unlock?: () => void }; + orientation?: { + lock?: (o: string) => Promise; + unlock?: () => void; + addEventListener?: (type: 'change', listener: () => void) => void; + removeEventListener?: (type: 'change', listener: () => void) => void; + }; }).orientation; + orientation?.addEventListener?.('change', update); if (orientation?.lock) { orientation.lock('landscape').catch(() => { // ignore; iOS Safari and most browsers refuse outside fullscreen @@ -53,6 +63,8 @@ function SignatureOverlay({ open, onCancel, onConfirm }: SignatureOverlayProps) } window.removeEventListener('resize', update); window.removeEventListener('orientationchange', update); + window.visualViewport?.removeEventListener('resize', update); + orientation?.removeEventListener?.('change', update); document.body.style.overflow = prevOverflow; orientation?.unlock?.(); };