UNPKG

@base-ui-components/react

Version:

Base UI is a library of headless ('unstyled') React components and low-level hooks. You gain complete control over your app's CSS and accessibility features.

20 lines (19 loc) 623 B
import { ownerWindow } from '@base-ui-components/utils/owner'; // This lets us invert the scale of the cursor to match the OS scale, in which the cursor doesn't // scale with the content on pinch-zoom. export function subscribeToVisualViewportResize(element, visualScaleRef) { const vV = ownerWindow(element).visualViewport; if (!vV) { return () => {}; } function handleVisualResize() { if (vV) { visualScaleRef.current = vV.scale; } } handleVisualResize(); vV.addEventListener('resize', handleVisualResize); return () => { vV.removeEventListener('resize', handleVisualResize); }; }