From de39195a618721932673521f10da83158145dfe3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=84=B1=EA=B2=BD?= Date: Fri, 13 Nov 2026 16:33:45 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=ED=99=88=20=EC=87=BC=EC=B8=A0=20?= =?UTF-8?q?=EB=AF=B8=EB=A6=AC=EB=B3=B4=EA=B8=B0=20=E2=80=94=20=EB=8D=B0?= =?UTF-8?q?=EC=8A=A4=ED=81=AC=ED=86=B1=EC=9D=80=20=EB=A7=88=EC=9A=B0?= =?UTF-8?q?=EC=8A=A4=EB=A5=BC=20=EC=98=AC=EB=A6=B0=20=EC=B9=B4=EB=93=9C?= =?UTF-8?q?=EB=A7=8C=20=EC=9E=AC=EC=83=9D(0.2=EC=B4=88=20=EB=A8=B8?= =?UTF-8?q?=EB=AC=BC=20=EB=95=8C),=20=ED=84=B0=EC=B9=98=20=EA=B8=B0?= =?UTF-8?q?=EA=B8=B0=EB=8A=94=20=EC=B2=AB=20=ED=84=B0=EC=B9=98=20=EB=92=A4?= =?UTF-8?q?=20=EC=B2=AB=20=EC=B9=B4=EB=93=9C.=20=EC=87=BC=EC=B8=A0=5F?= =?UTF-8?q?=EB=AF=B8=EB=A6=AC=EB=B3=B4=EA=B8=B0=EC=97=90=20trigger(hover?= =?UTF-8?q?=C2=B7auto)=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/b/Shorts.tsx | 58 +++++++++++++++++++++++++++++---------- 1 file changed, 44 insertions(+), 14 deletions(-) diff --git a/frontend/src/b/Shorts.tsx b/frontend/src/b/Shorts.tsx index 157eb75..1b4d1ed 100644 --- a/frontend/src/b/Shorts.tsx +++ b/frontend/src/b/Shorts.tsx @@ -75,16 +75,21 @@ function useVisible(threshold = 0.5) { return [ref, visible] as const } +// 마우스를 올릴 수 있는 기기(데스크톱)인지. 터치 기기는 올리기가 없어 첫 터치 뒤 첫 카드를 자동 재생한다 +const CAN_HOVER = typeof window !== 'undefined' && window.matchMedia('(hover: hover) and (pointer: fine)').matches +// 마우스가 줄 위를 지나가기만 할 땐 플레이어를 받지 않게, 이만큼 머물러야 재생한다 +const HOVER_PLAY_MS = 200 + // scroll 은 넣지 않는다: 브라우저가 스크롤 위치를 되돌릴 때도 나서 조작으로 볼 수 없다 -const TOUCH_EVENTS = ['pointerdown', 'touchstart', 'wheel', 'keydown', 'mousemove'] as const +const TOUCH_EVENTS = ['pointerdown', 'touchstart', 'keydown'] as const // 한 번 조작했으면 다른 화면에 다녀와도 그대로 둔다 let touchedOnce = false -/** 사용자가 화면을 처음 조작(누르기·굴리기·키)한 뒤부터 true. 유튜브 플레이어(약 850KB)를 첫 화면 로드에서 빼려고 쓴다 */ -function useTouched() { +/** 터치 기기에서 사용자가 화면을 처음 조작(누르기·키)한 뒤부터 true. 유튜브 플레이어(약 850KB)를 첫 화면 로드에서 빼려고 쓴다 */ +function useTouched(enabled: boolean) { const [touched, setTouched] = useState(touchedOnce) useEffect(() => { - if (touchedOnce) return + if (!enabled || touchedOnce) return const opts = { capture: true, passive: true } const off = () => TOUCH_EVENTS.forEach((t) => window.removeEventListener(t, on, opts)) const on = () => { @@ -94,16 +99,19 @@ function useTouched() { } TOUCH_EVENTS.forEach((t) => window.addEventListener(t, on, opts)) return off - }, []) + }, [enabled]) return touched } -/** 오늘 화면 히어로 아래 쇼츠 줄: 첫 조작 뒤 첫 카드만 소리 없이 재생, 누르면 쇼츠 페이지(/shorts/영상ID)에서 위아래로 넘겨 본다 */ +/** + * 오늘 화면 히어로 아래 쇼츠 줄: 누르면 쇼츠 페이지(/shorts/영상ID)에서 위아래로 넘겨 본다. + * 줄에서는 소리 없이 미리 보인다 — 데스크톱은 마우스를 올린 카드, 터치 기기는 첫 터치 뒤 첫 카드 + */ export function ShortsRail() { const q = useQuery(listShortsOptions()) const items = q.data?.items ?? [] const [ref, visible] = useVisible() - const touched = useTouched() + const touched = useTouched(!CAN_HOVER && !IS_TOSS) if (q.isPending) { return ( @@ -123,18 +131,30 @@ export function ShortsRail() { {items.map((s, i) => ( // 토스 앱 웹뷰는 유튜브 플레이어가 무거워, 줄에선 표지만 보이고 누르면 재생 - + ))} ) } -function ShortCard({ s, first, playing }: { s: ShortItem; first: boolean; playing: boolean }) { +/** auto: 올리지 않아도 재생 (터치 기기의 첫 카드) */ +function ShortCard({ s, first, auto }: { s: ShortItem; first: boolean; auto: boolean }) { + const [hover, setHover] = useState(false) + const hoverTimer = useRef(0) + useEffect(() => () => window.clearTimeout(hoverTimer.current), []) + const enter = () => { + hoverTimer.current = window.setTimeout(() => setHover(true), HOVER_PLAY_MS) + } + const leave = () => { + window.clearTimeout(hoverTimer.current) + setHover(false) + } + const playing = auto || hover // 재생이 시작된 뒤에만 플레이어를 보인다: 자동재생이 막히면(아이폰 절전 등) 유튜브 재생 버튼 대신 표지 그대로 const [started, setStarted] = useState(false) const frame = useRef(null) - // 플레이어는 반복 재생하며 재생 상태를 여러 번 보내므로 미리보기 이벤트는 한 번만 + // 플레이어는 반복 재생하며 재생 상태를 여러 번 보내고 마우스도 여러 번 올리므로, 미리보기 이벤트는 카드마다 한 번만 const previewSent = useRef(false) useEffect(() => { if (!playing) return @@ -145,16 +165,26 @@ function ShortCard({ s, first, playing }: { s: ShortItem; first: boolean; playin setStarted(true) if (previewSent.current) return previewSent.current = true - track('shorts_preview', { video_id: s.id }) + track('shorts_preview', { video_id: s.id, trigger: auto ? 'auto' : 'hover' }) } catch { return } } window.addEventListener('message', onMessage) - return () => window.removeEventListener('message', onMessage) - }, [playing, s.id]) + return () => { + window.removeEventListener('message', onMessage) + // 플레이어를 내렸다 다시 띄우면 첫 장면을 받을 때까지 다시 표지 + setStarted(false) + } + }, [playing, auto, s.id]) return ( - + {/* 첫 카드 표지는 첫 화면에서 가장 큰 그림(LCP)이라 미루지 않고 먼저 받는다 */} {playing && (