Browse Source

refactor: extract base geometry calculation and add phone number formatter import

master
mortezaei 5 days ago
parent
commit
280599eb07
  1. 23
      src/components/Componentes/question-viewport-coordinator.ts

23
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<HTMLElement>(".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<HTMLElement>(
'.question-snap-item[aria-current="step"] .question-snap-content',
@ -123,10 +140,8 @@ function updateLift() {
return;
}
const rect = content.getBoundingClientRect();
const snapList = content.closest<HTMLElement>(".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);
}

Loading…
Cancel
Save