Colota - Android GPS Location tracker
refactor: type stack navigation and fix bottom inset on sub-screens
Max Dietrich384939b40f5a
diff --git a/apps/mobile/src/components/ui/Container.tsx b/apps/mobile/src/components/ui/Container.tsxindex 0385e8df..c6dbc8a9 100644--- a/apps/mobile/src/components/ui/Container.tsx+++ b/apps/mobile/src/components/ui/Container.tsx@@ -5,19 +5,28 @@import React from "react"import { View, StyleSheet, ViewStyle, StyleProp } from "react-native"+import { useSafeAreaInsets } from "react-native-safe-area-context"+import { useRoute } from "@react-navigation/native"import { useTheme } from "../../hooks/useTheme"+import { TAB_ROUTES } from "./BottomTabBar"type ContainerProps = {children: React.ReactNodestyle?: StyleProp<ViewStyle>}+// Requires NavigationContainer: uses useRoute to skip the bottom inset on tab+// routes, where BottomTabBar already consumes the safe area.export function Container({ children, style }: ContainerProps) {const { colors } = useTheme()+ const insets = useSafeAreaInsets()+ const route = useRoute()++ const paddingBottom = TAB_ROUTES.has(route.name) ? 0 : insets.bottomreturn (<View style={[styles.root, { backgroundColor: colors.background }]}>- <View style={[styles.container, style]}>{children}</View>+ <View style={[styles.container, { paddingBottom }, style]}>{children}</View></View>)}diff --git a/apps/mobile/src/screens/GeofenceEditorScreen.tsx b/apps/mobile/src/screens/GeofenceEditorScreen.tsxindex a906c6cb..52ddb289 100644--- a/apps/mobile/src/screens/GeofenceEditorScreen.tsx+++ b/apps/mobile/src/screens/GeofenceEditorScreen.tsx@@ -23,8 +23,9 @@ import { Check, Trash2 } from "lucide-react-native"import { logger } from "../utils/logger"import { shortDistanceUnit, inputToMeters, metersToInput } from "../utils/geo"import { parsePositiveInt, isPositiveInt } from "../utils/settingsValidation"+import type { RootScreenProps } from "../types/navigation"-export function GeofenceEditorScreen({ navigation, route }: any) {+export function GeofenceEditorScreen({ navigation, route }: RootScreenProps<"Geofence Editor">) {const { colors } = useTheme()const geofenceId = route?.params?.geofenceId as number | undefinedconst isEditing = !!geofenceIddiff --git a/apps/mobile/src/screens/LocationInspectorScreen.tsx b/apps/mobile/src/screens/LocationInspectorScreen.tsxindex 0c31a6f3..cc7a5f71 100644--- a/apps/mobile/src/screens/LocationInspectorScreen.tsx+++ b/apps/mobile/src/screens/LocationInspectorScreen.tsx@@ -20,6 +20,7 @@ import { formatDistance } from "../utils/geo"import { segmentTrips } from "../utils/trips"import { TRIP_CONVERTERS, EXPORT_FORMATS, type ExportFormat } from "../utils/exportConverters"import { showAlert } from "../services/modalService"+import type { RootScreenProps } from "../types/navigation"interface TabProps {label: string@@ -30,7 +31,7 @@ interface TabProps {type TabType = "map" | "trips" | "data"-export function LocationHistoryScreen({ navigation, route }: { navigation: any; route: any }) {+export function LocationHistoryScreen({ navigation, route }: RootScreenProps<"Location History">) {const { colors } = useTheme()const [activeTab, setActiveTab] = useState<TabType>(route?.params?.initialTab ?? "map")diff --git a/apps/mobile/src/screens/ProfileEditorScreen.tsx b/apps/mobile/src/screens/ProfileEditorScreen.tsxindex 760e30d0..90ede302 100644--- a/apps/mobile/src/screens/ProfileEditorScreen.tsx+++ b/apps/mobile/src/screens/ProfileEditorScreen.tsx@@ -16,6 +16,7 @@ import { Check } from "lucide-react-native"import { logger } from "../utils/logger"import { shortDistanceUnit, inputToMeters, metersToInput } from "../utils/geo"import { MS_TO_KMH, PROFILE_CONDITIONS, SYNC_INTERVAL_PRESETS, SYNC_INTERVAL_LABELS } from "../constants"+import type { RootScreenProps } from "../types/navigation"function formatSyncDefault(seconds: number): string {if (SYNC_INTERVAL_LABELS[seconds]) return SYNC_INTERVAL_LABELS[seconds]@@ -23,7 +24,7 @@ function formatSyncDefault(seconds: number): string {return `${Math.round(seconds / 60)} min`}-export function ProfileEditorScreen({ navigation, route }: any) {+export function ProfileEditorScreen({ navigation, route }: RootScreenProps<"Profile Editor">) {const { colors } = useTheme()const { settings } = useTracking()const profileId = route?.params?.profileId as number | undefineddiff --git a/apps/mobile/src/screens/TripDetailScreen.tsx b/apps/mobile/src/screens/TripDetailScreen.tsxindex 032a84f9..e195c2f7 100644--- a/apps/mobile/src/screens/TripDetailScreen.tsx+++ b/apps/mobile/src/screens/TripDetailScreen.tsx@@ -19,6 +19,7 @@ import { showAlert } from "../services/modalService"import { logger } from "../utils/logger"import NativeLocationService from "../services/NativeLocationService"import type { Trip, ThemeColors } from "../types/global"+import type { RootScreenProps } from "../types/navigation"const MAX_BARS = 120@@ -37,7 +38,7 @@ function downsample(values: number[], maxBars: number): number[] {return result}-export function TripDetailScreen({ route }: { navigation: any; route: any }) {+export function TripDetailScreen({ route }: RootScreenProps<"Trip Detail">) {const { colors } = useTheme()const trip: Trip = route.params.tripconst tripColor = getTripColor(trip.index)diff --git a/apps/mobile/src/screens/__tests__/AutoExportScreen.test.tsx b/apps/mobile/src/screens/__tests__/AutoExportScreen.test.tsxindex 1fa94761..d0fdb77c 100644--- a/apps/mobile/src/screens/__tests__/AutoExportScreen.test.tsx+++ b/apps/mobile/src/screens/__tests__/AutoExportScreen.test.tsx@@ -180,7 +180,7 @@ jest.mock("lucide-react-native", () => {import { AutoExportScreen } from "../AutoExportScreen"describe("AutoExportScreen", () => {- const mockProps = { navigation: { navigate: jest.fn() } }+ const mockProps = { navigation: { navigate: jest.fn() } } as anybeforeEach(() => {jest.clearAllMocks()diff --git a/apps/mobile/src/screens/__tests__/GeofenceEditorScreen.test.tsx b/apps/mobile/src/screens/__tests__/GeofenceEditorScreen.test.tsxindex 3f13a7eb..05575f3f 100644--- a/apps/mobile/src/screens/__tests__/GeofenceEditorScreen.test.tsx+++ b/apps/mobile/src/screens/__tests__/GeofenceEditorScreen.test.tsx@@ -133,14 +133,14 @@ describe("GeofenceEditorScreen", () => {})function renderEdit(geofenceId = 1) {- return render(<GeofenceEditorScreen navigation={mockNavigation as any} route={{ params: { geofenceId } }} />)+ return render(<GeofenceEditorScreen navigation={mockNavigation as any} route={{ params: { geofenceId } } as any} />)}function renderNew() {return render(<GeofenceEditorScreennavigation={mockNavigation as any}- route={{ params: { lat: 48.1, lon: 11.5, name: "New Zone", radius: 50 } }}+ route={{ params: { lat: 48.1, lon: 11.5, name: "New Zone", radius: 50 } } as any}/>)}diff --git a/apps/mobile/src/screens/__tests__/LocationHistoryScreen.test.tsx b/apps/mobile/src/screens/__tests__/LocationHistoryScreen.test.tsxindex a48a3e24..0531449a 100644--- a/apps/mobile/src/screens/__tests__/LocationHistoryScreen.test.tsx+++ b/apps/mobile/src/screens/__tests__/LocationHistoryScreen.test.tsx@@ -110,15 +110,16 @@ jest.mock("../../utils/logger", () => ({import { LocationHistoryScreen } from "../LocationInspectorScreen"-const createProps = () => ({- navigation: {- navigate: jest.fn(),- setOptions: jest.fn()- },- route: {- params: {}- }-})+const createProps = () =>+ ({+ navigation: {+ navigate: jest.fn(),+ setOptions: jest.fn()+ },+ route: {+ params: {}+ }+ }) as anydescribe("LocationHistoryScreen", () => {beforeEach(() => {diff --git a/apps/mobile/src/screens/__tests__/ProfileEditorScreen.test.tsx b/apps/mobile/src/screens/__tests__/ProfileEditorScreen.test.tsxindex 3aca244d..97608c2c 100644--- a/apps/mobile/src/screens/__tests__/ProfileEditorScreen.test.tsx+++ b/apps/mobile/src/screens/__tests__/ProfileEditorScreen.test.tsx@@ -108,11 +108,11 @@ describe("ProfileEditorScreen", () => {})function renderNewProfile() {- return render(<ProfileEditorScreen navigation={mockNavigation as any} route={{ params: {} }} />)+ return render(<ProfileEditorScreen navigation={mockNavigation as any} route={{ params: {} } as any} />)}function renderEditProfile(profileId = 1) {- return render(<ProfileEditorScreen navigation={mockNavigation as any} route={{ params: { profileId } }} />)+ return render(<ProfileEditorScreen navigation={mockNavigation as any} route={{ params: { profileId } } as any} />)}// --- New Profile Mode ---diff --git a/apps/mobile/src/types/global.ts b/apps/mobile/src/types/global.tsindex afa3063d..1d1edd28 100644--- a/apps/mobile/src/types/global.ts+++ b/apps/mobile/src/types/global.ts@@ -7,8 +7,11 @@// NAVIGATION & UI// ============================================================================+import type { NativeStackNavigationProp } from "@react-navigation/native-stack"+import type { RootStackParamList } from "./navigation"+export interface ScreenProps {- navigation: any+ navigation: NativeStackNavigationProp<RootStackParamList>}export type { ThemeColors, ThemeMode } from "@colota/shared"diff --git a/apps/mobile/src/types/navigation.ts b/apps/mobile/src/types/navigation.tsnew file mode 100644index 00000000..e9359804--- /dev/null+++ b/apps/mobile/src/types/navigation.ts@@ -0,0 +1,44 @@+/**+ * Copyright (C) 2026 Max Dietrich+ * Licensed under the GNU AGPLv3. See LICENSE in the project root for details.+ */++import type { NativeStackScreenProps } from "@react-navigation/native-stack"+import type { Trip } from "./global"++type InspectorTab = "map" | "trips" | "data"++export type RootStackParamList = {+ Dashboard: undefined+ Settings: undefined+ Connection: undefined+ "Tracking & Sync": undefined+ Appearance: undefined+ "API Config": undefined+ "Auth Settings": undefined+ Geofences: undefined+ "Geofence Editor": { geofenceId?: number; name?: string; radius?: number; lat?: number; lon?: number } | undefined+ "Location History": { initialTab?: InspectorTab; initialDate?: string } | undefined+ "Location Summary": undefined+ "Export Data": undefined+ "Auto-Export": undefined+ "Data Management": undefined+ "Tracking Profiles": undefined+ "Profile Editor": { profileId?: number } | undefined+ "About Colota": undefined+ "Setup Import": undefined+ "Trip Detail": { trip: Trip }+ "Offline Maps": undefined+ "Activity Log": undefined+}++export type RootStackRoute = keyof RootStackParamList++export type RootScreenProps<Route extends RootStackRoute> = NativeStackScreenProps<RootStackParamList, Route>++declare global {+ // eslint-disable-next-line @typescript-eslint/no-namespace+ namespace ReactNavigation {+ interface RootParamList extends RootStackParamList {}+ }+}