feat: animate sidebar on mobile
Some checks failed
TrafficCue CI / check (push) Failing after 1m23s
TrafficCue CI / build (push) Failing after 1m6s
TrafficCue CI / build-android (push) Successful in 15m29s

This commit is contained in:
2025-09-12 17:09:24 +02:00
parent 5314f8e6c6
commit a48ed785f5

View File

@ -21,8 +21,9 @@
import { routing } from "$lib/services/navigation/routing.svelte"; import { routing } from "$lib/services/navigation/routing.svelte";
import InRouteSidebar from "./sidebar/InRouteSidebar.svelte"; import InRouteSidebar from "./sidebar/InRouteSidebar.svelte";
import { m } from "$lang/messages"; import { m } from "$lang/messages";
import LoadingSidebar from "./sidebar/LoadingSidebar.svelte"; import LoadingSidebar from "./sidebar/LoadingSidebar.svelte";
import { Tween } from "svelte/motion";
import { quintOut } from "svelte/easing";
const views: Record<string, string> = { const views: Record<string, string> = {
main: "MainSidebar", main: "MainSidebar",
@ -59,7 +60,17 @@
let isDragging = false; let isDragging = false;
let startY = 0; let startY = 0;
let startHeight = 0; let startHeight = 0;
let sidebarHeight = $state(200); let sidebarHeight = new Tween(200, {
duration: 500,
easing: quintOut
});
let lastSidebarHeight = 0;
$effect(() => {
if (lastSidebarHeight != sidebarHeight.current) {
lastSidebarHeight = sidebarHeight.current;
map.updateMapPadding();
}
});
let previousHeight = 200; let previousHeight = 200;
let hideSearch = $state(false); let hideSearch = $state(false);
@ -84,22 +95,22 @@
$effect(() => { $effect(() => {
const fullHeight = window.innerHeight - 20 - 40 - 10; const fullHeight = window.innerHeight - 20 - 40 - 10;
if (fullscreen[view.current.type]) { if (fullscreen[view.current.type]) {
if (sidebarHeight != fullHeight) { if (sidebarHeight.target != fullHeight) {
if (window.innerWidth < 768) { if (window.innerWidth < 768) {
hideSearch = true; hideSearch = true;
map.ignorePadding = true; map.ignorePadding = true;
} }
previousHeight = sidebarHeight; previousHeight = sidebarHeight.target;
sidebarHeight = fullHeight; sidebarHeight.target = fullHeight;
requestAnimationFrame(() => { requestAnimationFrame(() => {
map.updateMapPadding(); map.updateMapPadding();
}); });
} }
} else { } else {
hideSearch = false; hideSearch = false;
if (sidebarHeight == fullHeight) { if (sidebarHeight.target == fullHeight) {
map.ignorePadding = false; map.ignorePadding = false;
sidebarHeight = previousHeight; sidebarHeight.target = previousHeight;
requestAnimationFrame(() => { requestAnimationFrame(() => {
map.updateMapPadding(); map.updateMapPadding();
}); });
@ -157,7 +168,7 @@
<div <div
id="sidebar" id="sidebar"
class={mobileView ? "mobileView" : ""} class={mobileView ? "mobileView" : ""}
style={(mobileView ? `height: ${sidebarHeight}px;` : "") + style={(mobileView ? `height: ${sidebarHeight.current}px;` : "") +
(routing.currentTrip ? "bottom: 0 !important;" : "")} (routing.currentTrip ? "bottom: 0 !important;" : "")}
> >
{#if mobileView} {#if mobileView}
@ -168,7 +179,7 @@
ontouchstart={(e) => { ontouchstart={(e) => {
isDragging = true; isDragging = true;
startY = e.touches[0].clientY; startY = e.touches[0].clientY;
startHeight = sidebarHeight; startHeight = sidebarHeight.target;
}} }}
ontouchmove={(e) => { ontouchmove={(e) => {
if (!isDragging) return; if (!isDragging) return;
@ -181,7 +192,7 @@
if (Math.abs(newHeight - snapPoint) < snapThreshold) { if (Math.abs(newHeight - snapPoint) < snapThreshold) {
newHeight = snapPoint; newHeight = snapPoint;
} }
sidebarHeight = newHeight; sidebarHeight.target = newHeight;
map.updateMapPadding(); map.updateMapPadding();
}} }}