fix: 아이폰 사파리에서 쇼츠를 누르면 첫 영상부터 열리던 문제 — 시작 영상으로 옮긴 뒤 한 번 더 맞추고, 옮기기 전엔 보이는 칸 변화를 무시

This commit is contained in:
minaChoi committed 2026-10-27 20:03:27 +09:00
1 parent ef61a5bf73
commit 694ea85ed3
1 file changed
+14 -3
+14 -3
View File
@@ -184,14 +184,24 @@ function ShortsViewer({ items, start, onClose, onAt }: { items: ShortItem[]; sta
// 처음 한 번: 시작 영상으로 맞추고, 뒤 페이지 스크롤을 잠근다
const startRef = useRef(start)
useEffect(() => {
// scrollIntoView 는 바깥 칸까지 굴려 버튼 줄이 헤더 밑으로 숨으므로 목록만 옮긴다
// 시작 영상으로 옮기기 전엔 보이는 칸이 바뀐 것으로 치지 않는다 (사파리는 처음 그릴 때 맨 위 칸이 먼저 보여 첫 영상으로 바뀌던 것)
const placed = useRef(false)
useLayoutEffect(() => {
// scrollIntoView 는 바깥 칸까지 굴려 버튼 줄이 헤더 밑으로 숨으므로 목록만 옮긴다. 사파리는 첫 그림 전에 옮긴 값을 되돌려 한 번 더
const box = list.current
if (box) box.scrollTop = box.clientHeight * startRef.current
const place = () => {
if (box) box.scrollTop = box.clientHeight * startRef.current
}
place()
const raf = requestAnimationFrame(() => {
place()
placed.current = true
})
const root = document.documentElement
const before = root.style.overflow
root.style.overflow = 'hidden'
return () => {
cancelAnimationFrame(raf)
root.style.overflow = before
}
}, [])
@@ -207,6 +217,7 @@ function ShortsViewer({ items, start, onClose, onAt }: { items: ShortItem[]; sta
if (!box) return
const io = new IntersectionObserver(
(entries) => {
if (!placed.current) return
for (const e of entries) if (e.isIntersecting) setAt(Number((e.target as HTMLElement).dataset.i))
},
{ root: box, threshold: 0.6 },