import { AVATAR_COLORS, moodEmoji, naverMap, type Load } from '@nalssigak/shared/lib'; import { Image, type ImageStyle } from 'expo-image'; import { LinearGradient } from 'expo-linear-gradient'; import { Link, type Href } from 'expo-router'; import { useEffect, useState, type ReactNode } from 'react'; import Animated, { cancelAnimation, Easing, useAnimatedStyle, useReducedMotion, useSharedValue, withRepeat, withTiming } from 'react-native-reanimated'; import { Linking, Pressable, ScrollView, View, type StyleProp, type ViewStyle } from 'react-native'; import { Text } from '@/components/text'; import { ICONS } from '@/lib/icons'; import { imageUri } from '@/lib/site'; /** 아이콘 이름 → 그림. 'none'(데이터 없는 칸)은 빈 자리, 모르는 이름은 구름 낀 해 */ export function Ic({ name, size, style }: { name: string; size: number; style?: StyleProp }) { if (name === 'none') return ; return ; } type Stops = readonly [string, string, ...string[]]; /** 위에서 아래로 흐르는 그라데이션 (웹 linear-gradient(180deg, ...)) */ export function Grad({ colors, locations, className, style, children }: { colors: Stops; locations?: readonly [number, number, ...number[]]; className?: string; style?: StyleProp; children?: ReactNode }) { return ( {children} ); } /** 사진이 있으면 사진, 없거나 못 불러오면 아이콘 */ export function Thumb({ image, icon, iconSize, className, style, children }: { image?: string | null; icon: string; iconSize: number; className?: string; style?: StyleProp; children?: ReactNode }) { const [failed, setFailed] = useState(null); const photo = image && image !== failed ? image : null; return ( {photo ? setFailed(photo)} style={{ position: 'absolute', inset: 0 }} contentFit="cover" /> : } {children} ); } /** 불러오는 동안 자리만 잡는 막대. 천천히 깜빡인다 (웹 animate-pulse, 동작 줄이기면 멈춤) */ export function Skel({ className }: { className?: string }) { const reduce = useReducedMotion(); const dim = useSharedValue(0); useEffect(() => { if (reduce) return; dim.value = withRepeat(withTiming(1, { duration: 1000, easing: Easing.bezier(0.4, 0, 0.6, 1) }), -1, true); return () => cancelAnimation(dim); }, [reduce, dim]); const pulse = useAnimatedStyle(() => ({ opacity: 1 - dim.value * 0.5 })); return ( ); } export function Sec({ title, sub, more }: { title: string; sub?: string; more?: Href }) { return ( {title} {sub && {sub}} {more && ( 전체 보기 )} ); } /** 가로로 넘기는 줄 */ export function Rail({ children }: { children: ReactNode }) { return ( {children} ); } /** * 실패·빈 목록 안내. 불러오는 중엔 그리지 않는다(그 자리는 스켈레톤). * hold 에 스켈레톤을 주면 그 크기를 보이지 않게 깔고 안내를 그 위에 띄운다 — 로딩·실패·빈 상태의 자리 크기가 같다. * 이때 boxClassName 은 안내 상자의 위치(스켈레톤 바깥 여백만큼 inset). */ export function StateBox({ load, onRetry, empty, hold, boxClassName = 'inset-x-3 top-3 bottom-0' }: { load: Load; onRetry?: () => void; empty?: string; hold?: ReactNode; boxClassName?: string }) { const failed = load === 'error' || load === 'retrying'; const text = failed ? '정보를 불러오지 못했어요.' : load === 'ready' ? empty : undefined; if (!text) return null; const box = ( {text} {failed && onRetry && ( {load === 'retrying' ? '다시 불러오는 중…' : '다시 시도'} )} ); if (!hold) return box; return ( {hold} {box} ); } /** 사진 출처 표기 (공공누리 조건). 위치는 className 으로 */ export function Credit({ text, className = 'right-1 bottom-1' }: { text: string; className?: string }) { return ( {text} ); } /** 프로필 동그라미: 고른 배경색 위에 캐릭터, 오른쪽 위에 오늘 기분 */ export function Avatar({ character, color, mood, size = 34 }: { character: string; color?: string | null; mood?: string | null; size?: number }) { const emoji = moodEmoji(mood); return ( {emoji && ( {emoji} )} ); } type ChipsProps = { items: readonly (readonly [K, string])[]; value: K; onChange: (k: K) => void; disabled?: boolean }; /** 가로로 넘기는 고르기 칩 */ export function Chips({ items, value, onChange, disabled }: ChipsProps) { return ( {items.map(([k, l]) => ( onChange(k)} className={`rounded-full px-3.5 py-[7px] ${value === k ? 'bg-ink-btn' : 'border-b-[3px] border-shade bg-chip'}`}> {l} ))} ); } /** 장소 이름. 누르면 네이버 지도가 열린다 */ export function MapLink({ place, children }: { place: string; children: ReactNode }) { return ( Linking.openURL(naverMap(place))} accessibilityRole="link" accessibilityLabel={`${place}, 네이버 지도에서 보기`} className="underline"> {children} ); } /** 자외선 단계(1 낮음 ~ 5 위험) 칩 색 */ const LEVEL_CHIP = [ ['#1f9d62', '#fff'], ['#ffc21a', '#3a2a00'], ['#f0700a', '#fff'], ['#e03131', '#fff'], ['#8e3bc4', '#fff'], ] as const; /** 줄 목록 (라벨 · 값) */ export function Rows({ rows, dark = false }: { rows: { label: string; value: string; place?: string | null; level?: number | null }[]; dark?: boolean }) { return ( {rows.map((r, i) => ( {r.label} {r.level ? ( {r.value} ) : ( {r.place ? {r.value} : r.value} )} ))} ); }