diff --git a/frontend/app/(main)/screens/[screenId]/page.tsx b/frontend/app/(main)/screens/[screenId]/page.tsx index 72356cf0..81e7ee49 100644 --- a/frontend/app/(main)/screens/[screenId]/page.tsx +++ b/frontend/app/(main)/screens/[screenId]/page.tsx @@ -1,6 +1,6 @@ "use client"; -import { useEffect, useState, useRef } from "react"; +import React, { useEffect, useState, useRef, useMemo } from "react"; import { useParams } from "next/navigation"; import { Button } from "@/components/ui/button"; import { Loader2 } from "lucide-react"; @@ -152,6 +152,43 @@ export default function ScreenViewPage() { updateScale(); }, [layout]); + // 실제 컨텐츠의 동적 높이 상태 + const [actualContentHeight, setActualContentHeight] = useState(layout?.screenResolution?.height || 800); + const contentRef = useRef(null); + + // ResizeObserver로 컨텐츠 높이 실시간 모니터링 + useEffect(() => { + if (!contentRef.current) return; + + const resizeObserver = new ResizeObserver(() => { + if (!contentRef.current) return; + + // 모든 컴포넌트의 실제 높이를 측정 + const components = contentRef.current.querySelectorAll("[data-component-id]"); + let maxBottom = layout?.screenResolution?.height || 800; + + components.forEach((element) => { + const rect = element.getBoundingClientRect(); + const parentRect = contentRef.current!.getBoundingClientRect(); + const relativeTop = rect.top - parentRect.top; + const bottom = relativeTop + rect.height; + maxBottom = Math.max(maxBottom, bottom); + }); + + setActualContentHeight(maxBottom); + }); + + resizeObserver.observe(contentRef.current); + + // 모든 자식 요소도 관찰 + const childElements = contentRef.current.querySelectorAll("[data-component-id]"); + childElements.forEach((child) => resizeObserver.observe(child)); + + return () => { + resizeObserver.disconnect(); + }; + }, [layout]); + if (loading) { return (
@@ -185,23 +222,24 @@ export default function ScreenViewPage() { const screenHeight = layout?.screenResolution?.height || 800; return ( -
+
{layout && layout.components.length > 0 ? ( // 스케일링된 화면을 감싸는 래퍼 (실제 크기 조정 + 좌우 마진 16px)
{/* 캔버스 컴포넌트들을 가로폭에 맞춰 스케일링하여 표시 */}
{ @@ -435,7 +474,7 @@ export default function ScreenViewPage() {