From 697c4bfb201fed51f7897e0f1bff345e062f81d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=84=B1=EA=B2=BD?= Date: Wed, 4 Nov 2026 17:42:32 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=95=B1=20=EC=87=BC=EC=B8=A0=C2=B7?= =?UTF-8?q?=EA=B5=AC=EB=A6=84=20=ED=95=A9=EC=B9=98=EA=B8=B0=20=EA=B2=8C?= =?UTF-8?q?=EC=9E=84=20=E2=80=94=20=EC=98=A4=EB=8A=98=20=ED=94=BC=EB=93=9C?= =?UTF-8?q?=20=EC=87=BC=EC=B8=A0=20=EC=A4=84,=20/shorts=20=EC=9C=84?= =?UTF-8?q?=EC=95=84=EB=9E=98=EB=A1=9C=20=EB=84=98=EA=B2=A8=20=EB=B3=B4?= =?UTF-8?q?=EA=B8=B0(=EC=9C=A0=ED=8A=9C=EB=B8=8C=20=ED=94=8C=EB=A0=88?= =?UTF-8?q?=EC=9D=B4=EC=96=B4=EB=A5=BC=20=EC=82=AC=EC=9D=B4=ED=8A=B8=20?= =?UTF-8?q?=EC=A3=BC=EC=86=8C=20=EA=B8=B0=EC=A4=80=20=EC=9B=B9=EB=B7=B0?= =?UTF-8?q?=EB=A1=9C,=20=EC=95=9E=EB=92=A4=20=EB=AF=B8=EB=A6=AC=20?= =?UTF-8?q?=EB=B0=9B=EA=B8=B0,=20=EB=88=8C=EB=9F=AC=20=EC=86=8C=EB=A6=AC),?= =?UTF-8?q?=20/game=20=EC=9D=80=20=EC=9B=B9=20=EA=B2=8C=EC=9E=84=EC=9D=84?= =?UTF-8?q?=20=EC=9B=B9=EB=B7=B0=EB=A1=9C=20=EB=9D=84=EC=9A=B0=EA=B3=A0=20?= =?UTF-8?q?=EC=95=B1=20=EC=A7=80=EC=97=AD=C2=B7=EB=A1=9C=EA=B7=B8=EC=9D=B8?= =?UTF-8?q?=EC=9D=84=20=EB=84=98=EA=B9=80(react-native-webview)=20(GA=20sh?= =?UTF-8?q?orts=5Fopen=C2=B7shorts=5Fview=C2=B7shorts=5Fsound)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude --- docs/이벤트_추적.md | 2 +- mobile/package.json | 1 + mobile/src/app/(tabs)/index.tsx | 2 + mobile/src/app/game.tsx | 85 ++++++++++++++++ mobile/src/app/shorts/[id].tsx | 127 ++++++++++++++++++++++++ mobile/src/app/shorts/index.tsx | 2 + mobile/src/components/shorts/player.tsx | 53 ++++++++++ mobile/src/components/shorts/rail.tsx | 45 +++++++++ package-lock.json | 16 +++ 9 files changed, 332 insertions(+), 1 deletion(-) create mode 100644 mobile/src/app/game.tsx create mode 100644 mobile/src/app/shorts/[id].tsx create mode 100644 mobile/src/app/shorts/index.tsx create mode 100644 mobile/src/components/shorts/player.tsx create mode 100644 mobile/src/components/shorts/rail.tsx diff --git a/docs/이벤트_추적.md b/docs/이벤트_추적.md index f7d08c7..2c932e7 100644 --- a/docs/이벤트_추적.md +++ b/docs/이벤트_추적.md @@ -78,7 +78,7 @@ GA4 태그(`gtag.js`, 측정 ID `G-D378J4X373`)를 `index.html`에 심고, 화 - 앱도 같은 이벤트 이름·값으로 `track()`을 부른다 (`mobile/src/lib/analytics.ts`). 모든 이벤트에 `platform: 'app'`이 붙는다. - **아직 GA4로 보내지 않는다 (2026-11-04).** Firebase Analytics(`google-services.json`)를 붙이면 앱 시작 때 `setAnalyticsSender`로 보내는 함수를 단다. 그 전까지 `track()`은 아무것도 보내지 않는다. 개발 빌드(`__DEV__`)는 붙인 뒤에도 보내지 않는다. -- 앱에서 부르는 곳: `sheet_open`(`components/sheets/index.tsx`), `view_gak`(`sheets/gak.tsx`), `select_content`(`sheets/article.tsx`), `login`·`sign_up`(`sheets/login.tsx`, 구글만), `region_change`(`sheets/region.tsx`·`lib/region.tsx`), `like`(`post/post-card.tsx` 글, `sheets/comments.tsx` 댓글), `comment`·`report`·`block`·`terms_agree`(`sheets/comments.tsx`), `share`(`lib/share-image.ts`), `hero_day_switch`(`today/hero.tsx`), `like`의 `hero_post`·`gak_post`(`lib/pinned-like.ts`). 레벨 창·레벨업 창은 `sheet_open`(`level`·`levelUp`)으로 잡힌다. 동네 이야기: `talk_post`(`components/talk/talk.tsx` `Composer`), `like`·`report`·`block`의 `talk`(`talk/talk.tsx`), `talk_comment`(`sheets/comments.tsx`), `feed_item_view`(`app/(tabs)/index.tsx` `useSeen`, 화면에 반쯤 보일 때). 내 각: `my_gak_save`(`lib/my-gak.ts`), 만들기·상세 창은 `sheet_open`(`mix`·`myGak`). +- 앱에서 부르는 곳: `sheet_open`(`components/sheets/index.tsx`), `view_gak`(`sheets/gak.tsx`), `select_content`(`sheets/article.tsx`), `login`·`sign_up`(`sheets/login.tsx`, 구글만), `region_change`(`sheets/region.tsx`·`lib/region.tsx`), `like`(`post/post-card.tsx` 글, `sheets/comments.tsx` 댓글), `comment`·`report`·`block`·`terms_agree`(`sheets/comments.tsx`), `share`(`lib/share-image.ts`), `hero_day_switch`(`today/hero.tsx`), `like`의 `hero_post`·`gak_post`(`lib/pinned-like.ts`). 레벨 창·레벨업 창은 `sheet_open`(`level`·`levelUp`)으로 잡힌다. 동네 이야기: `talk_post`(`components/talk/talk.tsx` `Composer`), `like`·`report`·`block`의 `talk`(`talk/talk.tsx`), `talk_comment`(`sheets/comments.tsx`), `feed_item_view`(`app/(tabs)/index.tsx` `useSeen`, 화면에 반쯤 보일 때). 내 각: `my_gak_save`(`lib/my-gak.ts`), 만들기·상세 창은 `sheet_open`(`mix`·`myGak`). 쇼츠: `shorts_open`·`shorts_view`·`shorts_sound`(`app/shorts/[id].tsx`). 구름 합치기 게임은 앱이 웹 `/game`을 웹뷰로 띄우므로 `game_start`·`game_round`·`game_over`는 웹 페이지가 보내고 `platform: 'web'`으로 찍힌다(앱 안 게임과 웹 게임을 GA에서 나눠 볼 수 없음). - 앱 `share`의 `ratio`는 `'card'` — 보이는 카드를 그대로 찍어 보내 비율을 고르지 않는다. ## GA4 설정 diff --git a/mobile/package.json b/mobile/package.json index 9e34aa5..712a45e 100644 --- a/mobile/package.json +++ b/mobile/package.json @@ -38,6 +38,7 @@ "react-native-svg": "15.15.4", "react-native-view-shot": "5.1.0", "react-native-web": "~0.21.0", + "react-native-webview": "13.16.1", "react-native-worklets": "0.10.1", "tailwindcss": "^4.3.3", "uniwind": "^1.12.2" diff --git a/mobile/src/app/(tabs)/index.tsx b/mobile/src/app/(tabs)/index.tsx index 5d3099f..3d20022 100644 --- a/mobile/src/app/(tabs)/index.tsx +++ b/mobile/src/app/(tabs)/index.tsx @@ -9,6 +9,7 @@ import { RefreshControl, ScrollView, View, type LayoutRectangle } from 'react-na import { MyGakRow } from '@/components/my-gak/my-gak'; import { isAppPost, PostCard, PostCardSkel } from '@/components/post/post-card'; +import { ShortsRail } from '@/components/shorts/rail'; import { Composer, TalkPost } from '@/components/talk/talk'; import { GakCard } from '@/components/today/gak-card'; import { Hero } from '@/components/today/hero'; @@ -99,6 +100,7 @@ export default function TodayScreen() { onScroll={(e) => seen.onScroll(e.nativeEvent.contentOffset.y, e.nativeEvent.layoutMeasurement.height)} > + {/* 실패 안내는 여기 한 번만, 각 카드 스켈레톤과 같은 크기로 */} diff --git a/mobile/src/app/game.tsx b/mobile/src/app/game.tsx new file mode 100644 index 0000000..dd5938c --- /dev/null +++ b/mobile/src/app/game.tsx @@ -0,0 +1,85 @@ +import { getAccessToken } from '@nalssigak/shared/api/auth'; +import { router } from 'expo-router'; +import { useRef, useState } from 'react'; +import { ActivityIndicator, View } from 'react-native'; +import { useSafeAreaInsets } from 'react-native-safe-area-context'; +import { WebView, type WebViewMessageEvent } from 'react-native-webview'; + +import { ScreenHeader } from '@/components/screen-header'; +import { Text } from '@/components/text'; +import { useAuth } from '@/lib/auth'; +import { useRegion } from '@/lib/region'; +import { useSheet } from '@/lib/sheet'; +import { SITE_URL } from '@/lib/site'; + +/** + * 웹 페이지가 뜨기 전에 넣는 스크립트: 앱의 지역·로그인을 웹 저장소에 옮기고, + * 게임 화면을 떠나는 이동(뒤로 버튼)과 '로그인하면 …' 버튼은 앱으로 알린다 (웹 구글 로그인은 앱 안 웹뷰에서 막힌다). + * 갱신 토큰은 넘기지 않는다: 웹이 갱신하면 앱이 가진 갱신 토큰이 쓸모없어질 수 있다. + */ +function bridge(region: unknown, token: string | null) { + return `(function () { + try { + localStorage.setItem('nalssigak.b.region', ${JSON.stringify(JSON.stringify(region))}); + ${token ? `localStorage.setItem('nalssigak.accessToken', ${JSON.stringify(token)});` : `localStorage.removeItem('nalssigak.accessToken');`} + localStorage.removeItem('nalssigak.refreshToken'); + } catch (e) {} + var post = function (t) { window.ReactNativeWebView.postMessage(t); }; + var check = function () { if (location.pathname !== '/game') post('leave'); }; + var push = history.pushState, replace = history.replaceState; + history.pushState = function () { push.apply(this, arguments); check(); }; + history.replaceState = function () { replace.apply(this, arguments); check(); }; + window.addEventListener('popstate', check); + document.addEventListener('click', function (e) { + var b = e.target && e.target.closest && e.target.closest('button'); + if (b && b.textContent && b.textContent.trim().indexOf('로그인') === 0) { e.preventDefault(); e.stopPropagation(); post('login'); } + }, true); +})(); +true;`; +} + +/** 구름 합치기 게임: 웹 /game 을 그대로 띄운다 (물리 엔진·캔버스라 웹과 같은 화면, 사용자 결정 11/04) */ +export default function GameScreen() { + const { region } = useRegion(); + const { loggedIn } = useAuth(); + const { open } = useSheet(); + const { top, bottom } = useSafeAreaInsets(); + const [failed, setFailed] = useState(false); + const left = useRef(false); + + const onMessage = (e: WebViewMessageEvent) => { + if (e.nativeEvent.data === 'leave' && !left.current) { + left.current = true; + if (router.canGoBack()) router.back(); + else router.replace('/'); + } + if (e.nativeEvent.data === 'login') open({ type: 'login' }); + }; + + if (failed) + return ( + + + 게임을 불러오지 못했어요. 인터넷 연결을 확인하고 다시 들어와 주세요. + + ); + + return ( + + {/* 로그인하면 토큰을 다시 넣어야 해서 로그인 여부로 새로 띄운다 */} + setFailed(true)} + startInLoadingState + renderLoading={() => } + overScrollMode="never" + bounces={false} + setSupportMultipleWindows={false} + style={{ backgroundColor: 'transparent' }} + /> + + ); +} diff --git a/mobile/src/app/shorts/[id].tsx b/mobile/src/app/shorts/[id].tsx new file mode 100644 index 0000000..780a6e0 --- /dev/null +++ b/mobile/src/app/shorts/[id].tsx @@ -0,0 +1,127 @@ +import { listShortsOptions } from '@nalssigak/shared/api/client/@tanstack/react-query.gen'; +import type { ShortItem } from '@nalssigak/shared/api/client/types.gen'; +import { useQuery } from '@tanstack/react-query'; +import { Image } from 'expo-image'; +import { router, useLocalSearchParams } from 'expo-router'; +import { useEffect, useRef, useState } from 'react'; +import { FlatList, Pressable, View, type ViewToken } from 'react-native'; +import { useSafeAreaInsets } from 'react-native-safe-area-context'; +import Svg, { Path } from 'react-native-svg'; + +import { ShortPlayer, type PlayerHandle } from '@/components/shorts/player'; +import { thumb } from '@/components/shorts/rail'; +import { Text } from '@/components/text'; +import { track } from '@/lib/analytics'; + +const BAR = 48; + +/** 쇼츠 화면: 그 영상부터 위아래로 넘겨 본다. 보이는 영상과 앞뒤만 소리 없이 미리 띄우고, 누르면 소리 켜기·끄기 (웹 ShortsPage) */ +export default function ShortsScreen() { + const { id } = useLocalSearchParams<{ id?: string }>(); + const q = useQuery(listShortsOptions()); + const { top, bottom } = useSafeAreaInsets(); + // 처음 들어온 영상만 시작점으로 쓴다 + const [firstId] = useState(id); + const listed = q.data?.items ?? []; + const items: ShortItem[] = firstId && listed.length && !listed.some((s) => s.id === firstId) ? [{ id: firstId, title: '' }, ...listed] : listed; + const start = Math.max(0, items.findIndex((s) => s.id === firstId)); + const [at, setAt] = useState(start); + const [sound, setSound] = useState(false); + const [ready, setReady] = useState>(new Set()); + const [box, setBox] = useState({ w: 0, h: 0 }); + const players = useRef(new Map()); + const soundRef = useRef(false); + const atRef = useRef(start); + + useEffect(() => { + if (firstId) track('shorts_open', { video_id: firstId }); + }, [firstId]); + + // 넘어온 영상만 처음부터 다시 틀고 소리를 맞춘다. 앞뒤는 소리만 끈다 (멈추면 유튜브 버튼이 떠서 멈추지 않는다) + useEffect(() => { + for (const [i, p] of players.current) { + if (i === at) { + p.command('seekTo', [0, true]); + p.command(soundRef.current ? 'unMute' : 'mute'); + p.command('playVideo'); + } else p.command('mute'); + } + }, [at]); + + // FlatList 는 이 함수가 바뀌면 안 되어 처음 한 번만 만든다 + const [onViewable] = useState(() => ({ viewableItems }: { viewableItems: ViewToken[] }) => { + const i = viewableItems[0]?.index; + if (i == null || i === atRef.current) return; + atRef.current = i; + setAt(i); + const s = viewableItems[0].item; + track('shorts_view', { video_id: s.id, index: i }); + }); + + const toggleSound = () => { + const on = !soundRef.current; + soundRef.current = on; + setSound(on); + track('shorts_sound', { on }); + players.current.get(at)?.command(on ? 'unMute' : 'mute'); + }; + + const close = () => (router.canGoBack() ? router.back() : router.replace('/')); + // 9:16 을 칸 안에 맞춘다 + const w = Math.min(box.w, (box.h * 9) / 16); + const h = (w * 16) / 9; + + return ( + + {!!items[at] && } + + + + + + + + + {sound ? '소리 끄기' : '소리 켜기'} + + + setBox({ w: e.nativeEvent.layout.width, h: e.nativeEvent.layout.height })}> + {box.h > 0 && items.length > 0 && ( + s.id} + pagingEnabled + showsVerticalScrollIndicator={false} + initialScrollIndex={start} + getItemLayout={(_, i) => ({ length: box.h, offset: box.h * i, index: i })} + onViewableItemsChanged={onViewable} + viewabilityConfig={{ itemVisiblePercentThreshold: 60 }} + windowSize={3} + renderItem={({ item: s, index: i }) => ( + + + + {/* 릴스처럼 앞뒤 영상을 소리 없이 미리 받아 둔다. 첫 장면 전엔 표지가 보이게 숨긴다 */} + {Math.abs(i - at) <= 1 && ( + + { + if (p) players.current.set(i, p); + else players.current.delete(i); + }} + onPlaying={() => setReady((r) => (r.has(i) ? r : new Set(r).add(i)))} + /> + + )} + {/* 누르면 소리 켜기·끄기, 위아래로 밀면 목록이 넘어간다 */} + + + + )} + /> + )} + + + ); +} diff --git a/mobile/src/app/shorts/index.tsx b/mobile/src/app/shorts/index.tsx new file mode 100644 index 0000000..66ce3ae --- /dev/null +++ b/mobile/src/app/shorts/index.tsx @@ -0,0 +1,2 @@ +// 아이콘 줄 '쇼츠'(/shorts)는 첫 영상부터 +export { default } from './[id]'; diff --git a/mobile/src/components/shorts/player.tsx b/mobile/src/components/shorts/player.tsx new file mode 100644 index 0000000..d00318d --- /dev/null +++ b/mobile/src/components/shorts/player.tsx @@ -0,0 +1,53 @@ +import { useImperativeHandle, useRef, type Ref } from 'react'; +import { WebView } from 'react-native-webview'; + +import { SITE_URL } from '@/lib/site'; + +const YT_ORIGIN = 'https://www.youtube-nocookie.com'; + +export type PlayerFunc = 'playVideo' | 'seekTo' | 'mute' | 'unMute'; +export type PlayerHandle = { command: (func: PlayerFunc, args?: unknown[]) => void }; + +function embed(id: string) { + const q = new URLSearchParams({ autoplay: '1', mute: '1', playsinline: '1', loop: '1', playlist: id, controls: '0', rel: '0', modestbranding: '1', enablejsapi: '1', origin: SITE_URL }); + return `${YT_ORIGIN}/embed/${id}?${q}`; +} + +/** + * 유튜브 플레이어를 날씨각 주소를 기준으로 한 작은 문서 안 iframe 으로 띄운다. + * 앱 웹뷰에서 embed 주소를 바로 열면 보낸 곳(Referer)이 없어 유튜브가 막는다. 웹과 같이 IFrame API 메시지로 재생 상태를 받고 명령한다 + */ +function html(id: string) { + return ` + +`; +} + +/** 소리 없이 자동재생하는 쇼츠 플레이어. 첫 장면이 나오면 onPlaying (그 전엔 위에 표지를 덮어 둔다) */ +export function ShortPlayer({ id, onPlaying, ref }: { id: string; onPlaying: () => void; ref?: Ref }) { + const view = useRef(null); + useImperativeHandle(ref, () => ({ + command: (func, args = []) => view.current?.injectJavaScript(`window.cmd && window.cmd(${JSON.stringify(func)}, ${JSON.stringify(args)}); true;`), + })); + return ( + e.nativeEvent.data === 'playing' && onPlaying()} + mediaPlaybackRequiresUserAction={false} + allowsInlineMediaPlayback + scrollEnabled={false} + setSupportMultipleWindows={false} + style={{ backgroundColor: 'transparent' }} + /> + ); +} diff --git a/mobile/src/components/shorts/rail.tsx b/mobile/src/components/shorts/rail.tsx new file mode 100644 index 0000000..57f6cdb --- /dev/null +++ b/mobile/src/components/shorts/rail.tsx @@ -0,0 +1,45 @@ +import { listShortsOptions } from '@nalssigak/shared/api/client/@tanstack/react-query.gen'; +import { useQuery } from '@tanstack/react-query'; +import { Image } from 'expo-image'; +import { LinearGradient } from 'expo-linear-gradient'; +import { Link } from 'expo-router'; +import { Pressable, View } from 'react-native'; + +import { Text } from '@/components/text'; +import { Rail } from '@/components/ui'; + +const SKELS = [0, 1, 2, 3]; + +export const thumb = (id: string) => `https://i.ytimg.com/vi/${id}/hqdefault.jpg`; + +/** 오늘 화면 히어로 아래 쇼츠 줄. 누르면 쇼츠 화면에서 위아래로 넘겨 본다. 앱은 데이터를 아끼려고 줄에서는 표지만 (웹은 첫 카드를 소리 없이 재생) */ +export function ShortsRail() { + const q = useQuery(listShortsOptions()); + const items = q.data?.items ?? []; + if (q.isPending) + return ( + + {SKELS.map((i) => ( + + ))} + + ); + if (!items.length) return null; + return ( + + + {items.map((s) => ( + + + + + + {s.title} + + + + ))} + + + ); +} diff --git a/package-lock.json b/package-lock.json index ba07a31..6f11819 100644 --- a/package-lock.json +++ b/package-lock.json @@ -76,6 +76,7 @@ "react-native-svg": "15.15.4", "react-native-view-shot": "5.1.0", "react-native-web": "~0.21.0", + "react-native-webview": "13.16.1", "react-native-worklets": "0.10.1", "tailwindcss": "^4.3.3", "uniwind": "^1.12.2" @@ -15546,6 +15547,21 @@ "peerDependencies": { "expo": "*" } + }, + "node_modules/react-native-webview": { + "version": "13.16.1", + "resolved": "https://registry.npmjs.org/react-native-webview/-/react-native-webview-13.16.1.tgz", + "integrity": "sha512-If0eHhoEdOYDcHsX+xBFwHMbWBGK1BvGDQDQdVkwtSIXiq1uiqjkpWVP2uQ1as94J0CzvFE9PUNDuhiX0Z6ubw==", + "license": "MIT", + "peer": true, + "dependencies": { + "escape-string-regexp": "^4.0.0", + "invariant": "2.2.4" + }, + "peerDependencies": { + "react": "*", + "react-native": "*" + } } } }