Skip to content

Commit 3063883

Browse files
committed
refactor: optimize fullscreen dimensions handling using visualViewport
1 parent d98f3f7 commit 3063883

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/components/d-fullscreen/DFullScreen.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,15 @@ export const DFullScreen: React.FC<DFullScreenProps> = props => {
1717
if (!divRef.current) return
1818

1919
window.addEventListener("resize", () => {
20-
divRef.current!!.style.height = window.innerHeight + "px";
21-
divRef.current!!.style.width = window.innerWidth + "px";
20+
const vw = Math.round(window.visualViewport?.width ?? window.innerWidth);
21+
const vh = Math.round(window.visualViewport?.height ?? window.innerHeight);
22+
divRef.current!!.style.height = vh + "px";
23+
divRef.current!!.style.width = vw + "px";
2224
})
23-
divRef.current!!.style.height = window.innerHeight + "px";
24-
divRef.current!!.style.width = window.innerWidth + "px";
25+
const vw = Math.round(window.visualViewport?.width ?? window.innerWidth);
26+
const vh = Math.round(window.visualViewport?.height ?? window.innerHeight);
27+
divRef.current!!.style.height = vh + "px";
28+
divRef.current!!.style.width = vw + "px";
2529
}, [divRef])
2630

2731
return <div {...mergeCode0Props("d-full-screen", props)} ref={divRef}>

0 commit comments

Comments
 (0)