From be713620ef726ba4956c6c66b68b32e6312a6e97 Mon Sep 17 00:00:00 2001 From: Lucas Date: Tue, 3 Nov 2026 16:00:26 +0100 Subject: [PATCH] feat: better style for notifications --- .../arm64-v8a/libthomann_dsp_app_lib.so | 2 +- .../reports/problems/problems-report.html | 2 +- .../executionHistory/executionHistory.lock | Bin 17 -> 17 bytes .../buildOutputCleanup.lock | Bin 17 -> 17 bytes .../Notifications/Notifications.css | 69 +++++++++++++----- .../Notifications/Notifications.tsx | 66 ++++++++++++----- 6 files changed, 101 insertions(+), 38 deletions(-) diff --git a/src-tauri/gen/android/app/src/main/jniLibs/arm64-v8a/libthomann_dsp_app_lib.so b/src-tauri/gen/android/app/src/main/jniLibs/arm64-v8a/libthomann_dsp_app_lib.so index 78d71e2..07c4bb3 120000 --- a/src-tauri/gen/android/app/src/main/jniLibs/arm64-v8a/libthomann_dsp_app_lib.so +++ b/src-tauri/gen/android/app/src/main/jniLibs/arm64-v8a/libthomann_dsp_app_lib.so @@ -1 +1 @@ -C:/Users/lsdg/OneDrive - ETS ROBERT SAS 49/Bureau/Projects/dsp-thomann-interface/src-tauri/target/aarch64-linux-android/debug/libthomann_dsp_app_lib.so \ No newline at end of file +C:/Users/lsdg/OneDrive - ETS ROBERT SAS 49/Bureau/Projects/dsp-thomann-interface/src-tauri/target/aarch64-linux-android/release/libthomann_dsp_app_lib.so \ No newline at end of file diff --git a/src-tauri/gen/android/build/reports/problems/problems-report.html b/src-tauri/gen/android/build/reports/problems/problems-report.html index 5b35298..0ad6cfa 100644 --- a/src-tauri/gen/android/build/reports/problems/problems-report.html +++ b/src-tauri/gen/android/build/reports/problems/problems-report.html @@ -650,7 +650,7 @@ code + .copy-button { diff --git a/src-tauri/gen/android/buildSrc/.gradle/8.14.3/executionHistory/executionHistory.lock b/src-tauri/gen/android/buildSrc/.gradle/8.14.3/executionHistory/executionHistory.lock index e4081830f8e42825f91caaa6da729508bf291b87..0ed715884f8e01d289cfc6a88ecad239a36fe76f 100644 GIT binary patch literal 17 UcmZSXk>%+-t#JM&0|Zn604_KLVgLXD literal 17 UcmZSXk>%+-t#JM&0|aCM04^v5QUCw| diff --git a/src-tauri/gen/android/buildSrc/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/src-tauri/gen/android/buildSrc/.gradle/buildOutputCleanup/buildOutputCleanup.lock index 21aab41e867587a4c73c728509f8f3b902de79c6..c02f09f96d3fe9076dfcc17fa2167895e5534ed2 100644 GIT binary patch literal 17 VcmZR+(|%dt$g>V^1~6b`0suP@1d0Fv literal 17 UcmZR+(|%dt$g>V^1_*cr06XplX#fBK diff --git a/src/components/Notifications/Notifications.css b/src/components/Notifications/Notifications.css index 8d8ebfd..0b5f548 100644 --- a/src/components/Notifications/Notifications.css +++ b/src/components/Notifications/Notifications.css @@ -1,23 +1,20 @@ .notifications { position: fixed; right: var(--space-5); - top: var(--space-5); + top: calc(var(--topbar-h) + var(--space-3)); z-index: 9999; display: flex; flex-direction: column; gap: var(--space-3); - width: 320px; + width: min(320px, calc(100vw - 2 * var(--space-5))); pointer-events: none; - - animation: notification-in var(--dur-slow) var(--ease-out); /* no "forwards" */ - touch-action: pan-y; } .notification { display: flex; - align-items: center; + align-items: flex-start; justify-content: space-between; gap: var(--space-3); @@ -25,14 +22,34 @@ border-radius: var(--radius-md); font-size: 14px; + line-height: 1.45; box-shadow: var(--shadow-md); - animation: notification-in var(--dur-slow) var(--ease-out) forwards; + /* no "forwards": it would keep overriding the inline drag transform */ + animation: notification-in var(--dur-slow) var(--ease-out); pointer-events: auto; + min-width: 0; + + /* swipe behavior */ + touch-action: pan-y; /* browser keeps vertical scroll, we handle horizontal */ + user-select: none; + -webkit-user-select: none; + cursor: grab; + will-change: transform, opacity; } +.notification--dragging { + cursor: grabbing; +} + +/* once the user touches it, the inline style fully controls transform/opacity */ +.notification--touched:not(.notification-out) { + animation: none; +} + +/* must stay "forwards" so it holds its end state until removal */ .notification-out { animation: notification-out var(--dur-slow) var(--ease-in) forwards; } @@ -76,9 +93,10 @@ .notification-message { flex: 1; - overflow: hidden; - text-overflow: ellipsis; - white-space: nowrap; + min-width: 0; + white-space: normal; + overflow-wrap: anywhere; + word-break: normal; } @keyframes notification-in { @@ -105,13 +123,7 @@ } } -/* After a swipe-dismiss, the inline transition takes over (no restart from translateX(0)) */ -.notification--swiped { - animation: none; -} - @media (pointer: coarse) { - /* Undo the global 44px min-height on the small × button */ .notification-close { min-height: 0; } @@ -119,11 +131,30 @@ @media (max-width: 768px) { .notifications { - top: calc(var(--topbar-h, 0px) + var(--space-2)); - left: max(var(--space-3), var(--safe-left, 0px)); - right: max(var(--space-3), var(--safe-right, 0px)); + top: calc(var(--topbar-h) + var(--space-2)); + left: max(var(--space-3), var(--safe-left)); + right: max(var(--space-3), var(--safe-right)); width: auto; max-width: 420px; margin-inline: auto; } + + .notification { + padding: var(--space-3); + font-size: 14px; + align-items: flex-start; + } + + .notification-message { + white-space: normal; + overflow: visible; + text-overflow: unset; + overflow-wrap: anywhere; + } +} + +@media (prefers-reduced-motion: reduce) { + .notification { + animation-duration: 1ms; + } } \ No newline at end of file diff --git a/src/components/Notifications/Notifications.tsx b/src/components/Notifications/Notifications.tsx index 12355b9..1c33272 100644 --- a/src/components/Notifications/Notifications.tsx +++ b/src/components/Notifications/Notifications.tsx @@ -8,9 +8,11 @@ type Props = { onHover: (id: number, hovering: boolean) => void; }; -const DRAG_START_PX = 8; // movement before it counts as a swipe -const DISMISS_RATIO = 0.35; // fraction of the width to drag before it dismisses -const DISMISS_MS = 160; +const DRAG_START_PX = 6; // movement before it counts as a swipe +const DISMISS_RATIO = 0.35; // fraction of width to drag before it dismisses +const FLICK_VELOCITY = 0.5; // px/ms, a fast flick dismisses even below the threshold +const DISMISS_MS = 180; +const SNAP_MS = 220; function NotificationItem({ n, @@ -23,25 +25,34 @@ function NotificationItem({ }) { const ref = useRef(null); const startX = useRef(null); + const dxRef = useRef(0); const locked = useRef(false); + const last = useRef({ x: 0, t: 0, v: 0 }); // for velocity const [dx, setDx] = useState(0); const [dragging, setDragging] = useState(false); const [swiped, setSwiped] = useState(false); + const [interacted, setInteracted] = useState(false); // disables the entry animation after first touch + + function updateDx(v: number) { + dxRef.current = v; + setDx(v); + } function reset() { const wasLocked = locked.current; startX.current = null; locked.current = false; setDragging(false); - setDx(0); + updateDx(0); // transition handles the snap-back if (wasLocked) onHover(n.id, false); } function onPointerDown(e: React.PointerEvent) { if (swiped || n.removing) return; - if ((e.target as HTMLElement).closest('button')) return; // let the × button work + if ((e.target as HTMLElement).closest('button')) return; startX.current = e.clientX; + last.current = { x: e.clientX, t: performance.now(), v: 0 }; locked.current = false; } @@ -53,13 +64,25 @@ function NotificationItem({ if (Math.abs(delta) < DRAG_START_PX) return; locked.current = true; e.currentTarget.setPointerCapture(e.pointerId); + setInteracted(true); setDragging(true); - onHover(n.id, true); // pause the auto-dismiss timer + onHover(n.id, true); // pause auto-dismiss timer } - setDx(delta); + + // velocity (smoothed) + const now = performance.now(); + const dt = now - last.current.t; + if (dt > 0) { + const instant = (e.clientX - last.current.x) / dt; + last.current.v = last.current.v * 0.6 + instant * 0.4; + } + last.current.x = e.clientX; + last.current.t = now; + + updateDx(delta); } - function onPointerUp(e: React.PointerEvent) { + function finish(e: React.PointerEvent) { if (startX.current === null) return; if (!locked.current) { @@ -68,13 +91,18 @@ function NotificationItem({ } const width = ref.current?.offsetWidth ?? 300; - if (Math.abs(dx) > width * DISMISS_RATIO) { - const dir = dx > 0 ? 1 : -1; + const dist = dxRef.current; + const v = last.current.v; + const flicked = Math.abs(v) > FLICK_VELOCITY && Math.sign(v) === Math.sign(dist); + const farEnough = Math.abs(dist) > width * DISMISS_RATIO; + + if (flicked || farEnough) { + const dir = dist > 0 ? 1 : -1; startX.current = null; locked.current = false; setSwiped(true); setDragging(false); - setDx(dir * width * 1.2); + updateDx(dir * width * 1.1); window.setTimeout(() => onRemove(n.id), DISMISS_MS); } else { reset(); @@ -85,14 +113,17 @@ function NotificationItem({ } } - const touched = dx !== 0 || swiped; - const style: React.CSSProperties | undefined = touched + const width = ref.current?.offsetWidth ?? 300; + const progress = Math.min(1, Math.abs(dx) / (width * 0.8)); + + const style: React.CSSProperties | undefined = interacted ? { transform: `translateX(${dx}px)`, - opacity: swiped ? 0 : Math.max(0.3, 1 - Math.abs(dx) / 300), + opacity: swiped ? 0 : 1 - progress * 0.9, transition: dragging ? 'none' - : `transform ${DISMISS_MS}ms ease-out, opacity ${DISMISS_MS}ms ease-out`, + : `transform ${swiped ? DISMISS_MS : SNAP_MS}ms cubic-bezier(0.22, 1, 0.36, 1), + opacity ${swiped ? DISMISS_MS : SNAP_MS}ms ease-out`, } : undefined; @@ -103,7 +134,8 @@ function NotificationItem({ 'notification', n.type, n.removing && !swiped ? 'notification-out' : '', - swiped ? 'notification--swiped' : '', + interacted ? 'notification--touched' : '', + dragging ? 'notification--dragging' : '', ] .filter(Boolean) .join(' ')} @@ -112,7 +144,7 @@ function NotificationItem({ onMouseLeave={() => onHover(n.id, false)} onPointerDown={onPointerDown} onPointerMove={onPointerMove} - onPointerUp={onPointerUp} + onPointerUp={finish} onPointerCancel={reset} >