diff --git a/apps/mobile/lib/editor/RouteMap.tsx b/apps/mobile/lib/editor/RouteMap.tsx index 57171e1..c41eeb0 100644 --- a/apps/mobile/lib/editor/RouteMap.tsx +++ b/apps/mobile/lib/editor/RouteMap.tsx @@ -1,9 +1,18 @@ import { useRef, useCallback } from "react"; import { StyleSheet, View, Text } from "react-native"; -import MapLibreGL from "@maplibre/maplibre-react-native"; import type { Waypoint } from "@trails-cool/types"; import type { RouteSegment } from "./use-route-editor"; +import type MapLibreRN from "@maplibre/maplibre-react-native"; + +let MapLibreGL: typeof MapLibreRN | null = null; +try { + // eslint-disable-next-line @typescript-eslint/no-require-imports + MapLibreGL = require("@maplibre/maplibre-react-native").default; +} catch { + // Native module not available — will show fallback UI +} + const OSM_STYLE = { version: 8 as const, sources: { @@ -40,7 +49,32 @@ export function RouteMap({ onWaypointDragEnd: _onWaypointDragEnd, onWaypointPress, }: RouteMapProps) { - const cameraRef = useRef(null); + if (!MapLibreGL) { + return ( + + Map + Requires a dev build with MapLibre + + ); + } + + return ; +} + +function RouteMapInner({ + waypoints, + segments, + computing, + onLongPress, + onWaypointDragEnd: _onWaypointDragEnd, + onWaypointPress, +}: RouteMapProps) { + const ML = MapLibreGL!; + const cameraRef = useRef(null); const handleLongPress = useCallback( // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -71,7 +105,7 @@ export function RouteMap({ return ( - {bounds && ( - - + - + {/* Waypoint markers */} {waypoints.map((wp, i) => ( - @@ -126,9 +160,9 @@ export function RouteMap({ isDayBreak={wp.isDayBreak} onPress={() => onWaypointPress(i)} /> - + ))} - + {computing && ( @@ -186,6 +220,14 @@ function computeBounds( } const styles = StyleSheet.create({ + fallback: { + flex: 1, + backgroundColor: "#f3f4f6", + justifyContent: "center", + alignItems: "center", + }, + fallbackText: { fontSize: 16, color: "#9ca3af", fontWeight: "600" }, + fallbackHint: { fontSize: 12, color: "#9ca3af", marginTop: 4 }, container: { flex: 1 }, map: { flex: 1 }, computingBanner: {