import type { TimeKind } from '@nalssigak/shared/lib'; import { holidayOn, type Holiday } from '@nalssigak/shared/lib/holiday'; import { Image } from 'expo-image'; import { LinearGradient } from 'expo-linear-gradient'; import { useEffect, useState } from 'react'; import { StyleSheet, useWindowDimensions, View, type DimensionValue } from 'react-native'; import Animated, { cancelAnimation, Easing, interpolate, useAnimatedStyle, useReducedMotion, useSharedValue, withDelay, withRepeat, withTiming } from 'react-native-reanimated'; import { useSky } from '@/lib/sky'; const KINDS: TimeKind[] = ['morning', 'day', 'sunset', 'night']; const SKY: Record = { morning: { colors: ['#ffe0c4', '#fff0e2', '#e4f2ff'], locations: [0, 0.38, 1] }, day: { colors: ['#cde7ff', '#e9f5ff', '#f7fbff'], locations: [0, 0.45, 1] }, sunset: { colors: ['#ffd0b5', '#f9c3cf', '#ddd2f6'], locations: [0, 0.42, 1] }, night: { colors: ['#0e1433', '#1b2356', '#2a2e6e'], locations: [0, 0.5, 1] }, }; const STARS = Array.from({ length: 46 }, (_, i) => ({ left: `${(i * 41 + 7) % 100}%`, top: `${(i * 67 + 3) % 96}%`, size: 1 + (i % 3) * 0.8, period: (3 + (i % 5)) * 1000, delay: ((i * 0.7) % 6) * 1000 }) as const); /** 시간대 하나의 하늘 판. 고른 시간대만 1.4초 동안 서서히 드러난다 */ function Layer({ kind, on, reduce }: { kind: TimeKind; on: boolean; reduce: boolean }) { const shown = useSharedValue(on ? 1 : 0); useEffect(() => { shown.value = reduce ? (on ? 1 : 0) : withTiming(on ? 1 : 0, { duration: 1400, easing: Easing.ease }); }, [on, reduce, shown]); const style = useAnimatedStyle(() => ({ opacity: shown.value })); return ( ); } /** 밤 별: 제각각 주기로 반짝인다 */ function Star({ star, reduce }: { star: (typeof STARS)[number]; reduce: boolean }) { const glow = useSharedValue(0); useEffect(() => { if (reduce) return; glow.value = withDelay(star.delay, withRepeat(withTiming(1, { duration: star.period / 2, easing: Easing.inOut(Easing.ease) }), -1, true)); return () => cancelAnimation(glow); }, [reduce, glow, star]); const style = useAnimatedStyle(() => ({ opacity: reduce ? 0.7 : 0.25 + glow.value * 0.75 })); return ; } export type ShootSpec = { top: DimensionValue; left: DimensionValue; len: number; dur: number; dl: number }; // 별똥별: 위치·길이·주기를 엇갈려 몇 초마다 하나씩 떨어지게 (웹 BLayout SHOOTS, 밀리초) const SHOOTS: ShootSpec[] = [ { top: '8%', left: '78%', len: 110, dur: 7000, dl: 1000 }, { top: '22%', left: '46%', len: 80, dur: 9000, dl: 3500 }, { top: '5%', left: '30%', len: 95, dur: 8000, dl: 5500 }, { top: '36%', left: '88%', len: 70, dur: 10000, dl: 2200 }, { top: '52%', left: '62%', len: 90, dur: 11000, dl: 7000 }, { top: '14%', left: '96%', len: 120, dur: 12000, dl: 9000 }, ]; /** 별똥별 하나: 주기 끝 14% 동안만 비스듬히 240px 미끄러지며 반짝 (웹 .b-shoot). 동작 줄이기면 그리지 않는다 */ export function Shoot({ top, left, len, dur, dl }: ShootSpec) { const reduce = useReducedMotion(); const p = useSharedValue(0); useEffect(() => { if (reduce) return; p.value = withDelay(dl, withRepeat(withTiming(1, { duration: dur, easing: Easing.in(Easing.ease) }), -1, false)); return () => cancelAnimation(p); }, [reduce, dur, dl, p]); const style = useAnimatedStyle(() => ({ opacity: interpolate(p.value, [0, 0.86, 0.89, 1], [0, 0, 1, 0]), transform: [{ rotate: '-24deg' }, { translateX: interpolate(p.value, [0, 0.86, 1], [0, 0, -240]) }], })); if (reduce) return null; return ( ); } /** 화면 전체 하늘: 시간대별 색이 서서히 바뀌고, 밤에는 별이 반짝이고 별똥별이 떨어진다 */ // 기념일 소품: 투명 배경 그림을 화면 네 귀퉁이에 (웹 b.css .b-sky-holiday, frontend/public/b/holiday, 4:5 그림) const PROPS: Record = { halloween: [require('../../../frontend/public/b/holiday/halloween-tl.webp'), require('../../../frontend/public/b/holiday/halloween-tr.webp'), require('../../../frontend/public/b/holiday/halloween-bl.webp'), require('../../../frontend/public/b/holiday/halloween-br.webp')], pepero: [require('../../../frontend/public/b/holiday/pepero-tl.webp'), require('../../../frontend/public/b/holiday/pepero-tr.webp'), require('../../../frontend/public/b/holiday/pepero-bl.webp'), require('../../../frontend/public/b/holiday/pepero-br.webp')], christmas: [require('../../../frontend/public/b/holiday/christmas-tl.webp'), require('../../../frontend/public/b/holiday/christmas-tr.webp'), require('../../../frontend/public/b/holiday/christmas-bl.webp'), require('../../../frontend/public/b/holiday/christmas-br.webp')], chuseok: [require('../../../frontend/public/b/holiday/chuseok-tl.webp'), require('../../../frontend/public/b/holiday/chuseok-tr.webp'), require('../../../frontend/public/b/holiday/chuseok-bl.webp'), require('../../../frontend/public/b/holiday/chuseok-br.webp')], suneung: [require('../../../frontend/public/b/holiday/suneung-tl.webp'), require('../../../frontend/public/b/holiday/suneung-tr.webp'), require('../../../frontend/public/b/holiday/suneung-bl.webp'), require('../../../frontend/public/b/holiday/suneung-br.webp')], newyear: [require('../../../frontend/public/b/holiday/newyear-tl.webp'), require('../../../frontend/public/b/holiday/newyear-tr.webp'), require('../../../frontend/public/b/holiday/newyear-bl.webp'), require('../../../frontend/public/b/holiday/newyear-br.webp')], }; const CORNERS = [{ top: 0, left: 0 }, { top: 0, right: 0 }, { bottom: 0, left: 0 }, { bottom: 0, right: 0 }] as const; /** 기념일 기간에만 네 귀퉁이 소품. 폰은 반씩 나눠 폭을 채우고 넓은 화면은 300 으로. 밤엔 조금 어둡게 */ function HolidayProps({ night }: { night: boolean }) { const [holiday] = useState(holidayOn); const { width } = useWindowDimensions(); if (!holiday) return null; const w = Math.min(width / 2, 300); return ( <> {PROPS[holiday.key].map((src, i) => ( ))} ); } export function SkyBg() { const { kind } = useSky(); const reduce = useReducedMotion(); return ( {KINDS.map((k) => ( ))} {kind === 'night' && STARS.map((s, i) => )} {kind === 'night' && SHOOTS.map((s, i) => )} ); }