2021-08-16 07:50:50 +00:00
|
|
|
import 'react-native-gesture-handler';
|
|
|
|
import { StatusBar } from 'expo-status-bar';
|
2021-08-18 18:21:15 +00:00
|
|
|
import React, { useState, useEffect } from 'react';
|
2021-08-28 10:27:48 +00:00
|
|
|
import { Alert, Text } from 'react-native';
|
2021-08-18 18:21:15 +00:00
|
|
|
import * as Location from 'expo-location';
|
2021-08-16 07:50:50 +00:00
|
|
|
import { SafeAreaProvider } from 'react-native-safe-area-context';
|
2021-08-22 04:30:04 +00:00
|
|
|
|
2021-08-16 07:50:50 +00:00
|
|
|
import useCachedResources from './hooks/useCachedResources';
|
|
|
|
import useColorScheme from './hooks/useColorScheme';
|
|
|
|
import Navigation from './navigation';
|
2021-08-23 06:34:16 +00:00
|
|
|
import { Trips } from './GT2';
|
|
|
|
|
2021-08-24 00:02:21 +00:00
|
|
|
var debug:boolean = false;
|
|
|
|
var expoGeoState:any = null;
|
2021-08-25 07:59:02 +00:00
|
|
|
var advised:boolean = false;
|
2021-08-26 03:46:39 +00:00
|
|
|
|
2021-08-25 07:59:02 +00:00
|
|
|
export function getAdvised() : boolean { return advised; }
|
|
|
|
export function setAdvised() : void { advised = true; }
|
|
|
|
|
2021-08-16 07:50:50 +00:00
|
|
|
export default function App() {
|
|
|
|
const isLoadingComplete = useCachedResources();
|
|
|
|
const colorScheme = useColorScheme();
|
2021-08-30 00:19:58 +00:00
|
|
|
|
2021-08-16 22:39:34 +00:00
|
|
|
const [isKM, setIsKM] = useState(false);
|
|
|
|
const toggleUnits = () => setIsKM(previousState => !previousState);
|
2021-08-30 00:19:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
const [location, setLocation] = useState(Object);
|
|
|
|
const [errorMsg, setErrorMsg] = useState("");
|
2021-08-18 18:21:15 +00:00
|
|
|
|
2021-08-30 00:19:58 +00:00
|
|
|
useEffect(() => {
|
2021-08-18 18:21:15 +00:00
|
|
|
(async () => {
|
|
|
|
let { status } = await Location.requestForegroundPermissionsAsync();
|
|
|
|
if (status !== 'granted') {
|
|
|
|
setErrorMsg('Permission to access location was denied');
|
2021-08-26 03:46:39 +00:00
|
|
|
Trips.setLocEnabled(false);
|
2021-08-28 10:27:48 +00:00
|
|
|
Alert.alert("Permission to access location was denied, this app requires it.");
|
2021-08-18 18:21:15 +00:00
|
|
|
return;
|
2021-08-24 00:02:21 +00:00
|
|
|
} else Trips.setLocEnabled(true);
|
2021-08-18 18:21:15 +00:00
|
|
|
|
2021-08-28 10:27:48 +00:00
|
|
|
if (debug) {
|
2021-08-18 18:21:15 +00:00
|
|
|
let location = await Location.getCurrentPositionAsync({});
|
|
|
|
setLocation(location);
|
2021-08-24 00:02:21 +00:00
|
|
|
Trips.deltaLoc(location);
|
2021-08-28 10:27:48 +00:00
|
|
|
}
|
2021-08-18 18:21:15 +00:00
|
|
|
})();
|
2021-08-30 00:19:58 +00:00
|
|
|
}, []);
|
2021-08-18 18:21:15 +00:00
|
|
|
|
2021-08-30 00:19:58 +00:00
|
|
|
expoGeoState = 'Waiting..';
|
|
|
|
if (errorMsg) {
|
2021-08-18 18:21:15 +00:00
|
|
|
expoGeoState = errorMsg;
|
2021-08-30 00:19:58 +00:00
|
|
|
} else if (location) {
|
2021-08-18 18:21:15 +00:00
|
|
|
expoGeoState = JSON.stringify(location);
|
2021-08-30 00:19:58 +00:00
|
|
|
}
|
|
|
|
|
2021-08-25 02:25:04 +00:00
|
|
|
|
2021-08-16 07:50:50 +00:00
|
|
|
if (!isLoadingComplete) {
|
|
|
|
return null;
|
|
|
|
} else {
|
2021-08-18 18:21:15 +00:00
|
|
|
if (!debug)
|
2021-08-16 07:50:50 +00:00
|
|
|
return (
|
|
|
|
<SafeAreaProvider>
|
|
|
|
<Navigation colorScheme={colorScheme} />
|
|
|
|
<StatusBar />
|
|
|
|
</SafeAreaProvider>
|
|
|
|
);
|
2021-08-18 18:21:15 +00:00
|
|
|
else
|
|
|
|
return (
|
|
|
|
<SafeAreaProvider>
|
|
|
|
<Navigation colorScheme={colorScheme} />
|
|
|
|
<Text>{expoGeoState}</Text>
|
|
|
|
<StatusBar />
|
|
|
|
</SafeAreaProvider>
|
|
|
|
);
|
2021-08-16 07:50:50 +00:00
|
|
|
}
|
2021-08-25 02:25:04 +00:00
|
|
|
|
2021-08-16 07:50:50 +00:00
|
|
|
}
|