import type { Kind, LabelSize, Pt, Spot, Stage } from '@nalssigak/shared/lib/foliage'; import { Image } from 'expo-image'; import { useCallback, useRef, useState, type ReactNode } from 'react'; import { Platform, Pressable, View, type LayoutChangeEvent, type StyleProp, type ViewStyle } from 'react-native'; import { Text } from '@/components/text'; import { Ic } from '@/components/ui'; import { MAP_IMAGE } from '@/lib/foliage'; // 지도는 밤에도 밝은 종이 그대로 (웹 b-keep-bg) export const PAPER = '#fff6ea'; export const MAP_INK = '#28304a'; export const MAP_INK3 = '#6b7189'; const LABEL_INK: Record = { maple: '#b5321f', ginkgo: '#8a6508' }; /** * 지도 그림. 웹은 채도를 빼서(saturate .3) 잎 아이콘이 묻히지 않게 한다. * 안드로이드는 같은 filter, iOS 는 filter 의 채도를 못 써서 종이색을 반쯤 덮어 옅게 한다 */ export function MapImage({ style }: { style: StyleProp }) { const android = Platform.OS === 'android'; return ( {!android && } ); } const DOT: Record, { size: number; color: string }> = { first: { size: 7, color: 'rgba(217,119,46,0.85)' }, before: { size: 5, color: 'rgba(143,138,128,0.6)' }, gone: { size: 5, color: 'rgba(143,138,128,0.6)' }, }; /** 단계 표시: 절정은 잎, 첫 단풍은 주황 점, 단풍 전·지남은 회색 점(big 이면 점을 크게) */ export function StageMark({ m, big }: { m: Spot; big?: boolean }) { if (m.stage === 'peak') return ; const dot = DOT[m.stage]; const size = big ? 14 : dot.size; return ; } /** 지도 위 점·잎. 고른 명소는 속이 빈 고리만 둘러 옆 명소를 가리지 않게 */ export function Marker({ p, sel }: { p: Pt; sel: boolean }) { return ( {sel ? : null} ); } /** 시·도 이름: 지도에 옅게 깔리는 글자. 산 무늬 위에서도 읽히게 종이색 번짐을 두른다 */ export function Province({ name, x, y }: { name: string; x: number; y: number }) { return ( {name} ); } /** * 명소 이름표. 자리를 못 받았으면(at 없음) 숨긴 채 왼쪽 위에 두고 크기만 잰다 (웹 useLabelSize 대신 onLayout). * tone: 고름(진한 바탕) · 절정(잎 색 글자) · 그 밖(회색 글자) */ export function Label({ m, at, sel, onPress, onLayout, accessibilityLabel }: { m: Spot; at?: { left: number; top: number }; sel?: boolean; onPress: () => void; onLayout: (e: LayoutChangeEvent) => void; accessibilityLabel: string }) { const color = sel ? '#ffffff' : m.stage === 'peak' ? LABEL_INK[m.kind] : '#5b6075'; return ( {m.name} ); } /** 이름표 크기 모으기: Label 의 onLayout 을 받아 이름별 폭·높이. 한 프레임에 한 번만 다시 그린다 */ export function useLabelSizes() { const [size, setSize] = useState({}); const acc = useRef({}); const frame = useRef(0); const measure = useCallback( (name: string) => (e: LayoutChangeEvent) => { const { width: w, height: h } = e.nativeEvent.layout; const old = acc.current[name]; if (old && Math.abs(old.w - w) < 0.5 && Math.abs(old.h - h) < 0.5) return; acc.current = { ...acc.current, [name]: { w, h } }; cancelAnimationFrame(frame.current); frame.current = requestAnimationFrame(() => setSize(acc.current)); }, [], ); return [size, measure] as const; } /** 범례: 절정 잎 둘, full 이면 첫 단풍·단풍 전 점까지 */ export function Legend({ full, color }: { full?: boolean; color: string }) { const item = (mark: ReactNode, label: string) => ( {mark} {label} ); return ( {item(, '단풍 절정')} {item(, '은행 절정')} {full ? item(, '첫 단풍') : null} {full ? item(, '단풍 전') : null} ); }