From ad3df9b037e693cd8a07dba1f6932cdd6db1c96b Mon Sep 17 00:00:00 2001 From: codytseng Date: Sat, 23 Aug 2025 23:21:57 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=92=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/PageManager.tsx | 4 ++-- src/layouts/PrimaryPageLayout/index.tsx | 12 +++++++----- src/layouts/SecondaryPageLayout/index.tsx | 14 ++++++++------ src/types/index.d.ts | 2 +- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/PageManager.tsx b/src/PageManager.tsx index 913f5cb9..1926aceb 100644 --- a/src/PageManager.tsx +++ b/src/PageManager.tsx @@ -219,7 +219,7 @@ export function PageManager({ maxStackSize = 5 }: { maxStackSize?: number }) { } setCurrentPrimaryPage(page) if (needScrollToTop) { - PRIMARY_PAGE_REF_MAP[page].current?.scrollToTop() + PRIMARY_PAGE_REF_MAP[page].current?.scrollToTop('smooth') } if (isSmallScreen) { clearSecondaryPages() @@ -231,7 +231,7 @@ export function PageManager({ maxStackSize = 5 }: { maxStackSize?: number }) { if (isCurrentPage(prevStack, url)) { const currentItem = prevStack[prevStack.length - 1] if (currentItem?.ref?.current) { - currentItem.ref.current.scrollToTop() + currentItem.ref.current.scrollToTop('instant') } return prevStack } diff --git a/src/layouts/PrimaryPageLayout/index.tsx b/src/layouts/PrimaryPageLayout/index.tsx index a8dd6ee9..c30b0190 100644 --- a/src/layouts/PrimaryPageLayout/index.tsx +++ b/src/layouts/PrimaryPageLayout/index.tsx @@ -31,11 +31,13 @@ const PrimaryPageLayout = forwardRef( useImperativeHandle( ref, () => ({ - scrollToTop: () => { - if (scrollAreaRef.current) { - return scrollAreaRef.current.scrollTo({ top: 0, behavior: 'smooth' }) - } - window.scrollTo({ top: 0, behavior: 'smooth' }) + scrollToTop: (behavior: ScrollBehavior = 'smooth') => { + setTimeout(() => { + if (scrollAreaRef.current) { + return scrollAreaRef.current.scrollTo({ top: 0, behavior }) + } + window.scrollTo({ top: 0, behavior }) + }, 10) } }), [] diff --git a/src/layouts/SecondaryPageLayout/index.tsx b/src/layouts/SecondaryPageLayout/index.tsx index e3a1cad1..e1c325e5 100644 --- a/src/layouts/SecondaryPageLayout/index.tsx +++ b/src/layouts/SecondaryPageLayout/index.tsx @@ -34,11 +34,13 @@ const SecondaryPageLayout = forwardRef( useImperativeHandle( ref, () => ({ - scrollToTop: () => { - if (scrollAreaRef.current) { - return scrollAreaRef.current.scrollTo({ top: 0, behavior: 'smooth' }) - } - window.scrollTo({ top: 0, behavior: 'smooth' }) + scrollToTop: (behavior: ScrollBehavior = 'smooth') => { + setTimeout(() => { + if (scrollAreaRef.current) { + return scrollAreaRef.current.scrollTo({ top: 0, behavior }) + } + window.scrollTo({ top: 0, behavior }) + }, 10) } }), [] @@ -46,7 +48,7 @@ const SecondaryPageLayout = forwardRef( useEffect(() => { if (isSmallScreen) { - setTimeout(() => window.scrollTo({ top: 0 }), 0) + setTimeout(() => window.scrollTo({ top: 0 }), 10) return } }, []) diff --git a/src/types/index.d.ts b/src/types/index.d.ts index 0e93c297..df86d8bb 100644 --- a/src/types/index.d.ts +++ b/src/types/index.d.ts @@ -120,7 +120,7 @@ export type TNoteListMode = 'posts' | 'postsAndReplies' | 'you' export type TNotificationType = 'all' | 'mentions' | 'reactions' | 'zaps' -export type TPageRef = { scrollToTop: () => void } +export type TPageRef = { scrollToTop: (behavior?: ScrollBehavior) => void } export type TNip66RelayInfo = TRelayInfo & { url: string