Browse Source

fix: keep main feed scroll position on primary page navigation (#299)

imwald
TheMonkeyCoder 11 months ago committed by GitHub
parent
commit
d3d5842804
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 16
      src/layouts/PrimaryPageLayout/index.tsx

16
src/layouts/PrimaryPageLayout/index.tsx

@ -39,10 +39,21 @@ const PrimaryPageLayout = forwardRef(
[] []
) )
const lastScrollTopRef = useRef(0)
useEffect(() => { useEffect(() => {
if (isSmallScreen) { if (isSmallScreen) {
window.scrollTo({ top: 0 }) if (scrollAreaRef.current?.checkVisibility()) {
return window.scrollTo({ top: lastScrollTopRef.current })
}
const handleScroll = () => {
if (scrollAreaRef.current?.checkVisibility()) {
lastScrollTopRef.current = window.scrollY
}
}
window.addEventListener('scroll', handleScroll)
return () => {
window.removeEventListener('scroll', handleScroll)
}
} }
}, [current]) }, [current])
@ -50,6 +61,7 @@ const PrimaryPageLayout = forwardRef(
return ( return (
<DeepBrowsingProvider active={current === pageName}> <DeepBrowsingProvider active={current === pageName}>
<div <div
ref={scrollAreaRef}
style={{ style={{
paddingBottom: 'calc(env(safe-area-inset-bottom) + 3rem)' paddingBottom: 'calc(env(safe-area-inset-bottom) + 3rem)'
}} }}

Loading…
Cancel
Save