fix: 토스판 쇼츠는 유튜브 기본 플레이어로 — 토스 웹뷰엔 재생 상태가 안 와서 자동재생·숨기기 대신 재생 버튼을 처음부터 보이고, 카드는 표지와 재생 아이콘, 쇼츠 페이지에 이전·다음 버튼

This commit is contained in:
minaChoi committed 2026-10-26 16:24:45 +09:00
1 parent 61023d090e
commit 21bfa2a3ff
1 file changed
+42 -20
+42 -20
View File
@@ -3,6 +3,7 @@ import { type CSSProperties, type PointerEvent as ReactPointerEvent, useEffect,
import { Link, useNavigate, useParams } from 'react-router'
import { listShortsOptions } from '@nalssigak/shared/api/client/@tanstack/react-query.gen'
import type { ShortItem } from '@nalssigak/shared/api/client'
import { IS_TOSS } from '../lib/platform'
import { cx } from '../lib/utils'
import { Rail, Skel, SkelRail, TAP44 } from './ui'
@@ -30,9 +31,12 @@ function useTabBarHeight() {
const YT_ORIGIN = 'https://www.youtube-nocookie.com'
// 토스 웹뷰에서는 플레이어가 보내는 재생 상태가 오지 않아, 숨기기·자동재생 없이 유튜브 기본 플레이어(재생 버튼 포함)를 그대로 쓴다
const PLAIN = IS_TOSS
function embed(id: string) {
const q = new URLSearchParams({
autoplay: '1', mute: '1', playsinline: '1', loop: '1', playlist: id, controls: '0', rel: '0', modestbranding: '1',
autoplay: PLAIN ? '0' : '1', mute: PLAIN ? '0' : '1', playsinline: '1', loop: '1', playlist: id, controls: PLAIN ? '1' : '0', rel: '0', modestbranding: '1',
enablejsapi: '1', origin: window.location.origin,
})
return `${YT_ORIGIN}/embed/${id}?${q}`
@@ -104,7 +108,7 @@ export function ShortsRail() {
<section ref={ref} aria-label="날씨각 쇼츠">
<Rail label="쇼츠 목록">
{items.map((s, i) => (
<ShortCard key={s.id} s={s} playing={i === 0 && visible} />
<ShortCard key={s.id} s={s} playing={!PLAIN && i === 0 && visible} />
))}
</Rail>
</section>
@@ -314,6 +318,11 @@ function ShortsViewer({ items, start, onClose, onAt }: { items: ShortItem[]; sta
box.scrollTo({ top: target * h, behavior: 'smooth' })
}
const go = (step: number) => {
const box = list.current
if (box) box.scrollTo({ top: (at + step) * box.clientHeight, behavior: 'smooth' })
}
const toggleSound = () => {
const on = !sound
soundRef.current = on
@@ -342,16 +351,27 @@ function ShortsViewer({ items, start, onClose, onAt }: { items: ShortItem[]; sta
<button type="button" onClick={onClose} aria-label="닫기" className={cx('relative grid size-9 cursor-pointer place-items-center rounded-full bg-white/15 text-xl text-white', TAP44)}>
×
</button>
<button type="button" onClick={toggleSound} aria-pressed={sound} className="h-9 cursor-pointer rounded-full bg-white/15 px-3.5 text-[13px] font-bold text-white">
{sound ? '소리 끄기' : '소리 켜기'}
</button>
{PLAIN ? (
<div className="flex gap-2">
<button type="button" onClick={() => go(-1)} disabled={at === 0} className="h-9 cursor-pointer rounded-full bg-white/15 px-3.5 text-[13px] font-bold text-white disabled:opacity-40">
▲ 이전
</button>
<button type="button" onClick={() => go(1)} disabled={at === items.length - 1} className="h-9 cursor-pointer rounded-full bg-white/15 px-3.5 text-[13px] font-bold text-white disabled:opacity-40">
▼ 다음
</button>
</div>
) : (
<button type="button" onClick={toggleSound} aria-pressed={sound} className="h-9 cursor-pointer rounded-full bg-white/15 px-3.5 text-[13px] font-bold text-white">
{sound ? '소리 끄기' : '소리 켜기'}
</button>
)}
</div>
<div ref={list} className={cx('relative min-h-0 flex-1 overflow-y-auto [scrollbar-width:none]', !dragging && 'snap-y snap-mandatory')}>
{items.map((s, i) => (
<div key={s.id} data-i={i} className="relative grid h-full snap-start place-items-center">
<div className="relative" style={FIT}>
<img src={`https://i.ytimg.com/vi/${s.id}/hqdefault.jpg`} alt="" className="absolute inset-0 size-full object-cover" />
{Math.abs(i - at) <= 1 && (
{(PLAIN ? i === at : Math.abs(i - at) <= 1) && (
<iframe
ref={(f) => {
if (f) frames.current.set(i, f)
@@ -371,22 +391,24 @@ 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) && !(i === at && direct) && 'opacity-0')}
className={cx('absolute inset-0 size-full border-0 transition-opacity duration-200', !PLAIN && !ready.has(i) && !(i === at && direct) && 'opacity-0')}
/>
)}
<div
aria-hidden="true"
onPointerDown={onPointerDown}
onPointerMove={onPointerMove}
onPointerUp={onPointerUp}
onPointerCancel={() => {
drag.current = null
setDragging(false)
}}
onClick={() => lastPointer.current !== 'mouse' && togglePause()}
className={cx('absolute inset-0 touch-pan-y select-none', dragging ? 'cursor-grabbing' : 'cursor-grab', i === at && direct && !running && 'pointer-events-none')}
/>
{i === at && showPlay && <PlayIcon />}
{!PLAIN && (
<div
aria-hidden="true"
onPointerDown={onPointerDown}
onPointerMove={onPointerMove}
onPointerUp={onPointerUp}
onPointerCancel={() => {
drag.current = null
setDragging(false)
}}
onClick={() => lastPointer.current !== 'mouse' && togglePause()}
className={cx('absolute inset-0 touch-pan-y select-none', dragging ? 'cursor-grabbing' : 'cursor-grab', i === at && direct && !running && 'pointer-events-none')}
/>
)}
{!PLAIN && i === at && showPlay && <PlayIcon />}
</div>
</div>
))}