)
}
// 페이지마다 마지막 스크롤 위치: 뒤로 가기로 돌아오면 그 자리로
const scrolled = new Map()
/** intro: 토스 첫 소개 화면이 떠 있는지 */
function Shell({ intro }: { intro: boolean }) {
const { pathname, key } = useLocation()
const navType = useNavigationType()
const { kind } = useSky()
const [loaded, setLoaded] = useState(false)
const onLoaded = useCallback(() => setLoaded(true), [])
useEffect(() => {
const save = () => scrolled.set(key, window.scrollY)
window.addEventListener('scroll', save, { passive: true })
return () => window.removeEventListener('scroll', save)
}, [key])
useEffect(() => {
const top = navType === 'POP' ? scrolled.get(key) : undefined
if (top == null) {
window.scrollTo({ top: 0 })
return
}
// 피드가 다시 그려져 그 높이가 될 때까지 최대 3초 맞추고, 그 사이 사람이 화면을 만지면 멈춘다
let tries = 0
let raf = 0
const stop = () => cancelAnimationFrame(raf)
const go = () => {
window.scrollTo({ top })
if (Math.abs(window.scrollY - top) > 2 && ++tries < 180) raf = requestAnimationFrame(go)
}
go()
window.addEventListener('touchstart', stop, { once: true, passive: true })
window.addEventListener('wheel', stop, { once: true, passive: true })
return () => {
stop()
window.removeEventListener('touchstart', stop)
window.removeEventListener('wheel', stop)
}
}, [pathname, key, navType])
// 지금 보고 있는 탭을 다시 누르면 맨 위로
const toTopIfHere = (to: string) => () => {
if (pathname === to) window.scrollTo({ top: 0, behavior: 'smooth' })
}
useEffect(() => {
document.querySelector('meta[name="theme-color"]')?.setAttribute('content', NOTCH_BG[kind])
}, [kind])
return (
{/* 위·아래 바: 띠는 화면 끝까지, 내용은 가운데 440px 안 */}
{HOLIDAY && (
)}
)
}
/** .b-app 에 지금 시간대를 달아 밤에는 바깥 글자를 밝게 바꾼다 */
function SkyRoot({ children }: { children: ReactNode }) {
return (
{children}
)
}
function SkyApp({ children }: { children: ReactNode }) {
const { kind } = useSky()
return (