GT2/Ejectable/App.tsx

65 lines
1.8 KiB
TypeScript
Raw Normal View History

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-23 06:34:16 +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-18 18:21:15 +00:00
2021-08-16 07:50:50 +00:00
export default function App() {
const isLoadingComplete = useCachedResources();
const colorScheme = useColorScheme();
2021-08-16 22:39:34 +00:00
const [isKM, setIsKM] = useState(false);
const toggleUnits = () => setIsKM(previousState => !previousState);
2021-08-18 18:21:15 +00:00
const [location, setLocation] = useState(Object);
const [errorMsg, setErrorMsg] = useState("");
useEffect(() => {
(async () => {
let { status } = await Location.requestForegroundPermissionsAsync();
if (status !== 'granted') {
setErrorMsg('Permission to access location was denied');
return;
2021-08-24 00:02:21 +00:00
} else Trips.setLocEnabled(true);
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-18 18:21:15 +00:00
})();
}, []);
expoGeoState = 'Waiting..';
if (errorMsg) {
expoGeoState = errorMsg;
2021-08-23 06:34:16 +00:00
} else if (location) {
2021-08-18 18:21:15 +00:00
expoGeoState = JSON.stringify(location);
}
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
}
}