diff --git a/packages/nicolium/src/components/ui/layout.tsx b/packages/nicolium/src/components/ui/layout.tsx index 3eb99fa96..0f8c6964d 100644 --- a/packages/nicolium/src/components/ui/layout.tsx +++ b/packages/nicolium/src/components/ui/layout.tsx @@ -65,6 +65,26 @@ declare global { } } +const useWindowControlsOverlay = () => { + const getRect = (): DOMRect | null => { + const overlay = navigator.windowControlsOverlay; + return overlay?.visible ? overlay.getTitlebarAreaRect() : null; + }; + + const [rect, setRect] = useState(getRect); + + useEffect(() => { + const overlay = navigator.windowControlsOverlay; + if (!overlay) return; + + const update = () => setRect(overlay.visible ? overlay.getTitlebarAreaRect() : null); + overlay.addEventListener('geometrychange', update); + return () => overlay.removeEventListener('geometrychange', update); + }, []); + + return rect; +}; + /** Layout container, to hold Sidebar, Main, and Aside. */ const Layout: LayoutComponent = ({ children, fullWidth }) => (
@@ -81,6 +101,8 @@ const Layout: LayoutComponent = ({ children, fullWidth }) => ( /** Left sidebar container in the UI. */ const Sidebar: React.FC = ({ children, shrink }) => { const isVisible = useMinWidth(`(min-width: ${breakpoints.lg})`); + const wcoRect = useWindowControlsOverlay(); + const offsetTop = wcoRect && wcoRect.x > 0 ? 16 + wcoRect.y : 16; if (!isVisible) { return null; @@ -88,7 +110,7 @@ const Sidebar: React.FC = ({ children, shrink }) => { return (
- + {children}
@@ -117,13 +139,17 @@ const Main: React.FC> = ({ children, classN /** Right sidebar container in the UI. */ const Aside: React.FC = ({ children }) => { const isVisible = useMinWidth(`(min-width: ${breakpoints.xl})`); + const wcoRect = useWindowControlsOverlay(); + const offsetTop = + wcoRect && wcoRect.x + wcoRect.width < window.innerWidth ? 16 + wcoRect.height : 16; + if (!isVisible) { return null; } return (