fix: 🐛

This commit is contained in:
codytseng
2025-04-25 09:22:04 +08:00
parent 51913a5163
commit eb8fe17ae6

View File

@@ -23,6 +23,8 @@ const PrimaryPageLayout = forwardRef(
ref ref
) => { ) => {
const scrollAreaRef = useRef<HTMLDivElement>(null) const scrollAreaRef = useRef<HTMLDivElement>(null)
const smallScreenScrollAreaRef = useRef<HTMLDivElement>(null)
const smallScreenLastScrollTopRef = useRef(0)
const { isSmallScreen } = useScreenSize() const { isSmallScreen } = useScreenSize()
const { current } = usePrimaryPage() const { current } = usePrimaryPage()
@@ -39,15 +41,14 @@ const PrimaryPageLayout = forwardRef(
[] []
) )
const lastScrollTopRef = useRef(0)
useEffect(() => { useEffect(() => {
if (isSmallScreen) { if (isSmallScreen) {
if (scrollAreaRef.current?.checkVisibility()) { if (smallScreenScrollAreaRef.current?.checkVisibility()) {
window.scrollTo({ top: lastScrollTopRef.current }) window.scrollTo({ top: smallScreenLastScrollTopRef.current })
} }
const handleScroll = () => { const handleScroll = () => {
if (scrollAreaRef.current?.checkVisibility()) { if (smallScreenScrollAreaRef.current?.checkVisibility()) {
lastScrollTopRef.current = window.scrollY smallScreenLastScrollTopRef.current = window.scrollY
} }
} }
window.addEventListener('scroll', handleScroll) window.addEventListener('scroll', handleScroll)
@@ -55,13 +56,13 @@ const PrimaryPageLayout = forwardRef(
window.removeEventListener('scroll', handleScroll) window.removeEventListener('scroll', handleScroll)
} }
} }
}, [current]) }, [current, isSmallScreen])
if (isSmallScreen) { if (isSmallScreen) {
return ( return (
<DeepBrowsingProvider active={current === pageName}> <DeepBrowsingProvider active={current === pageName}>
<div <div
ref={scrollAreaRef} ref={smallScreenScrollAreaRef}
style={{ style={{
paddingBottom: 'calc(env(safe-area-inset-bottom) + 3rem)' paddingBottom: 'calc(env(safe-area-inset-bottom) + 3rem)'
}} }}