@towsila/expo-ui-library 4.18.1 → 4.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@towsila/expo-ui-library",
3
- "version": "4.18.1",
3
+ "version": "4.19.0",
4
4
  "description": "",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
@@ -6,43 +6,45 @@ import { useAppTheme } from "../../context/ThemeContext";
6
6
  import CustomMarker from "./customMarker";
7
7
  import PositionMarker from "./positionMarker";
8
8
  import MovingMarker from "./movingMarker";
9
- import { RouteInfo } from "../../types/route";
10
9
 
11
10
  type LngLat = [number, number];
12
11
 
13
-
12
+ type LineStringGeom = { type: "LineString"; coordinates: [number, number][] };
14
13
 
15
14
  export interface MapMarker {
16
15
  id: string;
17
16
  lngLat: LngLat;
18
- icon: any;
17
+ icon: any;
19
18
  selected?: boolean;
20
19
  onPress?: () => void;
21
- shadow?:boolean;
22
-
23
- }
24
- export interface MapRoute {
25
- id: string;
26
- geometry: { type: "LineString"; coordinates: LngLat[] };
27
- color?: string;
20
+ shadow?: boolean;
28
21
  }
29
22
 
30
- type RouteInput = RouteInfo | RouteInfo[] | null | undefined;
23
+ // Accepts a single LineString or an array of LineStrings
24
+ type RouteInput = LineStringGeom | LineStringGeom[] | null | undefined;
25
+
31
26
  interface Props {
32
27
  mapStyle: any;
33
28
  position: LngLat;
34
- userVariant?: "dot" | "arrow"; // dot = blue dot, arrow = moving marker
29
+ userVariant?: "dot" | "arrow";
35
30
  heading?: number;
36
31
  markers?: MapMarker[];
37
32
  routeGeometry?: RouteInput;
38
- follow?: boolean; // camera follows the user
39
- children?: React.ReactNode; // extra layers if a screen needs them
33
+ follow?: boolean;
34
+ children?: React.ReactNode;
40
35
  onCenterChange?: (center: [number, number]) => void;
41
36
  }
42
37
 
43
38
  export default function AppMap({
44
- mapStyle, position, userVariant = "dot", heading = 0,
45
- markers = [], routeGeometry, follow = false, children, onCenterChange
39
+ mapStyle,
40
+ position,
41
+ userVariant = "dot",
42
+ heading = 0,
43
+ markers = [],
44
+ routeGeometry,
45
+ follow = false,
46
+ children,
47
+ onCenterChange,
46
48
  }: Props) {
47
49
  const { colors } = useAppTheme();
48
50
  const cameraRef = useRef<any>(null);
@@ -52,20 +54,26 @@ export default function AppMap({
52
54
  cameraRef.current?.easeTo({ center: position, duration: 1000 });
53
55
  }, [follow, position[0], position[1]]);
54
56
 
55
- const routes: RouteInfo[] = Array.isArray(routeGeometry)
57
+ // Normalize: LineString OR LineString[] → LineString[]
58
+ const routes: LineStringGeom[] = Array.isArray(routeGeometry)
56
59
  ? routeGeometry
57
60
  : routeGeometry
58
61
  ? [routeGeometry]
59
62
  : [];
63
+
60
64
  return (
61
- <MLMap style={StyleSheet.absoluteFill} mapStyle={mapStyle} onRegionDidChange={(e: any) => onCenterChange?.(e.nativeEvent.center)}>
65
+ <MLMap
66
+ style={StyleSheet.absoluteFill}
67
+ mapStyle={mapStyle}
68
+ onRegionDidChange={(e: any) => onCenterChange?.(e.nativeEvent.center)}
69
+ >
62
70
  <Camera ref={cameraRef} initialViewState={{ center: position, zoom: 15 }} />
63
71
 
64
72
  {routes.map((r, i) => (
65
73
  <GeoJSONSource
66
74
  key={i}
67
75
  id={`route-${i}`}
68
- data={{ type: "Feature", properties: {}, geometry: r.geometry }}
76
+ data={{ type: "Feature", properties: {}, geometry: r }}
69
77
  >
70
78
  <Layer
71
79
  id={`route-line-${i}`}
@@ -0,0 +1,26 @@
1
+ import { useWindowDimensions } from "react-native";
2
+ import { useSafeAreaInsets } from "react-native-safe-area-context";
3
+
4
+ const MAX_CONTENT_WIDTH = 640;
5
+
6
+ export function useScreenLayout(hasBottomNav: boolean = false) {
7
+ const { width, height } = useWindowDimensions();
8
+ const insets = useSafeAreaInsets();
9
+
10
+ const horizontalPadding = width < 360 ? 16 : width >= 768 ? 32 : 20;
11
+ const topPadding = Math.max(insets.top, 12) + 12;
12
+ const bottomPadding = hasBottomNav
13
+ ? 16
14
+ : Math.max(insets.bottom, 12) + 10;
15
+
16
+ return {
17
+ width,
18
+ height,
19
+ insets,
20
+ horizontalPadding,
21
+ topPadding,
22
+ bottomPadding,
23
+ maxContentWidth: MAX_CONTENT_WIDTH,
24
+ isCompact: width < 360 || height < 700,
25
+ };
26
+ }
package/src/index.ts CHANGED
@@ -90,4 +90,5 @@ export {default as AppMap} from "./components/ui/appMap";
90
90
  export {default as CustomMarker} from "./components/ui/customMarker";
91
91
  export {default as PositionMarker} from "./components/ui/positionMarker";
92
92
  export {default as MovingMarker} from "./components/ui/movingMarker";
93
- export {default as MapHeader} from "./components/ui/mapHeader";
93
+ export {default as MapHeader} from "./components/ui/mapHeader";
94
+ export {useScreenLayout} from "./hooks/useScreenLayout";