Skip to content

Commit

Permalink
feat: If position is stale, show searching in UI
Browse files Browse the repository at this point in the history
  • Loading branch information
gmaclennan committed Apr 13, 2019
1 parent 95c438a commit 0a9d2be
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/frontend/components/GpsPill.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0a9d2be

Please sign in to comment.