From ffd267424e224eecd96d91adfa745b35f33551f0 Mon Sep 17 00:00:00 2001 From: Evelyn Gordon Date: Tue, 18 Aug 2026 23:43:18 -0500 Subject: [PATCH 1/5] feat(mobile): allow swiping notifications away --- .../NotificationBanner.css.ts | 52 ++++++++- .../NotificationBanner.tsx | 103 +++++++++++++++--- 2 files changed, 132 insertions(+), 23 deletions(-) diff --git a/src/app/components/notification-banner/NotificationBanner.css.ts b/src/app/components/notification-banner/NotificationBanner.css.ts index 73320a121..554ce8e44 100644 --- a/src/app/components/notification-banner/NotificationBanner.css.ts +++ b/src/app/components/notification-banner/NotificationBanner.css.ts @@ -13,17 +13,42 @@ const slideIn = keyframes({ }, }); -const slideOut = keyframes({ +const fadeOut = keyframes({ from: { opacity: 1, - transform: 'translateY(0)', }, to: { opacity: 0, + }, +}); + +const slideOut = keyframes({ + from: { + transform: 'translateY(0)', + }, + to: { transform: 'translateY(-100%)', }, }); +const swipeOutLeft = keyframes({ + from: { + transform: 'translateX(0)', + }, + to: { + transform: 'translateX(-100%)', + }, +}); + +const swipeOutRight = keyframes({ + from: { + transform: 'translateX(0)', + }, + to: { + transform: 'translateX(100%)', + }, +}); + // Positions at the top of the viewport, spanning full width. // Uses fixed positioning with safe-area-inset to handle iOS keyboard correctly. // On iOS, the banner stays at the top of the visual viewport even when keyboard is open. @@ -73,17 +98,32 @@ export const Banner = style({ animationName: slideIn, animationDuration: '260ms', animationTimingFunction: 'cubic-bezier(0.22, 0.8, 0.6, 1)', - animationFillMode: 'both', + animationFillMode: 'backwards', + transitionProperty: 'transform', + transitionDuration: '200ms', + transitionTimingFunction: 'ease-out', selectors: { '&:hover': { backgroundColor: color.Surface.ContainerHover, }, - '&[data-dismissing=true]': { - animationName: slideOut, + '&[data-dismissing=up], &[data-dismissing=left], &[data-dismissing=right]': { animationDuration: '200ms', animationTimingFunction: 'cubic-bezier(0.4, 0, 1, 1)', - animationFillMode: 'both', + animationFillMode: 'forwards', + animationComposition: 'accumulate, replace', + }, + '&[data-dismissing=up]': { + animationName: `${slideOut}, ${fadeOut}`, + }, + '&[data-dismissing=left]': { + animationName: `${swipeOutLeft}, ${fadeOut}`, + }, + '&[data-dismissing=right]': { + animationName: `${swipeOutRight}, ${fadeOut}`, + }, + '&[data-swiping=true]': { + transitionProperty: 'none', }, }, }); diff --git a/src/app/components/notification-banner/NotificationBanner.tsx b/src/app/components/notification-banner/NotificationBanner.tsx index cf4cc0633..413b5aacd 100644 --- a/src/app/components/notification-banner/NotificationBanner.tsx +++ b/src/app/components/notification-banner/NotificationBanner.tsx @@ -12,6 +12,7 @@ import * as css from './NotificationBanner.css'; const log = createLogger('NotificationBanner'); const BANNER_DURATION_MS = 5000; +const DISMISS_SWIPE_DISTANCE = 150; // Renders body text capped at a max height with a gradient fade when it overflows. function BodyText({ text, hovered }: { text: string; hovered: boolean }) { @@ -63,31 +64,37 @@ function BannerMessage({ notification }: { notification: InAppBannerNotification ); } +type DismissDirection = 'up' | 'left' | 'right'; + function BannerItem({ notification, onDismiss }: BannerItemProps) { - const [dismissing, setDismissing] = useState(false); + const [dismissing, setDismissing] = useState(); const [paused, setPaused] = useState(false); - const dismissedRef = useRef(false); const dismissAnimTimerRef = useRef | null>(null); const elapsedRef = useRef(0); + const [gesture, setGesture] = useState<{ startX: number; startY: number } | undefined>(); + const [swipeDistance, setSwipeDistance] = useState(0); + // Use a ref to guard against double-dismiss without creating a new callback identity. - const dismiss = useCallback(() => { - if (dismissedRef.current) return; - dismissedRef.current = true; - setDismissing(true); - dismissAnimTimerRef.current = setTimeout(() => onDismiss(notification.id), 200); - }, [notification.id, onDismiss]); + const dismiss = useCallback( + (direction: DismissDirection) => { + if (dismissing) return; + setDismissing(direction); + dismissAnimTimerRef.current = setTimeout(() => onDismiss(notification.id), 200); + }, + [notification.id, onDismiss, dismissing] + ); // Auto-dismiss timer  Eonly runs when not paused. useEffect(() => { if (paused) return undefined; const remaining = BANNER_DURATION_MS - elapsedRef.current; if (remaining <= 0) { - dismiss(); + dismiss('up'); return undefined; } const startedAt = Date.now(); - const t = setTimeout(dismiss, remaining); + const t = setTimeout(() => dismiss('up'), remaining); return () => { clearTimeout(t); // Accumulate time spent un-paused so we can resume from the right point. @@ -104,26 +111,88 @@ function BannerItem({ notification, onDismiss }: BannerItemProps) { const handleClick = () => { notification.onClick(); - dismiss(); + dismiss('up'); }; // When hovering, pause the auto-dismiss timer. - const handleMouseEnter = () => setPaused(true); - const handleMouseLeave = () => setPaused(false); + const handleMouseEnter = useCallback(() => setPaused(true), []); + const handleMouseLeave = useCallback(() => setPaused(false), []); + + const release = useCallback( + (commit: boolean) => { + setPaused(false); + + if (commit && Math.abs(swipeDistance) > DISMISS_SWIPE_DISTANCE) { + // Continue off the side of the screen + dismiss(swipeDistance > 0 ? 'right' : 'left'); + } else { + // Spring back to center + setSwipeDistance(0); + setGesture(undefined); + } + }, + [swipeDistance] + ); + + const handleTouchStart = useCallback( + (event: TouchEvent) => { + const touch = event.touches[0]; + if (!touch || event.touches.length !== 1) { + release(false); + return; + } + + setPaused(true); + + setGesture({ + startX: touch.clientX, + startY: touch.clientY, + }); + }, + [release] + ); + const handleTouchMove = useCallback( + (event: TouchEvent) => { + if (dismissing) return; + const touch = event.touches[0]; + if (!gesture || !touch) return; + + const swipeDistance = touch.clientX - gesture.startX; + setSwipeDistance(swipeDistance); + }, + [dismissing, gesture] + ); + const handleTouchEnd = useCallback(() => { + if (dismissing) return; + release(true); + }, [dismissing, release]); + const handleTouchCancel = useCallback(() => { + if (dismissing) return; + release(false); + }, [dismissing, release]); return (
:( tabIndex={0} onKeyDown={(e) => { if (e.key === 'Enter' || e.key === ' ') handleClick(); - if (e.key === 'Escape') dismiss(); + if (e.key === 'Escape') dismiss('up'); }} onMouseEnter={handleMouseEnter} onMouseLeave={handleMouseLeave} + onTouchStart={handleTouchStart} + onTouchMove={handleTouchMove} + onTouchCancel={handleTouchCancel} + onTouchEnd={handleTouchEnd} + style={{ + transform: `translateX(${swipeDistance}px)`, + willChange: 'transform', + }} > {!notification.event && notification.icon && ( { e.stopPropagation(); - dismiss(); + dismiss('up'); }} aria-label="Dismiss notification" > @@ -173,7 +242,7 @@ function BannerItem({ notification, onDismiss }: BannerItemProps) {
); From ed58095816f4d11f82323be3d37f39577419e422 Mon Sep 17 00:00:00 2001 From: Evelyn Gordon Date: Wed, 19 Aug 2026 00:00:55 -0500 Subject: [PATCH 2/5] Fix typecheck --- .../components/notification-banner/NotificationBanner.tsx | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/app/components/notification-banner/NotificationBanner.tsx b/src/app/components/notification-banner/NotificationBanner.tsx index 413b5aacd..c7a99c5d1 100644 --- a/src/app/components/notification-banner/NotificationBanner.tsx +++ b/src/app/components/notification-banner/NotificationBanner.tsx @@ -1,5 +1,5 @@ import { useAtom } from 'jotai'; -import { useCallback, useEffect, useRef, useState } from 'react'; +import { useCallback, useEffect, useRef, useState, TouchEvent } from 'react'; import { Box, IconButton, Text } from 'folds'; import { sizedIcon, X } from '$components/icons/phosphor'; import { createLogger } from '$utils/debug'; @@ -131,7 +131,7 @@ function BannerItem({ notification, onDismiss }: BannerItemProps) { setGesture(undefined); } }, - [swipeDistance] + [dismiss, swipeDistance] ); const handleTouchStart = useCallback( @@ -157,8 +157,7 @@ function BannerItem({ notification, onDismiss }: BannerItemProps) { const touch = event.touches[0]; if (!gesture || !touch) return; - const swipeDistance = touch.clientX - gesture.startX; - setSwipeDistance(swipeDistance); + setSwipeDistance(touch.clientX - gesture.startX); }, [dismissing, gesture] ); From 9e9bbd0cc925778236c1fef7d12685ee049577e5 Mon Sep 17 00:00:00 2001 From: Evelyn Gordon Date: Wed, 19 Aug 2026 00:04:15 -0500 Subject: [PATCH 3/5] Document change --- .../allow_swiping_away_in_app_notifications_on_mobile.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/allow_swiping_away_in_app_notifications_on_mobile.md diff --git a/.changeset/allow_swiping_away_in_app_notifications_on_mobile.md b/.changeset/allow_swiping_away_in_app_notifications_on_mobile.md new file mode 100644 index 000000000..ca917762a --- /dev/null +++ b/.changeset/allow_swiping_away_in_app_notifications_on_mobile.md @@ -0,0 +1,5 @@ +--- +default: minor +--- + +# Allow swiping away in-app notifications on mobile From a47a12dda41d2dc07dbb0a433cddcb7d5d1819a7 Mon Sep 17 00:00:00 2001 From: Evelyn Gordon Date: Wed, 19 Aug 2026 19:18:34 -0500 Subject: [PATCH 4/5] Fix checks --- .../allow_swiping_away_in_app_notifications_on_mobile.md | 2 +- src/app/components/notification-banner/NotificationBanner.tsx | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.changeset/allow_swiping_away_in_app_notifications_on_mobile.md b/.changeset/allow_swiping_away_in_app_notifications_on_mobile.md index ca917762a..2d248a8ac 100644 --- a/.changeset/allow_swiping_away_in_app_notifications_on_mobile.md +++ b/.changeset/allow_swiping_away_in_app_notifications_on_mobile.md @@ -2,4 +2,4 @@ default: minor --- -# Allow swiping away in-app notifications on mobile +Allow swiping away in-app notifications on mobile diff --git a/src/app/components/notification-banner/NotificationBanner.tsx b/src/app/components/notification-banner/NotificationBanner.tsx index c7a99c5d1..b379e02f5 100644 --- a/src/app/components/notification-banner/NotificationBanner.tsx +++ b/src/app/components/notification-banner/NotificationBanner.tsx @@ -1,5 +1,6 @@ import { useAtom } from 'jotai'; -import { useCallback, useEffect, useRef, useState, TouchEvent } from 'react'; +import type { TouchEvent } from 'react'; +import { useCallback, useEffect, useRef, useState } from 'react'; import { Box, IconButton, Text } from 'folds'; import { sizedIcon, X } from '$components/icons/phosphor'; import { createLogger } from '$utils/debug'; From bb7d9e24a4d0052b431b40f85c2dd4ac4fe0c31d Mon Sep 17 00:00:00 2001 From: Evelyn Gordon Date: Wed, 19 Aug 2026 20:32:16 -0500 Subject: [PATCH 5/5] Fix style conflicts --- .../NotificationBanner.css.ts | 36 +++--- .../NotificationBanner.tsx | 118 +++++++++--------- 2 files changed, 82 insertions(+), 72 deletions(-) diff --git a/src/app/components/notification-banner/NotificationBanner.css.ts b/src/app/components/notification-banner/NotificationBanner.css.ts index 554ce8e44..e7cbc8755 100644 --- a/src/app/components/notification-banner/NotificationBanner.css.ts +++ b/src/app/components/notification-banner/NotificationBanner.css.ts @@ -79,19 +79,8 @@ export const BannerContainer = style({ }, }); -export const Banner = style({ - position: 'relative', - overflow: 'hidden', +export const BannerWrapper = style({ pointerEvents: 'all', - display: 'flex', - alignItems: 'center', - gap: config.space.S300, - backgroundColor: color.Surface.Container, - color: color.Surface.OnContainer, - border: `${config.borderWidth.B300} solid ${color.Surface.ContainerLine}`, - borderRadius: toRem(16), - padding: `${config.space.S300} ${config.space.S400}`, - boxShadow: `0 ${toRem(8)} ${toRem(32)} rgba(0, 0, 0, 0.45), 0 ${toRem(2)} ${toRem(8)} rgba(0, 0, 0, 0.3)`, cursor: 'pointer', width: '100%', maxWidth: toRem(420), @@ -104,9 +93,6 @@ export const Banner = style({ transitionTimingFunction: 'ease-out', selectors: { - '&:hover': { - backgroundColor: color.Surface.ContainerHover, - }, '&[data-dismissing=up], &[data-dismissing=left], &[data-dismissing=right]': { animationDuration: '200ms', animationTimingFunction: 'cubic-bezier(0.4, 0, 1, 1)', @@ -128,6 +114,26 @@ export const Banner = style({ }, }); +export const Banner = style({ + position: 'relative', + overflow: 'hidden', + display: 'flex', + alignItems: 'center', + gap: config.space.S300, + backgroundColor: color.Surface.Container, + color: color.Surface.OnContainer, + border: `${config.borderWidth.B300} solid ${color.Surface.ContainerLine}`, + borderRadius: toRem(16), + padding: `${config.space.S300} ${config.space.S400}`, + boxShadow: `0 ${toRem(8)} ${toRem(32)} rgba(0, 0, 0, 0.45), 0 ${toRem(2)} ${toRem(8)} rgba(0, 0, 0, 0.3)`, + + selectors: { + ':hover > &': { + backgroundColor: color.Surface.ContainerHover, + }, + }, +}); + export const BannerIcon = style({ width: toRem(44), height: toRem(44), diff --git a/src/app/components/notification-banner/NotificationBanner.tsx b/src/app/components/notification-banner/NotificationBanner.tsx index b379e02f5..19df95720 100644 --- a/src/app/components/notification-banner/NotificationBanner.tsx +++ b/src/app/components/notification-banner/NotificationBanner.tsx @@ -173,16 +173,9 @@ function BannerItem({ notification, onDismiss }: BannerItemProps) { return (
:( - tabIndex={0} - onKeyDown={(e) => { - if (e.key === 'Enter' || e.key === ' ') handleClick(); - if (e.key === 'Escape') dismiss('up'); - }} onMouseEnter={handleMouseEnter} onMouseLeave={handleMouseLeave} onTouchStart={handleTouchStart} @@ -194,56 +187,67 @@ function BannerItem({ notification, onDismiss }: BannerItemProps) { willChange: 'transform', }} > - {!notification.event && notification.icon && ( - { - (e.currentTarget as HTMLImageElement).style.display = 'none'; - }} - /> - )} -
- {notification.room && notification.event ? ( - - ) : ( - <> - - {notification.senderName ?? notification.title} - {(notification.roomName || notification.serverName) && ( - - {' ('} - {notification.roomName && `#${notification.roomName}`} - {notification.roomName && notification.serverName && ', '} - {notification.serverName}) - - )} - - {notification.body && } - - )} -
- - { - e.stopPropagation(); - dismiss('up'); - }} - aria-label="Dismiss notification" - > - {sizedIcon(X, '100')} - -
+ className={css.Banner} + onClick={handleClick} + role="button" + tabIndex={0} + onKeyDown={(e) => { + if (e.key === 'Enter' || e.key === ' ') handleClick(); + if (e.key === 'Escape') dismiss('up'); + }} + > + {!notification.event && notification.icon && ( + { + (e.currentTarget as HTMLImageElement).style.display = 'none'; + }} + /> + )} +
+ {notification.room && notification.event ? ( + + ) : ( + <> + + {notification.senderName ?? notification.title} + {(notification.roomName || notification.serverName) && ( + + {' ('} + {notification.roomName && `#${notification.roomName}`} + {notification.roomName && notification.serverName && ', '} + {notification.serverName}) + + )} + + {notification.body && } + + )} +
+ + { + e.stopPropagation(); + dismiss('up'); + }} + aria-label="Dismiss notification" + > + {sizedIcon(X, '100')} + + +
+
); }