Add fullscreen safe-area layout and directional transitions

This commit is contained in:
Codex 2026-09-07 20:52:44 +00:00
parent 41dbaa66f4
commit 135d7f0203
3 changed files with 60 additions and 11 deletions

View file

@ -19,6 +19,8 @@
config: null,
customCategories: { income: [], expense: [] },
};
const viewOrder = ["dashboardView", "historyView", "leaderboardView", "addView"];
let transitionCleanupTimer = 0;
const categories = {
income: ["Зарплата", "Фриланс", "Подарок", "Продажа", "Инвестиции", "Другое"],
expense: ["Продукты", "Жильё", "Транспорт", "Здоровье", "Развлечения", "Покупки", "Другое"],
@ -34,6 +36,7 @@
if (!tg) return;
safeTelegram(() => tg.ready());
safeTelegram(() => tg.expand());
if (tg.isVersionAtLeast?.("8.0")) safeTelegram(() => tg.requestFullscreen());
safeTelegram(() => tg.enableClosingConfirmation?.());
if (tg.isVersionAtLeast?.("6.1")) safeTelegram(() => tg.setBackgroundColor("#111111"));
if (tg.isVersionAtLeast?.("6.9")) safeTelegram(() => tg.setHeaderColor("#111111"));
@ -63,6 +66,15 @@
}
function showView(viewId) {
const previousView = state.currentView;
if (viewId === previousView) {
if (viewId === "leaderboardView") loadLeaderboard();
return;
}
const previousIndex = viewOrder.indexOf(previousView);
const nextIndex = viewOrder.indexOf(viewId);
const direction = nextIndex >= previousIndex ? "forward" : "backward";
document.querySelectorAll(".bottom-nav button, .view").forEach((item) => item.classList.remove("active"));
$(`#${viewId}`).classList.add("active");
document.querySelector(`.bottom-nav button[data-view="${viewId}"]`)?.classList.add("active");
@ -70,9 +82,27 @@
document.body.classList.toggle("form-open", viewId === "addView");
updateNativeControls();
window.scrollTo({ top: 0, behavior: "auto" });
animateViewStage(direction);
if (viewId === "leaderboardView") loadLeaderboard();
}
function animateViewStage(direction) {
const stage = $("#viewStage");
const className = direction === "backward" ? "transition-backward" : "transition-forward";
window.clearTimeout(transitionCleanupTimer);
stage.onanimationend = null;
stage.classList.remove("transition-forward", "transition-backward");
void stage.offsetWidth;
stage.classList.add(className);
const cleanup = () => {
stage.classList.remove("transition-forward", "transition-backward");
stage.onanimationend = null;
};
stage.onanimationend = cleanup;
transitionCleanupTimer = window.setTimeout(cleanup, 400);
}
function openAddView() {
if (state.currentView !== "addView") state.previousView = state.currentView;
showView("addView");

View file

@ -6,9 +6,9 @@
<meta name="color-scheme" content="dark" />
<meta name="theme-color" content="#111111" />
<title>Пожитки</title>
<link rel="stylesheet" href="./styles.css?v=7" />
<link rel="stylesheet" href="./styles.css?v=8" />
<script src="./telegram-web-app.js"></script>
<script src="./app.js?v=7" defer></script>
<script src="./app.js?v=8" defer></script>
</head>
<body>
<main class="shell">
@ -23,6 +23,7 @@
</div>
</header>
<div id="viewStage" class="view-stage">
<section id="dashboardView" class="view active" aria-labelledby="dashboardTab">
<div class="dashboard-summary">
<article class="hero-card">
@ -118,6 +119,7 @@
<div id="leaderboardList" class="leaderboard-list loading">Загружаем рейтинг…</div>
<p id="friendHint" class="friend-hint hidden">Поделитесь ссылкой: когда друг запустит бота, он появится здесь.</p>
</section>
</div>
</main>
<nav class="bottom-nav" aria-label="Основная навигация">

View file

@ -33,7 +33,11 @@ body {
isolation: isolate;
min-height: 100vh;
min-height: 100dvh;
padding: max(14px, env(safe-area-inset-top)) 18px calc(96px + env(safe-area-inset-bottom));
padding:
max(14px, var(--tg-content-safe-area-inset-top, 0px), env(safe-area-inset-top))
max(18px, var(--tg-content-safe-area-inset-right, 0px), env(safe-area-inset-right))
calc(108px + max(var(--tg-content-safe-area-inset-bottom, 0px), env(safe-area-inset-bottom)))
max(18px, var(--tg-content-safe-area-inset-left, 0px), env(safe-area-inset-left));
overflow-x: hidden;
background: transparent;
}
@ -70,7 +74,7 @@ button:focus { outline: none; }
button:focus-visible { outline: 2px solid rgba(255, 255, 255, .72); outline-offset: 2px; }
button:active { filter: brightness(.88); }
.shell { display: flex; flex-direction: column; width: min(100%, 560px); min-height: calc(var(--tg-viewport-stable-height, 100dvh) - 110px); margin: 0 auto; }
.shell { display: flex; flex-direction: column; width: min(100%, 560px); min-height: calc(var(--tg-viewport-stable-height, 100dvh) - 126px - var(--tg-content-safe-area-inset-top, 0px) - var(--tg-content-safe-area-inset-bottom, 0px)); margin: 0 auto; }
.topbar { display: flex; align-items: center; justify-content: space-between; margin: 6px 2px 26px; text-shadow: 0 2px 14px rgba(0, 0, 0, .55); }
.eyebrow { margin: 0 0 3px; text-transform: uppercase; letter-spacing: .12em; font-size: 10px; font-weight: 750; color: var(--muted); }
h1, h2, p { margin-top: 0; }
@ -79,6 +83,9 @@ h2 { margin: 0; font-size: 23px; letter-spacing: -.025em; }
.user-chip { display: flex; align-items: center; gap: 8px; max-width: 48%; padding: 5px 11px 5px 5px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); font-size: 12px; font-weight: 650; white-space: nowrap; overflow: hidden; }
.mini-avatar { display: grid; flex: 0 0 auto; place-items: center; width: 29px; height: 29px; border-radius: 50%; background: rgba(0, 0, 0, .28); color: var(--text); }
.view-stage { display: flex; flex: 1; flex-direction: column; min-width: 0; }
.view-stage.transition-forward { animation: view-stage-from-right .3s cubic-bezier(.22, 1, .36, 1); }
.view-stage.transition-backward { animation: view-stage-from-left .3s cubic-bezier(.22, 1, .36, 1); }
.view { display: none; padding-top: 0; }
.view.active { display: block; }
#dashboardView.active { display: flex; flex: 1; flex-direction: column; justify-content: flex-end; }
@ -179,12 +186,12 @@ h2 { margin: 0; font-size: 23px; letter-spacing: -.025em; }
.leader-percent.negative { color: var(--danger); }
.friend-hint { margin: 13px 18px; color: var(--muted); font-size: 11px; line-height: 1.5; text-align: center; }
.bottom-nav { position: fixed; z-index: 10; right: 0; bottom: 0; left: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 8px max(15px, calc((100vw - 560px) / 2)) max(8px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--surface); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px); }
.bottom-nav { position: fixed; z-index: 10; right: max(12px, var(--tg-content-safe-area-inset-right, 0px), env(safe-area-inset-right)); bottom: max(12px, var(--tg-content-safe-area-inset-bottom, 0px), env(safe-area-inset-bottom)); left: max(12px, var(--tg-content-safe-area-inset-left, 0px), env(safe-area-inset-left)); display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; width: auto; max-width: 540px; margin: 0 auto; padding: 8px 18px; border: 1px solid var(--line); border-radius: 22px; background: var(--surface); box-shadow: var(--shadow); backdrop-filter: blur(50px); -webkit-backdrop-filter: blur(50px); }
.bottom-nav button { display: grid; place-items: center; gap: 2px; padding: 3px; border: 0; background: transparent; color: var(--muted); font-size: 9px; font-weight: 650; }
.bottom-nav button > span { font-size: 22px; line-height: 30px; }
.bottom-nav button.active { color: var(--accent); }
.form-open .bottom-nav { display: none; }
.toast { position: fixed; z-index: 20; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom)); max-width: calc(100% - 36px); padding: 11px 16px; border: 1px solid var(--line); border-radius: 12px; transform: translate(-50%, 20px); background: rgba(0, 0, 0, .62); color: var(--text); opacity: 0; pointer-events: none; transition: .2s ease; font-size: 12px; box-shadow: var(--shadow); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px); }
.toast { position: fixed; z-index: 20; left: 50%; bottom: calc(92px + max(var(--tg-content-safe-area-inset-bottom, 0px), env(safe-area-inset-bottom))); max-width: calc(100% - 36px); padding: 11px 16px; border: 1px solid var(--line); border-radius: 12px; transform: translate(-50%, 20px); background: rgba(0, 0, 0, .62); color: var(--text); opacity: 0; pointer-events: none; transition: .2s ease; font-size: 12px; box-shadow: var(--shadow); backdrop-filter: blur(50px); -webkit-backdrop-filter: blur(50px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.hero-card,
@ -200,14 +207,24 @@ h2 { margin: 0; font-size: 23px; letter-spacing: -.025em; }
.icon-button,
.leader-filter select,
.leaderboard-list {
backdrop-filter: blur(18px);
-webkit-backdrop-filter: blur(18px);
backdrop-filter: blur(50px);
-webkit-backdrop-filter: blur(50px);
}
input::placeholder { color: rgba(255, 255, 255, .48); }
select option { color: #ffffff; background: #252525; }
@media (min-width: 600px) {
body { padding-top: 28px; }
.bottom-nav { left: 50%; bottom: 14px; width: 540px; border: 1px solid var(--line); border-radius: 22px; transform: translateX(-50%); padding: 8px 22px; box-shadow: var(--shadow); }
@keyframes view-stage-from-right {
from { transform: translate3d(34px, 0, 0); }
to { transform: translate3d(0, 0, 0); }
}
@keyframes view-stage-from-left {
from { transform: translate3d(-34px, 0, 0); }
to { transform: translate3d(0, 0, 0); }
}
@media (prefers-reduced-motion: reduce) {
.view-stage.transition-forward,
.view-stage.transition-backward { animation: none; }
}