import { useState, useRef, useLayoutEffect, ReactNode } from 'react'; import { motion } from 'framer-motion'; import { useAtomValue } from 'jotai'; import { DrawerIsOpeningAtom, ScreenIsAnimatingAtom } from '../atoms'; export function SmoothHeight({ children }: { children: ReactNode }) { const [height, setHeight] = useState('auto'); const contentRef = useRef(null); const screenIsAnimating = useAtomValue(ScreenIsAnimatingAtom) const drawerIsOpening = useAtomValue(DrawerIsOpeningAtom) let instant = screenIsAnimating || drawerIsOpening useLayoutEffect(() => { if (!contentRef.current) return; const observer = new ResizeObserver(([entry]) => setHeight(entry.contentRect.height)); observer.observe(contentRef.current); return () => observer.disconnect(); }, []); return (
{children}
); }