Merge remote-tracking branch 'origin/main' into feat/apps-in-toss
This commit is contained in:
commit
cc5ecd7bbf
1 file changed
+14
-3
@@ -184,14 +184,24 @@ function ShortsViewer({ items, start, onClose, onAt }: { items: ShortItem[]; sta
|
|||||||
|
|
||||||
// 처음 한 번: 시작 영상으로 맞추고, 뒤 페이지 스크롤을 잠근다
|
// 처음 한 번: 시작 영상으로 맞추고, 뒤 페이지 스크롤을 잠근다
|
||||||
const startRef = useRef(start)
|
const startRef = useRef(start)
|
||||||
useEffect(() => {
|
// 시작 영상으로 옮기기 전엔 보이는 칸이 바뀐 것으로 치지 않는다 (사파리는 처음 그릴 때 맨 위 칸이 먼저 보여 첫 영상으로 바뀌던 것)
|
||||||
// scrollIntoView 는 바깥 칸까지 굴려 버튼 줄이 헤더 밑으로 숨으므로 목록만 옮긴다
|
const placed = useRef(false)
|
||||||
|
useLayoutEffect(() => {
|
||||||
|
// scrollIntoView 는 바깥 칸까지 굴려 버튼 줄이 헤더 밑으로 숨으므로 목록만 옮긴다. 사파리는 첫 그림 전에 옮긴 값을 되돌려 한 번 더
|
||||||
const box = list.current
|
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 root = document.documentElement
|
||||||
const before = root.style.overflow
|
const before = root.style.overflow
|
||||||
root.style.overflow = 'hidden'
|
root.style.overflow = 'hidden'
|
||||||
return () => {
|
return () => {
|
||||||
|
cancelAnimationFrame(raf)
|
||||||
root.style.overflow = before
|
root.style.overflow = before
|
||||||
}
|
}
|
||||||
}, [])
|
}, [])
|
||||||
@@ -207,6 +217,7 @@ function ShortsViewer({ items, start, onClose, onAt }: { items: ShortItem[]; sta
|
|||||||
if (!box) return
|
if (!box) return
|
||||||
const io = new IntersectionObserver(
|
const io = new IntersectionObserver(
|
||||||
(entries) => {
|
(entries) => {
|
||||||
|
if (!placed.current) return
|
||||||
for (const e of entries) if (e.isIntersecting) setAt(Number((e.target as HTMLElement).dataset.i))
|
for (const e of entries) if (e.isIntersecting) setAt(Number((e.target as HTMLElement).dataset.i))
|
||||||
},
|
},
|
||||||
{ root: box, threshold: 0.6 },
|
{ root: box, threshold: 0.6 },
|
||||||
|
|||||||
Reference in new issue
Block a user