fix: 쇼츠가 저절로 재생되지 않으면(토스 웹뷰) 2초 뒤 플레이어를 보이고 재생 아이콘을 띄워 직접 눌러 재생

This commit is contained in:
minaChoi committed 2026-10-26 16:11:49 +09:00
1 parent 81b17f057f
commit acb6c4d717
1 file changed
+26 -2
+26 -2
View File
@@ -46,6 +46,8 @@ function command(frame: HTMLIFrameElement | null | undefined, func: Func, args:
}
const PLAYING = 1
// 이만큼 지나도 재생이 시작되지 않으면(자동재생이 막힌 웹뷰) 플레이어를 보이고 재생 아이콘을 띄워 직접 누르게 한다
const STALL_MS = 2000
// 마우스로 이만큼 끌면 다음·이전 영상으로 넘긴다
const SWIPE_PX = 30
@@ -96,6 +98,7 @@ function ShortCard({ s, playing }: { s: ShortItem; playing: boolean }) {
return (
<Link to={`/shorts/${s.id}`} aria-label={`${s.title} 보기`} className="relative block aspect-[9/16] w-[120px] cursor-pointer overflow-hidden rounded-xl bg-[#1d2233] p-0 text-left text-white">
<img src={`https://i.ytimg.com/vi/${s.id}/hqdefault.jpg`} alt="" loading="lazy" className="absolute inset-0 size-full object-cover" />
<PlayIcon />
{playing && (
<iframe
src={embed(s.id)}
@@ -144,6 +147,9 @@ function ShortsViewer({ items, start, onClose, onAt }: { items: ShortItem[]; sta
const soundRef = useRef(false)
// 누르기로 멈춘 상태. 다른 영상으로 넘어가면 다시 재생 중으로
const paused = useRef(false)
// 보이는 영상이 저절로 재생되지 않음
const [stalled, setStalled] = useState(false)
const stalledHere = stalled && !ready.has(at)
// 처음 한 번: 시작 영상으로 맞추고, 뒤 페이지 스크롤을 잠근다
const startRef = useRef(start)
@@ -217,6 +223,12 @@ function ShortsViewer({ items, start, onClose, onAt }: { items: ShortItem[]; sta
}
}, [at, items])
useEffect(() => {
setStalled(false)
const t = window.setTimeout(() => setStalled(true), STALL_MS)
return () => window.clearTimeout(t)
}, [at])
// 마우스로도 끌어 넘긴다: 영상 위는 유튜브 iframe 이 마우스를 가져가서, 그 위에 투명한 판을 깔고 끈 만큼 목록을 옮긴다.
// 손가락은 브라우저 스크롤에 맡기고, 끌지 않고 누르기만 하면 재생·일시정지
const drag = useRef<{ y: number; top: number; moved: boolean } | null>(null)
@@ -314,7 +326,7 @@ function ShortsViewer({ items, start, onClose, onAt }: { items: ShortItem[]; sta
return next
})
}}
className={cx('absolute inset-0 size-full border-0 transition-opacity duration-200', !ready.has(i) && 'opacity-0')}
className={cx('absolute inset-0 size-full border-0 transition-opacity duration-200', !ready.has(i) && !(i === at && stalledHere) && 'opacity-0')}
/>
)}
<div
@@ -327,8 +339,9 @@ function ShortsViewer({ items, start, onClose, onAt }: { items: ShortItem[]; sta
setDragging(false)
}}
onClick={() => lastPointer.current !== 'mouse' && togglePause()}
className={cx('absolute inset-0 touch-pan-y select-none', dragging ? 'cursor-grabbing' : 'cursor-grab')}
className={cx('absolute inset-0 touch-pan-y select-none', dragging ? 'cursor-grabbing' : 'cursor-grab', i === at && stalledHere && 'pointer-events-none')}
/>
{i === at && stalledHere && <PlayIcon />}
</div>
</div>
))}
@@ -336,3 +349,14 @@ function ShortsViewer({ items, start, onClose, onAt }: { items: ShortItem[]; sta
</div>
)
}
/** 재생 아이콘. 누름은 아래 플레이어가 받는다 */
function PlayIcon() {
return (
<span aria-hidden="true" className="pointer-events-none absolute top-1/2 left-1/2 grid size-12 -translate-1/2 place-items-center rounded-full bg-black/45 text-white">
<svg viewBox="0 0 24 24" className="ml-0.5 size-6" fill="currentColor">
<path d="M8 5.5v13l10.5-6.5z" />
</svg>
</span>
)
}