From 6783ff23f98694edde4a3c697062725797f03e74 Mon Sep 17 00:00:00 2001 From: Gigi Date: Sat, 11 Oct 2025 01:39:24 +0100 Subject: [PATCH] feat: auto-hide mobile buttons on scroll down - Add useScrollDirection hook for scroll direction detection - Hide bookmark and highlight buttons when scrolling down - Show buttons again when scrolling up - Smooth opacity transitions for better UX - Only detect scroll when buttons are visible - Improves mobile reading experience by maximizing content area --- .cursor/rules/mobile-first-ui-ux.mdc | 5 ++- src/components/ThreePaneLayout.tsx | 12 +++++- src/hooks/useScrollDirection.ts | 59 ++++++++++++++++++++++++++++ src/index.css | 26 +++++++++++- 4 files changed, 97 insertions(+), 5 deletions(-) create mode 100644 src/hooks/useScrollDirection.ts diff --git a/.cursor/rules/mobile-first-ui-ux.mdc b/.cursor/rules/mobile-first-ui-ux.mdc index 3dca9096..cc64f96a 100644 --- a/.cursor/rules/mobile-first-ui-ux.mdc +++ b/.cursor/rules/mobile-first-ui-ux.mdc @@ -1,3 +1,6 @@ --- -alwaysApply: true +description: anything related to UI/UX +alwaysApply: false --- + +This is a mobile-first application. All UI elements should be designed with that in mind. The application should work well on small screens, including older smartphones. The UX should be immaculate on mobile, even when in flight mode. (We use local caches and local relays, so that app works offline too.) diff --git a/src/components/ThreePaneLayout.tsx b/src/components/ThreePaneLayout.tsx index c6923530..64053547 100644 --- a/src/components/ThreePaneLayout.tsx +++ b/src/components/ThreePaneLayout.tsx @@ -19,6 +19,7 @@ import { HighlightVisibility } from './HighlightsPanel' import { HighlightButtonRef } from './HighlightButton' import { BookmarkReference } from '../utils/contentLoader' import { useIsMobile } from '../hooks/useMediaQuery' +import { useScrollDirection } from '../hooks/useScrollDirection' interface ThreePaneLayoutProps { // Layout state @@ -86,6 +87,13 @@ const ThreePaneLayout: React.FC = (props) => { const isMobile = useIsMobile() const sidebarRef = useRef(null) const highlightsRef = useRef(null) + + // Detect scroll direction to hide/show mobile buttons + const scrollDirection = useScrollDirection({ + threshold: 10, + enabled: isMobile && !props.isSidebarOpen && props.isHighlightsCollapsed + }) + const showMobileButtons = scrollDirection !== 'down' // Lock body scroll when mobile sidebar or highlights is open useEffect(() => { @@ -204,7 +212,7 @@ const ThreePaneLayout: React.FC = (props) => { {/* Mobile bookmark button - only show when viewing article */} {isMobile && !props.isSidebarOpen && props.isHighlightsCollapsed && (