From a48ed785f56dad9268a6f42b6eb6dabc64281a99 Mon Sep 17 00:00:00 2001 From: Jannik Date: Fri, 12 Sep 2025 17:09:24 +0200 Subject: [PATCH] feat: animate sidebar on mobile --- src/lib/components/lnv/Sidebar.svelte | 31 ++++++++++++++++++--------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/lib/components/lnv/Sidebar.svelte b/src/lib/components/lnv/Sidebar.svelte index c69610f..e394b6b 100644 --- a/src/lib/components/lnv/Sidebar.svelte +++ b/src/lib/components/lnv/Sidebar.svelte @@ -21,8 +21,9 @@ import { routing } from "$lib/services/navigation/routing.svelte"; import InRouteSidebar from "./sidebar/InRouteSidebar.svelte"; import { m } from "$lang/messages"; - import LoadingSidebar from "./sidebar/LoadingSidebar.svelte"; + import { Tween } from "svelte/motion"; + import { quintOut } from "svelte/easing"; const views: Record = { main: "MainSidebar", @@ -59,7 +60,17 @@ let isDragging = false; let startY = 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 hideSearch = $state(false); @@ -84,22 +95,22 @@ $effect(() => { const fullHeight = window.innerHeight - 20 - 40 - 10; if (fullscreen[view.current.type]) { - if (sidebarHeight != fullHeight) { + if (sidebarHeight.target != fullHeight) { if (window.innerWidth < 768) { hideSearch = true; map.ignorePadding = true; } - previousHeight = sidebarHeight; - sidebarHeight = fullHeight; + previousHeight = sidebarHeight.target; + sidebarHeight.target = fullHeight; requestAnimationFrame(() => { map.updateMapPadding(); }); } } else { hideSearch = false; - if (sidebarHeight == fullHeight) { + if (sidebarHeight.target == fullHeight) { map.ignorePadding = false; - sidebarHeight = previousHeight; + sidebarHeight.target = previousHeight; requestAnimationFrame(() => { map.updateMapPadding(); }); @@ -157,7 +168,7 @@