Skip to content

Colota - Android GPS Location tracker

fix: improve touch targets, navigation and render performance Closes #274

Max Dietrich7222093eddb8
diff --git a/apps/mobile/App.tsx b/apps/mobile/App.tsx
index 7079d57d..b8e7b02b 100644
--- a/apps/mobile/App.tsx
+++ b/apps/mobile/App.tsx
@@ -187,7 +187,11 @@ function AppNavigator() {
}, [])
const handleTabNavigate = useCallback((route: string) => {
- navigationRef.current?.reset({ index: 0, routes: [{ name: route }] })
+ const nav = navigationRef.current
+ if (!nav) return
+ const current = nav.getCurrentRoute()?.name
+ if (current === route) return
+ nav.navigate(route as never)
}, [])
return (
diff --git a/apps/mobile/src/components/features/inspector/CalendarPicker.tsx b/apps/mobile/src/components/features/inspector/CalendarPicker.tsx
index e4df406d..1522385c 100644
--- a/apps/mobile/src/components/features/inspector/CalendarPicker.tsx
+++ b/apps/mobile/src/components/features/inspector/CalendarPicker.tsx
@@ -9,6 +9,7 @@ import { ChevronLeft, ChevronRight, Calendar } from "lucide-react-native"
import { ThemeColors } from "../../../types/global"
import { fonts } from "../../../styles/typography"
import { formatDistance } from "../../../utils/geo"
+import { HIT_SLOP_LG } from "../../../constants"
interface CalendarPickerProps {
date: Date
@@ -159,6 +160,7 @@ export function CalendarPicker({
<View style={styles.row}>
<Pressable
onPress={goBack}
+ hitSlop={HIT_SLOP_LG}
style={({ pressed }) => [styles.navBtn, pressed && { opacity: colors.pressedOpacity }]}
>
<ChevronLeft size={22} color={colors.primary} />
@@ -185,6 +187,7 @@ export function CalendarPicker({
<Pressable
onPress={goForward}
+ hitSlop={HIT_SLOP_LG}
style={({ pressed }) => [styles.navBtn, pressed && { opacity: colors.pressedOpacity }]}
disabled={isToday}
>
@@ -212,6 +215,7 @@ export function CalendarPicker({
<View style={styles.monthRow}>
<Pressable
onPress={() => navigateMonth(-1)}
+ hitSlop={HIT_SLOP_LG}
style={({ pressed }) => [styles.monthNav, pressed && { opacity: colors.pressedOpacity }]}
>
<ChevronLeft size={18} color={colors.primary} />
@@ -219,6 +223,7 @@ export function CalendarPicker({
<Text style={[styles.monthLabel, { color: colors.text }]}>{monthLabel}</Text>
<Pressable
onPress={() => navigateMonth(1)}
+ hitSlop={HIT_SLOP_LG}
style={({ pressed }) => [styles.monthNav, pressed && { opacity: colors.pressedOpacity }]}
disabled={isFutureMonth}
>
@@ -355,7 +360,7 @@ const styles = StyleSheet.create({
marginBottom: 8
},
monthNav: {
- padding: 4
+ padding: 8
},
monthLabel: {
fontSize: 14,
diff --git a/apps/mobile/src/components/features/inspector/TrackMap.tsx b/apps/mobile/src/components/features/inspector/TrackMap.tsx
index 985d4997..590dfde7 100644
--- a/apps/mobile/src/components/features/inspector/TrackMap.tsx
+++ b/apps/mobile/src/components/features/inspector/TrackMap.tsx
@@ -19,7 +19,7 @@ import {
type TrackLocation
} from "../map/mapUtils"
import { getSpeedUnit } from "../../../utils/geo"
-import { MAP_ANIMATION_DURATION_MS } from "../../../constants"
+import { HIT_SLOP_MD, MAP_ANIMATION_DURATION_MS } from "../../../constants"
const trackLineStyle = {
lineColor: ["get", "color"] as const,
@@ -268,7 +268,7 @@ export function TrackMap({ locations, selectedPoint, colors, trips, fitVersion }
</Text>
<Pressable
onPress={() => setPopup(null)}
- hitSlop={{ top: 8, right: 8, bottom: 8, left: 8 }}
+ hitSlop={HIT_SLOP_MD}
style={({ pressed }) => pressed && { opacity: colors.pressedOpacity }}
>
<X size={16} color={colors.textSecondary} />
diff --git a/apps/mobile/src/components/features/inspector/TripList.tsx b/apps/mobile/src/components/features/inspector/TripList.tsx
index 4c7b815a..ba706b64 100644
--- a/apps/mobile/src/components/features/inspector/TripList.tsx
+++ b/apps/mobile/src/components/features/inspector/TripList.tsx
@@ -12,6 +12,7 @@ import { formatDistance, formatDuration, formatSpeed, formatTime } from "../../.
import type { Trip, ThemeColors } from "../../../types/global"
import { getTripColor, computeTripStats, type TripStats } from "../../../utils/trips"
import { EXPORT_FORMATS, EXPORT_FORMAT_KEYS, type ExportFormat } from "../../../utils/exportConverters"
+import { HIT_SLOP_SM } from "../../../constants"
interface TripListProps {
trips: Trip[]
@@ -61,7 +62,7 @@ export function TripList({ trips, colors, onTripSelect, selectedTripIndex, onExp
{onExportTrip && (
<Pressable
onPress={() => setExportingTripIndex((prev) => (prev === item.index ? null : item.index))}
- hitSlop={{ top: 6, right: 6, bottom: 6, left: 6 }}
+ hitSlop={HIT_SLOP_SM}
style={({ pressed }) => pressed && { opacity: colors.pressedOpacity }}
>
<Share size={14} color={showTripExport ? colors.primary : colors.textSecondary} />
diff --git a/apps/mobile/src/constants/index.ts b/apps/mobile/src/constants/index.ts
index 7949b750..3e084f1c 100644
--- a/apps/mobile/src/constants/index.ts
+++ b/apps/mobile/src/constants/index.ts
@@ -18,6 +18,11 @@ export const TEST_RESULT_DISPLAY_MS = 5_000
export const SERVICE_RESTART_DELAY_MS = 500
export const RESTART_DEBOUNCE_MS = 100
+// Touch targets
+export const HIT_SLOP_SM = { top: 6, right: 6, bottom: 6, left: 6 } as const
+export const HIT_SLOP_MD = { top: 8, right: 8, bottom: 8, left: 8 } as const
+export const HIT_SLOP_LG = { top: 12, right: 12, bottom: 12, left: 12 } as const
+
// Map
export const DEFAULT_MAP_ZOOM = 17
export const WORLD_MAP_ZOOM = 2
diff --git a/apps/mobile/src/screens/GeofenceEditorScreen.tsx b/apps/mobile/src/screens/GeofenceEditorScreen.tsx
index 2705e1bf..379e70ef 100644
--- a/apps/mobile/src/screens/GeofenceEditorScreen.tsx
+++ b/apps/mobile/src/screens/GeofenceEditorScreen.tsx
@@ -4,7 +4,16 @@
*/
import React, { useState, useEffect, useCallback, useRef, useMemo } from "react"
-import { View, Text, StyleSheet, ScrollView, Switch, TextInput, DeviceEventEmitter } from "react-native"
+import {
+ View,
+ Text,
+ StyleSheet,
+ ScrollView,
+ Switch,
+ TextInput,
+ DeviceEventEmitter,
+ InteractionManager
+} from "react-native"
import { useTheme } from "../hooks/useTheme"
import NativeLocationService from "../services/NativeLocationService"
import { showAlert, showConfirm } from "../services/modalService"
@@ -70,38 +79,42 @@ export function GeofenceEditorScreen({ navigation, route }: any) {
useEffect(() => {
if (!geofenceId) return
- NativeLocationService.getGeofences()
- .then((geofences) => {
- const existing = geofences.find((g) => g.id === geofenceId)
- if (existing) {
- setName(existing.name)
- setRadiusStr(String(metersToInput(existing.radius)))
- setRadius(existing.radius)
- setPauseTracking(existing.pauseTracking)
- setPauseOnWifi(existing.pauseOnWifi)
- setPauseOnMotionless(existing.pauseOnMotionless)
- setMotionlessTimeoutMinutes(existing.motionlessTimeoutMinutes)
- setMotionlessTimeoutStr(String(existing.motionlessTimeoutMinutes))
- setHeartbeatEnabled(existing.heartbeatEnabled ?? false)
- setHeartbeatIntervalMinutes(existing.heartbeatIntervalMinutes ?? 15)
- setHeartbeatIntervalStr(String(existing.heartbeatIntervalMinutes ?? 15))
- savedState.current = {
- name: existing.name,
- radius: existing.radius,
- pauseTracking: existing.pauseTracking,
- pauseOnWifi: existing.pauseOnWifi,
- pauseOnMotionless: existing.pauseOnMotionless,
- motionlessTimeoutMinutes: existing.motionlessTimeoutMinutes,
- heartbeatEnabled: existing.heartbeatEnabled ?? false,
- heartbeatIntervalMinutes: existing.heartbeatIntervalMinutes ?? 15
+ const task = InteractionManager.runAfterInteractions(() => {
+ NativeLocationService.getGeofences()
+ .then((geofences) => {
+ const existing = geofences.find((g) => g.id === geofenceId)
+ if (existing) {
+ setName(existing.name)
+ setRadiusStr(String(metersToInput(existing.radius)))
+ setRadius(existing.radius)
+ setPauseTracking(existing.pauseTracking)
+ setPauseOnWifi(existing.pauseOnWifi)
+ setPauseOnMotionless(existing.pauseOnMotionless)
+ setMotionlessTimeoutMinutes(existing.motionlessTimeoutMinutes)
+ setMotionlessTimeoutStr(String(existing.motionlessTimeoutMinutes))
+ setHeartbeatEnabled(existing.heartbeatEnabled ?? false)
+ setHeartbeatIntervalMinutes(existing.heartbeatIntervalMinutes ?? 15)
+ setHeartbeatIntervalStr(String(existing.heartbeatIntervalMinutes ?? 15))
+ savedState.current = {
+ name: existing.name,
+ radius: existing.radius,
+ pauseTracking: existing.pauseTracking,
+ pauseOnWifi: existing.pauseOnWifi,
+ pauseOnMotionless: existing.pauseOnMotionless,
+ motionlessTimeoutMinutes: existing.motionlessTimeoutMinutes,
+ heartbeatEnabled: existing.heartbeatEnabled ?? false,
+ heartbeatIntervalMinutes: existing.heartbeatIntervalMinutes ?? 15
+ }
}
- }
- })
- .catch((err) => {
- logger.error("[GeofenceEditor] Failed to load geofence:", err)
- showAlert("Error", "Failed to load geofence data.", "error")
- navigation.goBack()
- })
+ })
+ .catch((err) => {
+ logger.error("[GeofenceEditor] Failed to load geofence:", err)
+ showAlert("Error", "Failed to load geofence data.", "error")
+ navigation.goBack()
+ })
+ })
+
+ return () => task.cancel()
}, [geofenceId, navigation])
const handleRadiusChange = useCallback((val: string) => {
diff --git a/apps/mobile/src/screens/GeofenceScreen.tsx b/apps/mobile/src/screens/GeofenceScreen.tsx
index 19a9db8f..b6fd8730 100644
--- a/apps/mobile/src/screens/GeofenceScreen.tsx
+++ b/apps/mobile/src/screens/GeofenceScreen.tsx
@@ -11,14 +11,15 @@ import { showAlert } from "../services/modalService"
import { Geofence, ScreenProps } from "../types/global"
import { useTracking, useCoords } from "../contexts/TrackingProvider"
import { fonts } from "../styles/typography"
-import { ChevronRight, Wifi, PersonStanding } from "lucide-react-native"
+import { ChevronRight, Wifi, PersonStanding, MapPin } from "lucide-react-native"
import { Container, SectionTitle, Card } from "../components"
import {
DEFAULT_MAP_ZOOM,
WORLD_MAP_ZOOM,
GEOFENCE_ZOOM_PADDING,
MAP_ANIMATION_DURATION_MS,
- MAX_MAP_ZOOM
+ MAX_MAP_ZOOM,
+ HIT_SLOP_MD
} from "../constants"
import { MapCenterButton } from "../components/features/map/MapCenterButton"
import { ColotaMapView, ColotaMapRef } from "../components/features/map/ColotaMapView"
@@ -28,55 +29,117 @@ import { UserLocationOverlay } from "../components/features/map/UserLocationOver
import { logger } from "../utils/logger"
import { formatShortDistance, shortDistanceUnit, inputToMeters } from "../utils/geo"
-export function GeofenceScreen({ navigation }: ScreenProps) {
- const { tracking } = useTracking()
+const GeofenceMap = React.memo(function GeofenceMap({
+ tracking,
+ geofenceData,
+ currentPauseZone,
+ onMapPress,
+ focusRequest
+}: {
+ tracking: boolean
+ geofenceData: ReturnType<typeof buildGeofencesGeoJSON>
+ currentPauseZone: string | null
+ onMapPress: (coords: { latitude: number; longitude: number }) => void
+ focusRequest: { geofence: Geofence; key: number } | null
+}) {
const coords = useCoords()
const { colors } = useTheme()
- const [geofences, setGeofences] = useState<Geofence[]>([])
- const [newName, setNewName] = useState("")
- const [newRadius, setNewRadius] = useState("50")
- const [placingGeofence, setPlacingGeofence] = useState(false)
- const [isCentered, setIsCentered] = useState(true)
+ const mapRef = useRef<ColotaMapRef>(null)
const isCenteredRef = useRef(true)
+ const [isCentered, setIsCentered] = useState(true)
const [hasInitialCoords, setHasInitialCoords] = useState(false)
- const [currentPauseZone, setCurrentPauseZone] = useState<string | null>(null)
+ const initialCenter = useRef<{ latitude: number; longitude: number; accuracy: number } | null>(null)
- const mapRef = useRef<ColotaMapRef>(null)
- const initialCenter = useRef<{
- latitude: number
- longitude: number
- accuracy: number
- } | null>(null)
-
- // Set initial map center
useEffect(() => {
if (hasInitialCoords) return
-
if (coords) {
- initialCenter.current = {
- latitude: coords.latitude,
- longitude: coords.longitude,
- accuracy: coords.accuracy ?? 0
- }
+ initialCenter.current = { latitude: coords.latitude, longitude: coords.longitude, accuracy: coords.accuracy ?? 0 }
setHasInitialCoords(true)
return
}
-
NativeLocationService.getMostRecentLocation().then((latest) => {
if (initialCenter.current) return
-
initialCenter.current = latest
- ? {
- latitude: latest.latitude,
- longitude: latest.longitude,
- accuracy: latest.accuracy ?? 0
- }
+ ? { latitude: latest.latitude, longitude: latest.longitude, accuracy: latest.accuracy ?? 0 }
: { latitude: 0, longitude: 0, accuracy: 0 }
setHasInitialCoords(true)
})
}, [coords, hasInitialCoords])
+ useEffect(() => {
+ if (!coords || !isCenteredRef.current || !tracking || !mapRef.current?.camera) return
+ mapRef.current.camera.moveTo([coords.longitude, coords.latitude], MAP_ANIMATION_DURATION_MS)
+ }, [coords, tracking])
+
+ useEffect(() => {
+ if (!focusRequest || !mapRef.current?.camera) return
+ const { geofence } = focusRequest
+ const latDelta = (geofence.radius / 111320) * 1.5
+ const lonDelta = (geofence.radius / (111320 * Math.cos((geofence.lat * Math.PI) / 180))) * 1.5
+ mapRef.current.camera.fitBounds(
+ [geofence.lon + lonDelta, geofence.lat + latDelta],
+ [geofence.lon - lonDelta, geofence.lat - latDelta],
+ [...GEOFENCE_ZOOM_PADDING],
+ 600
+ )
+ }, [focusRequest])
+
+ const handleCenterMe = useCallback(() => {
+ if (coords && mapRef.current?.camera) {
+ mapRef.current.camera.setCamera({
+ centerCoordinate: [coords.longitude, coords.latitude],
+ zoomLevel: MAX_MAP_ZOOM,
+ animationDuration: MAP_ANIMATION_DURATION_MS,
+ animationMode: "flyTo"
+ })
+ isCenteredRef.current = true
+ setIsCentered(true)
+ }
+ }, [coords])
+
+ const handleRegionChange = useCallback((payload: { isUserInteraction: boolean }) => {
+ if (payload.isUserInteraction) {
+ isCenteredRef.current = false
+ setIsCentered(false)
+ }
+ }, [])
+
+ const hasRealCoords =
+ initialCenter.current && (initialCenter.current.latitude !== 0 || initialCenter.current.longitude !== 0)
+ const initialZoom = hasRealCoords ? DEFAULT_MAP_ZOOM : WORLD_MAP_ZOOM
+
+ return (
+ <View style={[styles.map, { borderRadius: colors.borderRadius }]}>
+ {hasInitialCoords && initialCenter.current ? (
+ <ColotaMapView
+ ref={mapRef}
+ initialCenter={[initialCenter.current.longitude, initialCenter.current.latitude]}
+ initialZoom={initialZoom}
+ onPress={onMapPress}
+ onRegionDidChange={handleRegionChange}
+ >
+ <GeofenceLayers fills={geofenceData.fills} labels={geofenceData.labels} haloColor={colors.card} />
+ {coords && tracking && <UserLocationOverlay coords={coords} isPaused={!!currentPauseZone} colors={colors} />}
+ </ColotaMapView>
+ ) : null}
+ <MapCenterButton visible={!isCentered && tracking} onPress={handleCenterMe} />
+ </View>
+ )
+})
+
+export function GeofenceScreen({ navigation }: ScreenProps) {
+ const { tracking } = useTracking()
+ const { colors } = useTheme()
+
+ const [geofences, setGeofences] = useState<Geofence[]>([])
+ const [newName, setNewName] = useState("")
+ const [newRadius, setNewRadius] = useState("50")
+ const [placingGeofence, setPlacingGeofence] = useState(false)
+ const [currentPauseZone, setCurrentPauseZone] = useState<string | null>(null)
+
+ const [focusRequest, setFocusRequest] = useState<{ geofence: Geofence; key: number } | null>(null)
+
const loadGeofences = useCallback(async () => {
try {
const data = await NativeLocationService.getGeofences()
@@ -108,12 +171,6 @@ export function GeofenceScreen({ navigation }: ScreenProps) {
return () => listener.remove()
}, [loadGeofences])
- // Auto-center camera when position changes (ref avoids overriding setCamera zoom).
- useEffect(() => {
- if (!coords || !isCenteredRef.current || !tracking || !mapRef.current?.camera) return
- mapRef.current.camera.moveTo([coords.longitude, coords.latitude], MAP_ANIMATION_DURATION_MS)
- }, [coords, tracking])
-
const handleMapPress = useCallback(
async (pressCoords: { latitude: number; longitude: number }) => {
if (!placingGeofence) return
@@ -159,71 +216,39 @@ export function GeofenceScreen({ navigation }: ScreenProps) {
setPlacingGeofence(true)
}, [newName, newRadius])
- const handleCenterMe = useCallback(() => {
- if (coords && mapRef.current?.camera) {
- mapRef.current.camera.setCamera({
- centerCoordinate: [coords.longitude, coords.latitude],
- zoomLevel: MAX_MAP_ZOOM,
- animationDuration: MAP_ANIMATION_DURATION_MS,
- animationMode: "flyTo"
- })
- isCenteredRef.current = true
- setIsCentered(true)
- }
- }, [coords])
-
- const handleRegionChange = useCallback((payload: { isUserInteraction: boolean }) => {
- if (payload.isUserInteraction) {
- isCenteredRef.current = false
- setIsCentered(false)
- }
- }, [])
-
+ const focusKeyRef = useRef(0)
const handleZoomToGeofence = useCallback((item: Geofence) => {
- if (!mapRef.current?.camera) return
-
- // Compute bounds from circle center + radius
- const latDelta = (item.radius / 111320) * 1.5
- const lonDelta = (item.radius / (111320 * Math.cos((item.lat * Math.PI) / 180))) * 1.5
- mapRef.current.camera.fitBounds(
- [item.lon + lonDelta, item.lat + latDelta],
- [item.lon - lonDelta, item.lat - latDelta],
- [...GEOFENCE_ZOOM_PADDING],
- 600
- )
+ setFocusRequest({ geofence: item, key: ++focusKeyRef.current })
}, [])
- // Geofence GeoJSON
const geofenceData = useMemo(() => buildGeofencesGeoJSON(geofences, colors), [geofences, colors])
- const hasRealCoords =
- initialCenter.current && (initialCenter.current.latitude !== 0 || initialCenter.current.longitude !== 0)
- const initialZoom = hasRealCoords ? DEFAULT_MAP_ZOOM : WORLD_MAP_ZOOM
-
const renderItem = useCallback(
({ item }: { item: Geofence }) => (
<Card style={styles.card}>
<View style={styles.row}>
<Pressable
- testID={`geofence-info-${item.id}`}
- style={({ pressed }) => [styles.info, pressed && { opacity: colors.pressedOpacity }]}
onPress={() => handleZoomToGeofence(item)}
+ hitSlop={HIT_SLOP_MD}
+ style={({ pressed }) => [styles.zoomBtn, pressed && { opacity: colors.pressedOpacity }]}
>
- <Text style={[styles.name, { color: colors.text }]}>{item.name}</Text>
- <View style={styles.radiusRow}>
- <Text style={[styles.radius, { color: colors.textSecondary }]}>
- {formatShortDistance(item.radius)} radius
- </Text>
- {item.pauseOnWifi && <Wifi size={12} color={colors.textSecondary} />}
- {item.pauseOnMotionless && <PersonStanding size={12} color={colors.textSecondary} />}
- </View>
+ <MapPin size={18} color={colors.textSecondary} />
</Pressable>
-
<Pressable
testID={`edit-geofence-${item.id}`}
+ style={({ pressed }) => [styles.editBtn, pressed && { opacity: colors.pressedOpacity }]}
onPress={() => navigation.navigate("Geofence Editor", { geofenceId: item.id })}
- style={({ pressed }) => [pressed && { opacity: colors.pressedOpacity }]}
>
+ <View style={styles.info}>
+ <Text style={[styles.name, { color: colors.text }]}>{item.name}</Text>
+ <View style={styles.radiusRow}>
+ <Text style={[styles.radius, { color: colors.textSecondary }]}>
+ {formatShortDistance(item.radius)} radius
+ </Text>
+ {item.pauseOnWifi && <Wifi size={12} color={colors.textSecondary} />}
+ {item.pauseOnMotionless && <PersonStanding size={12} color={colors.textSecondary} />}
+ </View>
+ </View>
<ChevronRight size={20} color={colors.textSecondary} />
</Pressable>
</View>
@@ -234,26 +259,13 @@ export function GeofenceScreen({ navigation }: ScreenProps) {
return (
<Container>
- <View style={[styles.map, { borderRadius: colors.borderRadius }]}>
- {hasInitialCoords && initialCenter.current ? (
- <ColotaMapView
- ref={mapRef}
- initialCenter={[initialCenter.current.longitude, initialCenter.current.latitude]}
- initialZoom={initialZoom}
- onPress={handleMapPress}
- onRegionDidChange={handleRegionChange}
- >
- <GeofenceLayers fills={geofenceData.fills} labels={geofenceData.labels} haloColor={colors.card} />
-
- {/* Accuracy circle + user marker */}
- {coords && tracking && (
- <UserLocationOverlay coords={coords} isPaused={!!currentPauseZone} colors={colors} />
- )}
- </ColotaMapView>
- ) : null}
-
- <MapCenterButton visible={!isCentered && tracking} onPress={handleCenterMe} />
- </View>
+ <GeofenceMap
+ tracking={tracking}
+ geofenceData={geofenceData}
+ currentPauseZone={currentPauseZone}
+ onMapPress={handleMapPress}
+ focusRequest={focusRequest}
+ />
<FlatList
data={geofences}
@@ -380,6 +392,8 @@ const styles = StyleSheet.create({
alignItems: "center",
justifyContent: "space-between"
},
+ zoomBtn: { padding: 4, marginRight: 8 },
+ editBtn: { flex: 1, flexDirection: "row", alignItems: "center" },
info: { flex: 1, marginRight: 12 },
name: { fontSize: 15, ...fonts.semiBold, marginBottom: 2 },
radiusRow: { flexDirection: "row", alignItems: "center", gap: 4 },
diff --git a/apps/mobile/src/screens/SettingsScreen.tsx b/apps/mobile/src/screens/SettingsScreen.tsx
index 1c244349..883e5e56 100644
--- a/apps/mobile/src/screens/SettingsScreen.tsx
+++ b/apps/mobile/src/screens/SettingsScreen.tsx
@@ -4,6 +4,7 @@
*/
import React, { useState, useCallback, useEffect } from "react"
+import { useFocusEffect } from "@react-navigation/native"
import { Text, StyleSheet, Switch, View, ScrollView, Pressable, TextInput, Linking } from "react-native"
import { ScreenProps, Settings } from "../types/global"
import { useTheme } from "../hooks/useTheme"
@@ -122,12 +123,14 @@ export function SettingsScreen({ navigation }: ScreenProps) {
}
}, [])
- // Poll stats: 3s when tracking, 30s when idle
- useEffect(() => {
- updateStats()
- const interval = setInterval(updateStats, tracking ? STATS_REFRESH_FAST : STATS_REFRESH_IDLE)
- return () => clearInterval(interval)
- }, [updateStats, tracking])
+ // Poll stats: 3s when tracking, 30s when idle (only while screen is focused)
+ useFocusEffect(
+ useCallback(() => {
+ updateStats()
+ const interval = setInterval(updateStats, tracking ? STATS_REFRESH_FAST : STATS_REFRESH_IDLE)
+ return () => clearInterval(interval)
+ }, [updateStats, tracking])
+ )
/** Debounced save + restart for continuous changes (text input, sliders) */
const handleDebouncedSave = useCallback(
diff --git a/apps/mobile/src/screens/__tests__/GeofenceEditorScreen.test.tsx b/apps/mobile/src/screens/__tests__/GeofenceEditorScreen.test.tsx
index 84acb7e3..3f13a7eb 100644
--- a/apps/mobile/src/screens/__tests__/GeofenceEditorScreen.test.tsx
+++ b/apps/mobile/src/screens/__tests__/GeofenceEditorScreen.test.tsx
@@ -32,6 +32,12 @@ jest.mock("../../services/modalService", () => ({
jest.mock("react-native/Libraries/EventEmitter/NativeEventEmitter")
+jest.spyOn(require("react-native").InteractionManager, "runAfterInteractions").mockImplementation((task: any) => {
+ if (typeof task === "function") task()
+ else if (task?.run) task.run()
+ return { cancel: jest.fn(), done: Promise.resolve() }
+})
+
jest.mock("../../hooks/useTheme", () => ({
useTheme: () => ({
colors: {
diff --git a/apps/mobile/src/screens/__tests__/GeofenceScreen.test.tsx b/apps/mobile/src/screens/__tests__/GeofenceScreen.test.tsx
index b6c386bf..fdd0ee9f 100644
--- a/apps/mobile/src/screens/__tests__/GeofenceScreen.test.tsx
+++ b/apps/mobile/src/screens/__tests__/GeofenceScreen.test.tsx
@@ -144,7 +144,8 @@ jest.mock("lucide-react-native", () => {
return {
ChevronRight: (props: any) => R.createElement(Text, props, "ChevronRight"),
Wifi: (props: any) => R.createElement(Text, props, "Wifi"),
- PersonStanding: (props: any) => R.createElement(Text, props, "PersonStanding")
+ PersonStanding: (props: any) => R.createElement(Text, props, "PersonStanding"),
+ MapPin: (props: any) => R.createElement(Text, props, "MapPin")
}
})
diff --git a/apps/mobile/src/screens/__tests__/SettingsScreen.test.tsx b/apps/mobile/src/screens/__tests__/SettingsScreen.test.tsx
index cb9080a8..22a567a5 100644
--- a/apps/mobile/src/screens/__tests__/SettingsScreen.test.tsx
+++ b/apps/mobile/src/screens/__tests__/SettingsScreen.test.tsx
@@ -4,6 +4,10 @@ import { DEFAULT_SETTINGS, Settings } from "../../types/global"
// --- Mocks ---
+jest.mock("@react-navigation/native", () => ({
+ useFocusEffect: (cb: () => (() => void) | void) => require("react").useEffect(() => cb(), [])
+}))
+
let mockSettings: Settings = { ...DEFAULT_SETTINGS }
const mockSetSettings = jest.fn()
const mockUpdateSettingsLocal = jest.fn()