feat: React Native(Expo) 앱 추가 — 탭 구조와 오늘 화면

- Expo SDK 57 + expo-router, react-query, Uniwind(Tailwind v4), SecureStore 토큰
- Metro 가 앱의 react(19.2.3)만 쓰게 고정 (루트에는 웹용 react 19.3.0)
- 탭 5개·위 막대·시간대 하늘 배경·밤 테마, 오늘 히어로·각 순위·행사/TOP5/계절 띠
- 남은 이전 작업은 TODO.md 앱 마이그레이션 표
This commit is contained in:
minaChoi committed 2026-10-14 14:27:47 +09:00
1 parent 2ab2271d61
commit e52f93fdbb
56 files changed
+1211

No files matched your search

+147
View File
@@ -0,0 +1,147 @@
import type { Hero as HeroData, ResWeatherToday, TopIndex } from '@nalssigak/shared/api/client/types.gen';
import { kindOfHour, kst, type Load, type TimeKind, WEEKDAYS } from '@nalssigak/shared/lib';
import { KINDS, moonPath, PREVIEW, SLOT_KEY, WANING, WEATHER_ICON, weatherOf } from '@nalssigak/shared/lib/today';
import { deg, slotAt } from '@nalssigak/shared/lib/weatherText';
import { useEffect, useState, type ReactNode } from 'react';
import { Pressable, Text, View } from 'react-native';
import { LinearGradient } from 'expo-linear-gradient';
import Svg, { Defs, Path, RadialGradient, Rect, Stop } from 'react-native-svg';
import { Ic, Skel } from '@/components/ui';
import { useSky } from '@/lib/sky';
type Mode = 'now' | TimeKind;
const HERO_BG: Record<TimeKind | 'gray', readonly [string, string, string]> = {
morning: ['#ffd9b8', '#ffe9d4', '#dff0ff'],
day: ['#9fd3ff', '#cfe9ff', '#f1f8ff'],
sunset: ['#4c42b0', '#6a48b0', '#9a4a88'],
night: ['#141b3d', '#27306a', '#3d3f86'],
gray: ['#a9bbd0', '#cbd7e4', '#eef2f7'],
};
// 가운데 해(낮)·달(저녁·밤) 색과 글자색
const ORB: Record<'sun' | 'sunset' | 'night', { stops: [string, string, string, string]; text: string }> = {
sun: { stops: ['#fff5cf', '#ffc86e', '#ff8e4e', '#ee6436'], text: '#5c1f08' },
sunset: { stops: ['#fff4e6', '#ffd9b8', '#f7a991', '#e07a8f'], text: '#4a2442' },
night: { stops: ['#ffffff', '#e7e3ff', '#b9b0f2', '#8f86d9'], text: '#2b2a5c' },
};
const STARS = Array.from({ length: 26 }, (_, i) => ({ left: `${(i * 37) % 100}%`, top: `${(i * 53) % 60}%`, opacity: 0.4 + ((i * 7) % 6) / 10 }) as const);
function useNow(ms = 20000) {
const [now, setNow] = useState(() => new Date());
useEffect(() => {
const id = setInterval(() => setNow(new Date()), ms);
return () => clearInterval(id);
}, [ms]);
return now;
}
const failed = (load: Load) => load === 'error' || load === 'retrying';
// 값이 오기 전엔 스켈레톤, 못 불러왔거나 값이 없으면 '?'
function heroVal(load: Load, v: ReactNode, skel: string) {
if (v != null) return v;
if (load === 'loading') return <Skel className={skel} />;
return <Text className="opacity-50">?</Text>;
}
type Props = { hero?: HeroData | null; today?: ResWeatherToday; ranked: TopIndex[]; feedLoad: Load; todayLoad: Load };
export function Hero({ hero, today, ranked, feedLoad, todayLoad }: Props) {
const { preview, setServerKind, setPreview } = useSky();
const mode: Mode = preview ?? 'now';
const t = kst(useNow());
const nowKind = hero?.sky_mode ?? kindOfHour(t.h, t.mo, t.mi);
const kind = mode === 'now' ? nowKind : mode;
// 화면 전체 하늘 배경도 같은 시간대로 맞춘다
useEffect(() => setServerKind(hero?.sky_mode ?? null), [hero?.sky_mode, setServerKind]);
const slots = today?.slots ?? [];
// 지금은 가장 가까운 3시간 칸. 시간대는 그 시각 칸, 비어 있으면(지난 새벽 칸 등) 그 뒤 첫 예보 칸
const slotOf = (k: Mode) => {
if (k === 'now') {
const known = slots.filter((x) => x.temp_c != null);
const at = t.h + t.mi / 60;
return known.length ? known.reduce((a, b) => (Math.abs(kst(b.at).h - at) < Math.abs(kst(a.at).h - at) ? b : a)) : undefined;
}
const h = PREVIEW[k].hour;
const s = slots.length ? slotAt(slots, h) : undefined;
return s?.temp_c != null ? s : (slots.find((x) => kst(x.at).h > h && x.temp_c != null) ?? s);
};
const weather = weatherOf(slotOf(mode));
const slotScore = mode === 'now' ? undefined : hero?.weather_slots?.[SLOT_KEY[mode]];
const score = slotScore ?? hero?.weather_score;
const slotTop = mode === 'now' ? undefined : ranked.find((g) => g.active);
const top1 = slotTop ?? hero?.top1;
const dark = kind === 'sunset' || kind === 'night';
const moon = dark && hero?.moon_name && hero.moon_pct != null ? { pct: hero.moon_pct, waning: WANING.includes(hero.moon_name) } : null;
const when = mode === 'now' || mode === nowKind ? '지금' : PREVIEW[mode].label;
const bubble = slotTop ? (slotTop.score >= 70 ? `${when}은 ${slotTop.name}!` : `${when}은 쉬어 가요`) : hero ? (hero.bubble ?? '지금은 쉬어 가요') : failed(feedLoad) ? '앗, 날씨를 못 불러왔어요' : null;
const status = hero?.status ?? [];
const gray = !dark && weather !== 'clear' && weather !== 'partly';
const orb = ORB[kind === 'sunset' ? 'sunset' : kind === 'night' ? 'night' : 'sun'];
const text = dark ? 'text-white' : 'text-[#28304a]';
return (
<View className="mx-3 mt-1 overflow-hidden rounded-[28px] px-4 pt-3 pb-3">
<LinearGradient colors={HERO_BG[gray ? 'gray' : kind]} locations={kind === 'night' ? [0, 0.6, 1] : [0, 0.5, 1]} style={{ position: 'absolute', inset: 0 }} />
{kind === 'night' && STARS.map((s, i) => <View key={i} className="absolute size-[3px] rounded-full bg-white" style={{ left: s.left, top: s.top, opacity: s.opacity }} />)}
<Text className={`text-[14px] font-bold opacity-80 ${text}`}>
{t.mo}월 {t.d}일 {WEEKDAYS[t.wd]}요일
</Text>
<View className="h-[146px] items-center">
<View className="mt-2 size-32 items-center justify-center" style={{ boxShadow: `0 20px 40px ${kind === 'night' ? 'rgb(190 180 255 / 0.35)' : kind === 'sunset' ? 'rgb(255 150 110 / 0.4)' : 'rgb(240 106 58 / 0.32)'}`, borderRadius: 64 }}>
<Svg viewBox="-1 -1 2 2" width={128} height={128} style={{ position: 'absolute' }}>
<Defs>
<RadialGradient id="orb" cx="-0.32" cy="-0.4" r="1.4" gradientUnits="userSpaceOnUse">
<Stop offset="0" stopColor={orb.stops[0]} />
<Stop offset="0.3" stopColor={orb.stops[1]} />
<Stop offset="0.68" stopColor={orb.stops[2]} />
<Stop offset="1" stopColor={orb.stops[3]} />
</RadialGradient>
</Defs>
<Rect x="-1" y="-1" width="2" height="2" rx="1" fill="url(#orb)" opacity={gray ? 0.85 : 1} />
{/* 안 보이는 쪽을 덮어 오늘 밤 달 모양으로 */}
{moon && <Path d={moonPath(moon.pct, 1, false)} fill={kind === 'sunset' ? 'rgb(96 40 86 / .55)' : 'rgb(34 30 86 / .62)'} transform={moon.waning ? 'scale(-1,1)' : undefined} />}
</Svg>
<Text className="font-jua text-[12px]" style={{ color: orb.text }}>
{failed(feedLoad) ? '점수를 못 불러왔어요' : `${slotScore != null && mode !== 'now' ? PREVIEW[mode].label : '지금'} 날씨 점수`}
</Text>
<Text className="font-bagel text-[52px] leading-[52px]" style={{ color: orb.text }}>
{heroVal(feedLoad, score, 'w-[84px] h-10')}
</Text>
</View>
</View>
<View className="items-center">
{bubble ? <Text className={`text-center font-jua text-[24px] leading-tight ${text}`}>{bubble}</Text> : <Skel className="h-6 w-[160px]" />}
{top1?.summary ? <Text className={`mt-0.5 text-center text-[15px] font-bold opacity-80 ${text}`}>{top1.summary}</Text> : feedLoad === 'loading' ? <Skel className="mt-1 w-[140px]" /> : null}
{/* 상태 한 줄: 습도·불쾌지수·자외선·미세먼지 단계 이름. 조심할 것만 색 */}
{status.length > 0 && (
<Text className={`mt-1.5 text-center font-jua text-[14px] ${text}`}>
{status.map((x, i) => (
<Text key={x.label}>
{i > 0 && <Text className="opacity-30"> · </Text>}
<Text style={x.tone === 'warn' ? { color: dark ? '#ffb38a' : '#d4552a' } : undefined}>
<Text className={x.tone !== 'warn' ? 'opacity-75' : undefined}>{x.label}</Text> {x.value}
</Text>
</Text>
))}
</Text>
)}
</View>
<View className="mt-2.5 flex-row gap-1 rounded-[18px] p-[3px]" style={{ backgroundColor: dark ? 'rgb(255 255 255 / 0.14)' : 'rgb(255 255 255 / 0.42)' }} accessibilityRole="tablist" accessibilityLabel="하루 흐름, 누르면 그 시간대 하늘로">
{KINDS.map((k) => {
const isNow = k === nowKind;
const s = slotOf(isNow ? 'now' : k);
const on = k === kind;
return (
<Pressable key={k} accessibilityRole="tab" accessibilityState={{ selected: on }} onPress={() => setPreview(isNow ? null : k)} className={`flex-1 items-center rounded-[14px] py-1.5 ${on ? 'bg-white' : ''}`} style={on ? { boxShadow: '0 4px 12px rgb(40 48 74 / 0.1)' } : undefined}>
<Text className={`text-[13px] font-bold ${on ? 'text-[#d4552a]' : `opacity-75 ${text}`}`}>{isNow ? '지금' : PREVIEW[k].label}</Text>
<Ic name={k === 'night' && weatherOf(s) === 'clear' ? 'moon' : WEATHER_ICON[weatherOf(s)]} size={22} style={{ marginVertical: 2 }} />
<Text className={`font-jua text-[15px] ${on ? 'text-[#28304a]' : text}`}>{heroVal(todayLoad, s?.temp_c != null ? deg(s.temp_c) : null, 'w-7')}</Text>
</Pressable>
);
})}
</View>
</View>
);
}
+135
View File
@@ -0,0 +1,135 @@
import type { BandArticle, BandEvent, TopIndex } from '@nalssigak/shared/api/client/types.gen';
import { cardBg, MEDALS } from '@nalssigak/shared/lib';
import { LinearGradient } from 'expo-linear-gradient';
import { Link, type Href } from 'expo-router';
import type { ReactNode } from 'react';
import { Pressable, Text, View } from 'react-native';
import { Ic, Rail, Sec, Skel, Thumb } from '@/components/ui';
import { CARD_BG, BAND_BG } from '@/lib/colors';
import { useSky } from '@/lib/sky';
const CARD = 'overflow-hidden rounded-[22px] border-b-[5px] border-shade bg-card';
/** 오늘의 각 순위: 동그라미 + 이름 + 점수. 지금 시간대가 아닌 각은 흐리게 */
export function Stories({ items }: { items: TopIndex[] }) {
return (
<Rail>
{items.map((g, i) => (
<View key={g.index_id} accessibilityLabel={g.active ? `${g.rank}위 ${g.name} ${g.score}점` : `${g.name}, 지금 시간대 아님`} className={`w-[72px] items-center gap-1 ${g.active ? '' : 'opacity-55'}`}>
<View className="size-[68px]">
{!g.active || g.score < 50 ? (
<View className="absolute inset-0 rounded-full bg-[#d6deea]" />
) : (
<LinearGradient colors={['#ff7a45', '#ffc86e', '#8fcaff']} start={{ x: 0, y: 0 }} end={{ x: 1, y: 1 }} style={{ position: 'absolute', inset: 0, borderRadius: 34 }} />
)}
<View className="m-[3px] flex-1 items-center justify-center rounded-full border-[3px] border-page bg-page">
<Ic name={g.icon} size={42} />
</View>
{i < 3 && g.active && <Ic name={MEDALS[i]} size={25} style={{ position: 'absolute', right: -4, bottom: -4 }} />}
</View>
<Text numberOfLines={1} className="font-jua text-[13px] text-ink">
{g.name}
</Text>
{g.active ? <Text className="font-bagel text-[12.5px] leading-[14px] text-orange">{g.score}</Text> : <Text className="text-[11px] leading-[14px] font-extrabold text-ink3">지금 아님</Text>}
</View>
))}
</Rail>
);
}
const SKELS = Array.from({ length: 6 }, (_, i) => i);
export function StoriesSkel() {
return (
<Rail>
{SKELS.map((i) => (
<View key={i} className="w-[72px] items-center gap-1.5">
<View className="size-[68px] rounded-full bg-skel" />
<Skel className="w-12" />
<Skel className="w-6" />
</View>
))}
</Rail>
);
}
function Band({ tone, title, sub, to, children }: { tone: 1 | 2 | 3; title: string; sub: string; to: Href; children: ReactNode }) {
const { kind } = useSky();
return (
<View className="mt-3.5 pb-3.5" accessibilityLabel={title}>
<LinearGradient colors={BAND_BG[kind === 'night' ? 'night' : 'day'][tone]} style={{ position: 'absolute', inset: 0 }} />
<View className="-mt-[6px]">
<Sec title={title} sub={sub} more={to} />
</View>
{children}
</View>
);
}
function useCardBg() {
const { kind } = useSky();
return CARD_BG[kind === 'night' ? 'night' : 'day'];
}
export function EventsBand({ events }: { events: BandEvent[] }) {
const bg = useCardBg();
return (
<Band tone={1} title="이번 주 가까운 행사" sub="30km 안 · 날씨까지 같이 보고 골라요" to="/week">
<Rail>
{events.map((e, i) => (
<Link key={e.event_id} href="/week" asChild>
<Pressable className={`w-[200px] ${CARD}`}>
<Thumb image={e.image} icon={e.icon} iconSize={76} className="h-[116px]">
<LinearGradient colors={bg[cardBg(e.icon, i)]} style={{ position: 'absolute', inset: 0, zIndex: -1 }} />
<View className={`absolute top-2.5 left-2.5 rounded-full px-2 py-[3px] ${e.status_label === '진행 중' ? 'bg-[#1f9d62]' : 'bg-orange'}`}>
<Text className="text-[11.5px] font-extrabold text-white">{e.status_label}</Text>
</View>
</Thumb>
<Text className="px-3 pt-2.5 pb-3 font-jua text-[16.5px] leading-snug text-ink">{e.name}</Text>
</Pressable>
</Link>
))}
</Rail>
</Band>
);
}
export function TopBand({ items, sub }: { items: TopIndex[]; sub: string }) {
return (
<Band tone={2} title="지금 뜨는 각 TOP 5" sub={sub} to="/gak">
<Rail>
{items.slice(0, 5).map((g, i) => (
<View key={g.index_id} className="w-[138px] gap-1 rounded-[22px] border-b-[5px] border-shade bg-card p-3">
{i < 3 ? <Ic name={MEDALS[i]} size={26} style={{ position: 'absolute', top: 8, left: 8 }} /> : <Text className="absolute top-2.5 left-3 font-jua text-ink3">{i + 1}위</Text>}
<Ic name={g.icon} size={58} style={{ alignSelf: 'center' }} />
<Text className="font-jua text-base text-ink">{g.name}</Text>
<Text className="font-bagel text-[22px] leading-[24px] text-orange">{g.score}</Text>
{g.summary && <Text className="text-xs font-semibold text-ink2">{g.summary}</Text>}
</View>
))}
</Rail>
</Band>
);
}
export function SeasonBand({ news }: { news: BandArticle[] }) {
const bg = useCardBg();
return (
<Band tone={3} title="이번 주 계절 이야기" sub="예년 이맘때의 소식" to="/season">
<Rail>
{news.map((a) => (
<View key={a.article_id} className={`w-[200px] ${CARD}`}>
<Thumb image={a.image} icon={a.icon} iconSize={76} className="h-[116px]">
<LinearGradient colors={bg[cardBg(a.icon, a.article_id)]} style={{ position: 'absolute', inset: 0, zIndex: -1 }} />
</Thumb>
<View className="px-3 pt-2.5 pb-3">
<Text className="font-jua text-[16.5px] leading-snug text-ink">{a.title}</Text>
<Text className="text-[12.5px] font-semibold text-ink2">{a.meta}</Text>
</View>
</View>
))}
</Rail>
</Band>
);
}