- Expo SDK 57 + expo-router, react-query, Uniwind(Tailwind v4), SecureStore 토큰 - Metro 가 앱의 react(19.2.3)만 쓰게 고정 (루트에는 웹용 react 19.3.0) - 탭 5개·위 막대·시간대 하늘 배경·밤 테마, 오늘 히어로·각 순위·행사/TOP5/계절 띠 - 남은 이전 작업은 TODO.md 앱 마이그레이션 표
31 lines
1.4 KiB
TypeScript
31 lines
1.4 KiB
TypeScript
import { kindOfHour, kst, type TimeKind } from '@nalssigak/shared/lib';
|
|
import { createContext, use, useEffect, useMemo, useState, type ReactNode } from 'react';
|
|
import { Uniwind } from 'uniwind';
|
|
|
|
/** 화면 전체 하늘의 시간대. 히어로에서 고른 미리보기는 탭을 옮겨도 유지된다 */
|
|
export type SkyApi = { kind: TimeKind; preview: TimeKind | null; setServerKind: (k: TimeKind | null) => void; setPreview: (k: TimeKind | null) => void };
|
|
|
|
const SkyContext = createContext<SkyApi | null>(null);
|
|
|
|
export function useSky() {
|
|
const ctx = use(SkyContext);
|
|
if (!ctx) throw new Error('useSky must be used inside SkyProvider');
|
|
return ctx;
|
|
}
|
|
|
|
export function SkyProvider({ children }: { children: ReactNode }) {
|
|
const [preview, setPreview] = useState<TimeKind | null>(null);
|
|
const [serverKind, setServerKind] = useState<TimeKind | null>(null);
|
|
const [now, setNow] = useState(() => new Date());
|
|
useEffect(() => {
|
|
const id = setInterval(() => setNow(new Date()), 60000);
|
|
return () => clearInterval(id);
|
|
}, []);
|
|
const t = kst(now);
|
|
const kind = preview ?? serverKind ?? kindOfHour(t.h, t.mo, t.mi);
|
|
// 밤에만 어두운 테마 (기기 다크 모드와 상관없이 하늘 시간대를 따른다)
|
|
useEffect(() => Uniwind.setTheme(kind === 'night' ? 'dark' : 'light'), [kind]);
|
|
const api = useMemo(() => ({ kind, preview, setPreview, setServerKind }), [kind, preview]);
|
|
return <SkyContext value={api}>{children}</SkyContext>;
|
|
}
|