From 49a98240340a42c466ccc30a1f1c7adced3378f1 Mon Sep 17 00:00:00 2001 From: codytseng Date: Sun, 8 Dec 2024 15:25:08 +0800 Subject: [PATCH] fix: ensure titlebar appears when scrolling to top on mobile --- src/renderer/src/layouts/PrimaryPageLayout/index.tsx | 9 +++++++-- .../src/layouts/SecondaryPageLayout/index.tsx | 11 +++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/renderer/src/layouts/PrimaryPageLayout/index.tsx b/src/renderer/src/layouts/PrimaryPageLayout/index.tsx index 920b6ad..058c7bb 100644 --- a/src/renderer/src/layouts/PrimaryPageLayout/index.tsx +++ b/src/renderer/src/layouts/PrimaryPageLayout/index.tsx @@ -32,13 +32,18 @@ const PrimaryPageLayout = forwardRef(({ children }: { children?: React.ReactNode const handleScroll = () => { const scrollTop = scrollAreaRef.current?.scrollTop || 0 const diff = scrollTop - lastScrollTop + if (scrollTop <= 100) { + setVisible(true) + setLastScrollTop(scrollTop) + return + } + if (diff > 50) { setVisible(false) - setLastScrollTop(scrollTop) } else if (diff < -50) { setVisible(true) - setLastScrollTop(scrollTop) } + setLastScrollTop(scrollTop) } const scrollArea = scrollAreaRef.current diff --git a/src/renderer/src/layouts/SecondaryPageLayout/index.tsx b/src/renderer/src/layouts/SecondaryPageLayout/index.tsx index d63a8c7..5d51294 100644 --- a/src/renderer/src/layouts/SecondaryPageLayout/index.tsx +++ b/src/renderer/src/layouts/SecondaryPageLayout/index.tsx @@ -26,9 +26,16 @@ export default function SecondaryPageLayout({ useEffect(() => { const handleScroll = () => { const scrollTop = scrollAreaRef.current?.scrollTop || 0 - if (scrollTop > lastScrollTop) { + const diff = scrollTop - lastScrollTop + if (scrollTop <= 100) { + setVisible(true) + setLastScrollTop(scrollTop) + return + } + + if (diff > 50) { setVisible(false) - } else { + } else if (diff < -50) { setVisible(true) } setLastScrollTop(scrollTop)