From 0a9d2be291cfdea411f2407bcf512f5d413c6ee4 Mon Sep 17 00:00:00 2001 From: Gregor MacLennan Date: Sat, 13 Apr 2019 11:32:26 +0100 Subject: [PATCH] feat: If position is stale, show searching in UI --- src/frontend/components/GpsPill.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/frontend/components/GpsPill.js b/src/frontend/components/GpsPill.js index 2c95985dd..69b97c23c 100644 --- a/src/frontend/components/GpsPill.js +++ b/src/frontend/components/GpsPill.js @@ -6,8 +6,14 @@ import { withNavigation, withNavigationFocus } from "react-navigation"; import LocationContext from "../context/LocationContext"; import GpsIcon from "./icons/GpsIcon"; -const GOOD_PRECISION = 10; +// If the current position on the app state is more than 60 seconds old then we +// consider it stale and show that the GPS is searching for a new position +const STALE_TIMEOUT = 60 * 1000; // 60 seconds +// If the precision is less than 10 meters then we consider this to be a "good +// position" and we change the UI accordingly +const GOOD_PRECISION = 10; // 10 meters const ERROR_COLOR = "#FF0000"; + const styles = StyleSheet.create({ container: { flex: 0, @@ -85,9 +91,12 @@ const ConnectedGpsPill = ({ navigation, isFocused }) => ( const locationServicesDisabled = provider && !provider.locationServicesEnabled; const noPermission = permission && permission !== "granted"; + const positionStale = + position && Date.now() - position.timestamp > STALE_TIMEOUT; let variant: Variant; if (error || gpsUnavailable || locationServicesDisabled || noPermission) variant = "error"; + else if (positionStale) variant = "searching"; else if ( typeof precision === "number" && Math.round(precision) <= GOOD_PRECISION