feat: 앱 단풍 지도 — /foliage 지도(두 손가락 확대·이동, 눌러 가까운 명소)·단계별 명소 목록, 단풍철 오늘 피드 맨 앞 카드(foliage_post 좋아요·댓글)와 아이콘. 명소 데이터·계산을 shared/lib/foliage.ts 로 (GA foliage_open·foliage_spot)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
skkimandClaude committed 2026-11-04 17:52:23 +09:00
1 parent 6daa2f4d2a
commit e5cdfa2642
11 files changed
+966 -180

No files matched your search

@@ -0,0 +1,153 @@
import type { PostReaction } from '@nalssigak/shared/api/client/types.gen';
import { headline, ICON_R, labelBoxes, md, nearest, placeLabels, placeProvinces, PROVINCES, rankNow, spread } from '@nalssigak/shared/lib/foliage';
import { router } from 'expo-router';
import { useEffect, useMemo, useState } from 'react';
import { Pressable, View, type GestureResponderEvent, type LayoutChangeEvent } from 'react-native';
import { Label, Legend, MapImage, MAP_INK, MAP_INK3, Marker, PAPER, Province, useLabelSizes } from '@/components/foliage/parts';
import { Pager } from '@/components/post/pager';
import { PostFrame } from '@/components/post/post-frame';
import { Text } from '@/components/text';
import { Ic } from '@/components/ui';
import { track } from '@/lib/analytics';
import { useFoliage } from '@/lib/foliage';
const RANK_N = 7;
// 지도 아래 고른 명소 줄(범례 자리) 높이
const BAR_H = 60;
// 지도 그림은 땅이 왼쪽에 치우쳐 있어 오른쪽(빈 바다)으로 밀어 가운데에 맞춘다
const SHIFT = 0.07;
const goMap = (spot?: string) => router.push(spot ? { pathname: '/foliage', params: { spot } } : '/foliage');
/**
* 피드의 단풍 지도 카드 (웹 FoliageCard): 1장은 지금 절정인 곳만 잎으로(누르면 카드 안에 정보), 2장은 지금 가기 좋은 순위.
* '지도 크게 보기'로 단풍 지도 화면. 단풍철이 아니면 그리지 않는다
*/
export function FoliageCard({ post }: { post?: PostReaction | null }) {
const { today, spots, inSeason } = useFoliage();
const peak = useMemo(() => spots.filter((m) => m.stage === 'peak').sort((a, b) => Number(a.kind === 'ginkgo') - Number(b.kind === 'ginkgo') || a.y - b.y), [spots]);
const [size, measure] = useLabelSizes();
const [W, setW] = useState(0);
const [picked, setPicked] = useState<string | null>(null);
const [index, setIndex] = useState(0);
const pts = useMemo(() => spread(peak.map((m) => ({ m, x: m.x * W, y: m.y * W, r: ICON_R }))), [peak, W]);
const labelAt = useMemo(() => placeLabels(pts, pts, size, { l: 0, t: 0, r: W, b: W }, [], () => true), [pts, size, W]);
const provs = useMemo(() => placeProvinces(PROVINCES.map((v) => ({ name: v.name, x: v.x * W, y: v.y * W })), pts, labelBoxes(labelAt, size)), [pts, W, labelAt, size]);
useEffect(() => {
if (picked) track('foliage_spot', { spot_name: picked, from: 'card' });
}, [picked]);
if (!inSeason) return null;
const toggle = (name: string) => setPicked(name === picked ? null : name);
// 잎이 작아 손가락으로 겨냥하기 어려우니 누른 자리에서 가까운 명소를 고른다
const tapMap = (e: GestureResponderEvent) => {
const best = nearest(pts, e.nativeEvent.locationX, e.nativeEvent.locationY);
setPicked(best && best !== picked ? best : null);
};
const onLayout = (e: LayoutChangeEvent) => setW(e.nativeEvent.layout.width);
const sel = peak.find((m) => m.name === picked);
// 2번째 장: 지금 절정인 곳을 절정 예상일이 오늘과 가까운 순서로
const ranked = rankNow(spots).slice(0, RANK_N);
const caption = peak.length ? `지금 절정 ${peak.length}곳: ${peak.slice(0, 5).map((m) => m.name).join(' · ')}${peak.length > 5 ? ' 외' : ''}` : undefined;
const pageH = W + 8 + BAR_H;
const mapPage = (
<View className="overflow-hidden" style={{ width: W, height: pageH }}>
<Pressable onPress={tapMap} accessibilityLabel="단풍 지도, 지금 절정인 곳" style={{ width: W, height: W, transform: [{ translateX: W * SHIFT }], backgroundColor: PAPER }}>
<MapImage style={{ left: 0, top: 0, width: W, height: W }} />
{provs.map((v) => (
<Province key={v.name} name={v.name} x={v.x} y={v.y} />
))}
{pts.map((p) => (
<Marker key={p.m.name} p={p} sel={p.m.name === picked} />
))}
{peak.map((m) => (
<Label key={m.name} m={m} at={labelAt[m.name]} onPress={() => toggle(m.name)} onLayout={measure(m.name)} accessibilityLabel={`${m.name} 정보 보기`} />
))}
</Pressable>
{/* 고른 명소 정보는 지도 밖, 범례 자리에: 지도 위 잎을 가리지 않게 */}
{sel ? (
<View className="mt-2 flex-row items-center gap-3 rounded-[16px] bg-white px-3" style={{ height: BAR_H, boxShadow: 'inset 0 -3px 0 rgba(40,48,74,0.08)' }}>
<Ic name={sel.kind} size={32} />
<View className="min-w-0 flex-1">
<Text numberOfLines={1} className="font-jua text-[18px] leading-tight" style={{ color: MAP_INK }}>
{sel.name}
</Text>
<Text numberOfLines={1} className="text-[12px] font-bold" style={{ color: MAP_INK3 }}>
{`${sel.region.split(' ')[0]} · 절정 예상 ${md(sel.peak)}`}
</Text>
</View>
<Pressable onPress={() => goMap(sel.name)} accessibilityRole="link" className="rounded-full px-3 py-1.5" style={{ backgroundColor: MAP_INK }}>
<Text className="text-[12.5px] font-extrabold text-white">지도에서 보기 ›</Text>
</Pressable>
</View>
) : (
<View className="mt-2 items-start" style={{ height: BAR_H }}>
<Legend color={MAP_INK} />
</View>
)}
</View>
);
const rankPage = (
<View className="pl-1" style={{ width: W, height: pageH }}>
<Text className="font-jua text-[20px] leading-tight" style={{ color: MAP_INK }}>
지금 가기 좋은 곳
</Text>
<Text className="mt-0.5 text-[12px] font-bold" style={{ color: MAP_INK3 }}>
절정 예상일이 오늘과 가까운 순서예요
</Text>
<View className="mt-2 flex-1 justify-between">
{ranked.map((m, i) => (
<Pressable key={m.name} onPress={() => goMap(m.name)} accessibilityRole="link" accessibilityLabel={`${i + 1}위 ${m.name}, 절정 예상 ${md(m.peak)}`} className="flex-row items-center gap-2.5 py-1.5">
<Text className="w-6 text-center font-jua text-[22px]" style={{ color: i < 3 ? '#b5321f' : '#9a8f80' }}>
{String(i + 1)}
</Text>
<Ic name={m.kind} size={28} />
<View className="min-w-0 flex-1">
<Text numberOfLines={1} className="text-[15px] font-extrabold" style={{ color: MAP_INK }}>
{m.name}
</Text>
<Text numberOfLines={1} className="text-[12px] font-semibold" style={{ color: MAP_INK3 }}>
{m.region}
</Text>
</View>
<Text className="text-[14px] font-extrabold" style={{ color: MAP_INK, fontVariant: ['tabular-nums'] }}>
{md(m.peak)}
</Text>
</Pressable>
))}
</View>
</View>
);
return (
<PostFrame title="단풍 지도" account="단풍 지도" avatar="maple" pinned={{ key: 'foliage_post', post }} caption={caption}>
{/* 밤에도 지도 카드는 밝은 종이 그대로 (웹 b-keep-bg) */}
<View className="px-4 pt-4 pb-3" style={{ backgroundColor: PAPER }}>
<Text className="text-[13px] font-extrabold opacity-75" style={{ color: MAP_INK }}>{`단풍 지도 · ${md(today)}`}</Text>
<Text className="mt-1 font-jua text-[24px] leading-tight" style={{ color: MAP_INK }}>
{headline(spots)}
</Text>
<View className="mt-1" onLayout={onLayout}>
{W > 0 ? (
<Pager width={W} height={pageH} onIndex={setIndex}>
{[mapPage, rankPage]}
</Pager>
) : null}
<View pointerEvents="none" className="absolute top-0 right-0 rounded-full px-[9px] py-[3px]" style={{ zIndex: 4, backgroundColor: 'rgba(30,36,56,0.55)' }} accessibilityElementsHidden>
<Text className="text-xs font-extrabold text-white">{`${index + 1}/2`}</Text>
</View>
</View>
<Pressable onPress={() => goMap()} accessibilityRole="link" className="mt-2 w-full items-center rounded-full bg-white py-2" style={{ boxShadow: 'inset 0 -3px 0 rgba(40,48,74,0.08)' }}>
<Text className="text-[14px] font-extrabold" style={{ color: MAP_INK }}>
지도 크게 보기 ›
</Text>
</Pressable>
</View>
</PostFrame>
);
}
@@ -0,0 +1,272 @@
import { ICON_R, LAND_CX, labelBoxes, nearest, placeLabels, placeProvinces, PROVINCES, spread, type Box, type Spot, type Stage } from '@nalssigak/shared/lib/foliage';
import { useCallback, useEffect, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState, type Ref } from 'react';
import { Pressable, View, type GestureResponderEvent, type LayoutChangeEvent } from 'react-native';
import { Label, MapImage, Marker, MAP_INK, PAPER, Province, useLabelSizes } from '@/components/foliage/parts';
import { Text } from '@/components/text';
type Cam = { s: number; tx: number; ty: number };
const DOT_R: Record<Stage, number> = { peak: ICON_R, first: 4, before: 3, gone: 3 };
const MAX_ZOOM = 5;
const FIT_TOP = 30;
const FIT_BOTTOM = 14;
// 이름 우선순위(절정 단풍 > 절정 은행 > 첫 단풍 > 나머지)와 그 이름이 나오기 시작하는 배율(처음 화면 대비)
const pri = (m: Spot) => (m.stage === 'peak' ? (m.kind === 'maple' ? 0 : 1) : m.stage === 'first' ? 2 : 3);
const LABEL_FROM = [1, 1.6, 2.5, 3.5];
// 점이 나오기 시작하는 배율: 처음엔 절정 잎만 보여 차분하게
const DOT_FROM: Record<Stage, number> = { peak: 1, first: 1.6, before: 2.5, gone: 2.5 };
const ZOOM_BTNS = [
['+', '확대', 1.6],
['−', '축소', 1 / 1.6],
] as const;
export type FoliageMapHandle = { focus: (m: Spot) => void };
type Props = { spots: Spot[]; sel: string | null; onSelect: (name: string | null) => void; height: number; ref?: Ref<FoliageMapHandle> };
/**
* 단풍 지도 페이지의 지도: 두 손가락으로 확대·이동, 한 손가락으로 이동, 누르면 가까운 명소 고르기, 두 번 누르면 확대 (웹 FoliagePage 지도).
* 앱은 지도를 스크롤 밖에 고정해 손짓이 페이지 스크롤과 다투지 않는다
*/
export function FoliageMap({ spots, sel, onSelect, height, ref }: Props) {
const vpRef = useRef<View>(null);
const origin = useRef({ x: 0, y: 0 });
const [box, setBox] = useState({ W: 0, H: 0 });
const [view, setView] = useState<Cam>({ s: 1, tx: 0, ty: 0 });
const viewRef = useRef(view);
useLayoutEffect(() => {
viewRef.current = view;
}, [view]);
const [size, measure] = useLabelSizes();
// 처음 화면: 명소가 다 들어오는 만큼 확대해 가운데
const fit = useMemo<Cam>(() => {
const { W, H } = box;
if (!W || !spots.length) return { s: 1, tx: 0, ty: 0 };
const xs = spots.map((m) => m.x);
const ys = spots.map((m) => m.y);
const [x0, x1, y0, y1] = [Math.min(...xs), Math.max(...xs), Math.min(...ys), Math.max(...ys)];
// 위쪽은 맨 북쪽 이름표가 잘리지 않게 FIT_TOP 만큼 띄우고, 아래는 제주까지만
const h = H - FIT_TOP - FIT_BOTTOM;
// 가로는 땅 가운데(LAND_CX)에 맞추되 동·서 끝 명소가 다 들어오게
const half = Math.max(LAND_CX - x0, x1 - LAND_CX) + 0.07;
const s = Math.min(W / (2 * half * W), h / ((y1 - y0) * W));
return { s, tx: W / 2 - LAND_CX * W * s, ty: FIT_TOP + h / 2 - ((y0 + y1) / 2) * W * s };
}, [box, spots]);
const clamp = useCallback(
(v: Cam): Cam => {
const { W, H } = box;
const s = Math.min(fit.s * MAX_ZOOM, Math.max(fit.s, v.s));
const w = W * s;
// 지도 그림 가장자리가 화면 안쪽으로 너무 들어오지 않게
const tx = Math.min(W * 0.25, Math.max(W * 0.75 - w, v.tx));
const ty = Math.min(H * 0.25, Math.max(H * 0.75 - w, v.ty));
return { s, tx, ty };
},
[box, fit],
);
const anim = useRef(0);
const set = useCallback((v: Cam) => {
cancelAnimationFrame(anim.current);
setView(v);
}, []);
const animateTo = useCallback(
(to: Cam) => {
cancelAnimationFrame(anim.current);
const from = viewRef.current;
const target = clamp(to);
const start = performance.now();
const step = (now: number) => {
const k = Math.min(1, (now - start) / 280);
const e = 1 - (1 - k) ** 3;
setView({ s: from.s + (target.s - from.s) * e, tx: from.tx + (target.tx - from.tx) * e, ty: from.ty + (target.ty - from.ty) * e });
if (k < 1) anim.current = requestAnimationFrame(step);
};
anim.current = requestAnimationFrame(step);
},
[clamp],
);
const zoomAt = useCallback(
(f: number, cx: number, cy: number, smooth = false) => {
const v = viewRef.current;
const s = Math.min(fit.s * MAX_ZOOM, Math.max(fit.s, v.s * f));
const k = s / v.s;
const next = clamp({ s, tx: cx - (cx - v.tx) * k, ty: cy - (cy - v.ty) * k });
if (smooth) animateTo(next);
else set(next);
},
[fit, clamp, animateTo, set],
);
const focus = useCallback(
(m: Spot) => {
const { W, H } = box;
const s = Math.max(viewRef.current.s, fit.s * 2.5);
animateTo({ s, tx: W / 2 - m.x * W * s, ty: H * 0.42 - m.y * W * s });
},
[box, fit, animateTo],
);
useImperativeHandle(ref, () => ({ focus }), [focus]);
// 크기가 정해지면 처음 화면으로, 링크로 고른 명소가 있으면 그곳으로. 그 뒤 크기가 바뀌면 지금 화면을 범위 안으로
const started = useRef(false);
const linked = useRef(sel);
useEffect(() => {
if (!box.W) return;
if (started.current) {
set(clamp(viewRef.current));
return;
}
started.current = true;
set(fit);
const m = spots.find((s) => s.name === linked.current);
if (m) focus(m);
}, [box, fit, spots, set, clamp, focus]);
useEffect(() => () => cancelAnimationFrame(anim.current), []);
const pts = useMemo(() => {
const ratio = view.s / fit.s;
const visible = spots.filter((m) => m.name === sel || ratio >= DOT_FROM[m.stage] - 0.01);
return spread(visible.map((m) => ({ m, x: view.tx + m.x * box.W * view.s, y: view.ty + m.y * box.W * view.s, r: DOT_R[m.stage] })));
}, [spots, view, box.W, fit.s, sel]);
const ptsRef = useRef(pts);
useLayoutEffect(() => {
ptsRef.current = pts;
}, [pts]);
const labelAt = useMemo(() => {
const ratio = view.s / fit.s;
const order = pts.filter((p) => p.m.name === sel || ratio >= LABEL_FROM[pri(p.m)]).sort((a, b) => Number(b.m.name === sel) - Number(a.m.name === sel) || pri(a.m) - pri(b.m));
// 오른쪽 위 +/− 단추 자리는 비운다
const blocked: Box[] = [{ l: box.W - 52, t: 0, r: box.W, b: 100 }];
return placeLabels(order, pts, size, { l: 4, t: 4, r: box.W - 4, b: box.H - 4 }, blocked, (p) => p.m.stage === 'peak' || p.m.name === sel);
}, [pts, size, sel, view.s, fit.s, box]);
const provs = useMemo(
() => placeProvinces(PROVINCES.map((v) => ({ name: v.name, x: view.tx + v.x * box.W * view.s, y: view.ty + v.y * box.W * view.s })), pts, labelBoxes(labelAt, size)),
[view, box.W, pts, labelAt, size],
);
// 손짓 상태: 두 손가락 거리·가운데, 한 손가락 시작점과 움직였는지, 마지막으로 누른 때(두 번 누르기)
const gesture = useRef<{ pinch: { d: number; x: number; y: number } | null; one: { x: number; y: number; moved: boolean } | null; lastTap: number }>({ pinch: null, one: null, lastTap: 0 });
const local = (t: { pageX: number; pageY: number }) => ({ x: t.pageX - origin.current.x, y: t.pageY - origin.current.y });
const pickAt = (x: number, y: number) => {
const best = nearest(ptsRef.current, x, y);
onSelect(best && best !== sel ? best : null);
};
const begin = (e: GestureResponderEvent) => {
const g = gesture.current;
const ts = e.nativeEvent.touches;
if (ts.length >= 2) {
const [a, b] = [local(ts[0]), local(ts[1])];
g.pinch = { d: Math.hypot(a.x - b.x, a.y - b.y), x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 };
g.one = null;
} else if (ts.length === 1) {
g.pinch = null;
g.one = { ...local(ts[0]), moved: false };
}
};
const onGrant = (e: GestureResponderEvent) => {
cancelAnimationFrame(anim.current);
// 지도 칸의 화면 위치: 손가락 좌표(pageX)를 지도 안 좌표로 바꾸는 데 쓴다
vpRef.current?.measure((_x, _y, _w, _h, px, py) => {
origin.current = { x: px, y: py };
});
begin(e);
};
const onMove = (e: GestureResponderEvent) => {
const g = gesture.current;
const ts = e.nativeEvent.touches;
if (ts.length >= 2) {
if (!g.pinch) return begin(e);
const [a, b] = [local(ts[0]), local(ts[1])];
const d = Math.hypot(a.x - b.x, a.y - b.y);
const x = (a.x + b.x) / 2;
const y = (a.y + b.y) / 2;
const v = viewRef.current;
const s = Math.min(fit.s * MAX_ZOOM, Math.max(fit.s, (v.s * d) / g.pinch.d));
const k = s / v.s;
set(clamp({ s, tx: x - (g.pinch.x - v.tx) * k, ty: y - (g.pinch.y - v.ty) * k }));
g.pinch = { d, x, y };
return;
}
// 두 손가락에서 한 손가락이 떨어지면 남은 손가락으로 이어서 이동 (누르기로는 안 친다)
if (!g.one || g.pinch) {
if (ts.length === 1) g.one = { ...local(ts[0]), moved: true };
g.pinch = null;
return;
}
const p = local(ts[0]);
if (Math.hypot(p.x - g.one.x, p.y - g.one.y) > 6) g.one.moved = true;
if (!g.one.moved) return;
const v = viewRef.current;
set(clamp({ s: v.s, tx: v.tx + p.x - g.one.x, ty: v.ty + p.y - g.one.y }));
g.one = { ...p, moved: true };
};
const onRelease = (e: GestureResponderEvent) => {
const g = gesture.current;
const tap = g.one && !g.one.moved ? g.one : null;
g.one = null;
g.pinch = null;
if (!tap) return;
// 두 번 누르기: 300ms 안에 또 누르면 확대
if (e.nativeEvent.timestamp - g.lastTap < 300) {
g.lastTap = 0;
zoomAt(2, tap.x, tap.y, true);
} else {
g.lastTap = e.nativeEvent.timestamp;
pickAt(tap.x, tap.y);
}
};
const onEnd = () => {
gesture.current.one = null;
gesture.current.pinch = null;
};
const onLayout = (e: LayoutChangeEvent) => {
const { width, height: h } = e.nativeEvent.layout;
setBox({ W: width, H: h });
vpRef.current?.measure((_x, _y, _w, _h, px, py) => {
origin.current = { x: px, y: py };
});
};
const markers = [...pts].sort((a, b) => Number(a.m.stage === 'peak') - Number(b.m.stage === 'peak'));
return (
<View
ref={vpRef}
onLayout={onLayout}
onStartShouldSetResponder={() => true}
onMoveShouldSetResponder={() => true}
onResponderTerminationRequest={() => false}
onResponderGrant={onGrant}
onResponderMove={onMove}
onResponderRelease={onRelease}
onResponderTerminate={onEnd}
className="overflow-hidden"
style={{ height, backgroundColor: PAPER }}
accessibilityLabel="단풍 지도"
>
{box.W > 0 ? <MapImage style={{ left: view.tx, top: view.ty, width: box.W * view.s, height: box.W * view.s }} /> : null}
{provs.map((v) => (
<Province key={v.name} name={v.name} x={v.x} y={v.y} />
))}
{markers.map((p) => (
<Marker key={p.m.name} p={p} sel={p.m.name === sel} />
))}
{spots.map((m) => (
<Label key={m.name} m={m} at={labelAt[m.name]} sel={m.name === sel} onPress={() => onSelect(m.name === sel ? null : m.name)} onLayout={measure(m.name)} accessibilityLabel={`${m.name} 고르기`} />
))}
<View className="absolute top-2.5 right-2.5 gap-2" style={{ zIndex: 4 }}>
{ZOOM_BTNS.map(([t, label, f]) => (
<Pressable key={t} onPress={() => zoomAt(f, box.W / 2, box.H / 2, true)} accessibilityRole="button" accessibilityLabel={label} className="size-9 items-center justify-center rounded-full bg-white" style={{ boxShadow: '0 2px 6px rgba(40,48,74,0.2)' }}>
<Text className="text-[20px] leading-6 font-bold" style={{ color: MAP_INK }}>
{t}
</Text>
</Pressable>
))}
</View>
</View>
);
}
+135
View File
@@ -0,0 +1,135 @@
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<Kind, string> = { maple: '#b5321f', ginkgo: '#8a6508' };
/**
* 지도 그림. 웹은 채도를 빼서(saturate .3) 잎 아이콘이 묻히지 않게 한다.
* 안드로이드는 같은 filter, iOS 는 filter 의 채도를 못 써서 종이색을 반쯤 덮어 옅게 한다
*/
export function MapImage({ style }: { style: StyleProp<ViewStyle> }) {
const android = Platform.OS === 'android';
return (
<View pointerEvents="none" style={[{ position: 'absolute' }, style, android ? { filter: [{ saturate: 0.3 }, { brightness: 1.08 }] } : null]}>
<Image source={MAP_IMAGE} style={{ width: '100%', height: '100%' }} contentFit="contain" accessibilityIgnoresInvertColors />
{!android && <View style={{ position: 'absolute', inset: 0, backgroundColor: PAPER, opacity: 0.5 }} />}
</View>
);
}
const DOT: Record<Exclude<Stage, 'peak'>, { 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 <Ic name={m.kind} size={big ? 32 : 20} />;
const dot = DOT[m.stage];
const size = big ? 14 : dot.size;
return <View style={{ width: size, height: size, borderRadius: size / 2, backgroundColor: dot.color }} />;
}
/** 지도 위 점·잎. 고른 명소는 속이 빈 고리만 둘러 옆 명소를 가리지 않게 */
export function Marker({ p, sel }: { p: Pt; sel: boolean }) {
return (
<View pointerEvents="none" className="absolute size-8 items-center justify-center" style={{ left: p.x - 16, top: p.y - 16, zIndex: sel ? 3 : 1 }}>
{sel ? <View className="absolute size-8 rounded-full border-[2.5px]" style={{ borderColor: MAP_INK, backgroundColor: 'rgba(255,255,255,0.3)' }} /> : null}
<StageMark m={p.m} big={sel && p.m.stage !== 'peak'} />
</View>
);
}
/** 시·도 이름: 지도에 옅게 깔리는 글자. 산 무늬 위에서도 읽히게 종이색 번짐을 두른다 */
export function Province({ name, x, y }: { name: string; x: number; y: number }) {
return (
<View pointerEvents="none" className="absolute w-10 items-center" style={{ left: x - 20, top: y - 8 }} accessibilityElementsHidden importantForAccessibility="no-hide-descendants">
<Text className="font-jua text-[13px] leading-4" style={{ color: 'rgba(92,74,54,0.85)', textShadowColor: PAPER, textShadowRadius: 4 }}>
{name}
</Text>
</View>
);
}
/**
* 명소 이름표. 자리를 못 받았으면(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 (
<Pressable
onPress={onPress}
onLayout={onLayout}
disabled={!at}
hitSlop={{ top: 8, bottom: 8, left: 4, right: 4 }}
accessibilityRole="button"
accessibilityLabel={accessibilityLabel}
accessibilityElementsHidden={!at}
importantForAccessibility={at ? 'auto' : 'no-hide-descendants'}
className="absolute rounded-[7px] px-[5px] py-px"
style={{
left: at?.left ?? 0,
top: at?.top ?? 0,
opacity: at ? 1 : 0,
zIndex: sel ? 3 : 2,
backgroundColor: sel ? MAP_INK : 'rgba(255,255,255,0.92)',
boxShadow: '0 1px 3px rgba(40,48,74,0.18)',
}}
>
<Text numberOfLines={1} className="text-[11.5px] leading-[15.5px] font-extrabold" style={{ color }}>
{m.name}
</Text>
</Pressable>
);
}
/** 이름표 크기 모으기: Label 의 onLayout 을 받아 이름별 폭·높이. 한 프레임에 한 번만 다시 그린다 */
export function useLabelSizes() {
const [size, setSize] = useState<LabelSize>({});
const acc = useRef<LabelSize>({});
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) => (
<View key={label} className="flex-row items-center gap-1">
{mark}
<Text className="text-[12.5px] font-bold" style={{ color }}>
{label}
</Text>
</View>
);
return (
<View className="h-[52px] flex-row flex-wrap items-center justify-center gap-x-3 gap-y-1">
{item(<Ic name="maple" size={16} />, '단풍 절정')}
{item(<Ic name="ginkgo" size={16} />, '은행 절정')}
{full ? item(<View style={{ width: 7, height: 7, borderRadius: 4, backgroundColor: DOT.first.color }} />, '첫 단풍') : null}
{full ? item(<View style={{ width: 5, height: 5, borderRadius: 3, backgroundColor: DOT.before.color }} />, '단풍 전') : null}
</View>
);
}
@@ -0,0 +1,93 @@
import { md, STAGE, type Spot, type Stage } from '@nalssigak/shared/lib/foliage';
import { Pressable, View } from 'react-native';
import { Legend, StageMark } from '@/components/foliage/parts';
import { Text } from '@/components/text';
const GROUPS: [Stage, string][] = [
['peak', '지금 절정'],
['first', '곧 절정'],
['before', '아직'],
['gone', '절정 지남'],
];
const CHIP: Partial<Record<Stage, { bg: string; ink: string }>> = {
peak: { bg: '#ffe3db', ink: '#b5321f' },
first: { bg: '#ffe8d2', ink: '#a34f12' },
};
/** 지도 아래 한 줄: 고른 명소가 있으면 그 명소 정보, 없으면 범례 (지도 위를 가리지 않게 범례 자리에) */
export function ChosenBar({ chosen, legendColor }: { chosen?: Spot; legendColor: string }) {
if (!chosen)
return (
<View className="mx-3 mt-2 h-[60px] justify-center">
<Legend full color={legendColor} />
</View>
);
const chip = CHIP[chosen.stage];
return (
<View className="mx-3 mt-2 h-[60px] flex-row items-center gap-3 rounded-[18px] border-b-4 border-shade bg-card px-3.5">
<View className="size-8 items-center justify-center">
<StageMark m={chosen} big />
</View>
<View className="min-w-0 flex-1">
<View className="flex-row items-center gap-1.5">
<Text numberOfLines={1} className="shrink font-jua text-[18px] text-ink">
{chosen.name}
</Text>
<Text className={`overflow-hidden rounded-full px-1.5 py-px text-[11px] font-extrabold ${chip ? '' : 'bg-chip text-ink2'}`} style={chip ? { backgroundColor: chip.bg, color: chip.ink } : undefined}>
{STAGE[chosen.stage]}
</Text>
</View>
<Text numberOfLines={1} className="text-[12px] font-bold text-ink3">
{`${chosen.region} · 절정 예상 ${md(chosen.peak)}`}
</Text>
</View>
</View>
);
}
/** 단계별 명소 목록 (지금 절정 · 곧 절정 · 아직 · 절정 지남). 누르면 지도에서 그 명소로 */
export function SpotList({ spots, sel, onPick }: { spots: Spot[]; sel: string | null; onPick: (m: Spot) => void }) {
return (
<View className="px-4">
{GROUPS.map(([g, title]) => {
const rows = spots.filter((m) => m.stage === g).sort((a, b) => a.peak.localeCompare(b.peak));
if (!rows.length) return null;
return (
<View key={g} accessibilityLabel={title} className="pt-5">
<View className="flex-row items-baseline gap-1.5 px-1 pb-1.5">
<Text className="font-jua text-[19px] text-ink">{title}</Text>
<Text className="text-[13px] font-extrabold text-ink3">{`${rows.length}곳`}</Text>
</View>
<View className="border-t border-line">
{rows.map((m) => (
<Pressable
key={m.name}
onPress={() => onPick(m)}
accessibilityRole="button"
accessibilityState={{ selected: m.name === sel }}
className="flex-row items-center gap-3 border-b border-line py-2.5 pl-1"
style={m.name === sel ? { backgroundColor: 'rgba(255,122,69,0.08)' } : undefined}
>
<View className="size-7 items-center justify-center">
<StageMark m={m} big />
</View>
<View className="min-w-0 flex-1">
<Text numberOfLines={1} className="text-[15px] font-extrabold text-ink">
{m.name}
</Text>
<Text numberOfLines={1} className="text-[12px] font-semibold text-ink3">
{`${m.region} · ${m.own ? '절정 예상' : '가까운 지점 날짜'}`}
</Text>
</View>
<Text className={`pr-1 font-jua text-[18px] ${g === 'peak' ? 'text-orange' : 'text-ink2'}`}>{md(m.peak)}</Text>
</Pressable>
))}
</View>
</View>
);
})}
</View>
);
}