GT2/Ejectable/App.tsx

64 lines
1.9 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';
import { Platform, Text, View, Switch, StyleSheet } from 'react-native';
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-18 18:21:15 +00:00
export var debug:boolean = false;
export var expoGeoState:any;
export var tripInProgress:boolean = true;
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
}
}
2021-08-18 18:21:15 +00:00
export function toggleTripInProgress() {tripInProgress = !tripInProgress;}