diff --git a/src/components/Componentes/question-viewport-coordinator.ts b/src/components/Componentes/question-viewport-coordinator.ts index 957a72e..d6aab31 100644 --- a/src/components/Componentes/question-viewport-coordinator.ts +++ b/src/components/Componentes/question-viewport-coordinator.ts @@ -103,6 +103,23 @@ function getKeyboardTop() { return Math.min(flutterTop, viewportBottom); } +function getBaseGeometry(content: HTMLElement) { + const item = content.closest(".question-snap-item"); + if (item && typeof item.getBoundingClientRect === "function" && content.offsetHeight > 0) { + const itemRect = item.getBoundingClientRect(); + const top = itemRect.top + content.offsetTop; + return { + baseTop: top, + baseBottom: top + content.offsetHeight, + }; + } + const rect = content.getBoundingClientRect(); + return { + baseTop: rect.top + currentLift, + baseBottom: rect.bottom + currentLift, + }; +} + function updateLift() { const content = document.querySelector( '.question-snap-item[aria-current="step"] .question-snap-content', @@ -123,10 +140,8 @@ function updateLift() { return; } - const rect = content.getBoundingClientRect(); const snapList = content.closest(".question-snap-list"); - const baseTop = rect.top + currentLift; - const baseBottom = rect.bottom + currentLift; + const { baseTop, baseBottom } = getBaseGeometry(content); const safeTop = Number.parseFloat( getComputedStyle(document.documentElement).getPropertyValue("--safe-top"), ); @@ -140,7 +155,7 @@ function updateLift() { ), visibleBottom: Math.min(...visibleBottomCandidates), }); - console.log(`[Coord] computed lift: ${computed}px (rect: ${rect.top.toFixed(0)}-${rect.bottom.toFixed(0)}, kTop: ${keyboardTop?.toFixed(0)})`); + console.log(`[Coord] computed lift: ${computed}px (baseTop: ${baseTop.toFixed(0)}, baseBottom: ${baseBottom.toFixed(0)}, kTop: ${keyboardTop?.toFixed(0)})`); setLift(computed); }