GT2/Ejectable/App.tsx

62 lines
1.7 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-20 08:41:16 +00:00
import { 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';
import useCachedResources from './hooks/useCachedResources';
import useColorScheme from './hooks/useColorScheme';
import Navigation from './navigation';
2021-08-20 08:41:16 +00:00
import { GT2 } from './GT2';
2021-08-21 07:45:27 +00:00
export var debug:boolean = false;
2021-08-18 18:21:15 +00:00
export var expoGeoState:any;
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;
}
let location = await Location.getCurrentPositionAsync({});
setLocation(location);
})();
}, []);
expoGeoState = 'Waiting..';
if (errorMsg) {
expoGeoState = errorMsg;
} else if (location) {
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
}
}