-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathApp.tsx
66 lines (58 loc) · 1.76 KB
/
App.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import "./i18n";
import { AppLoading, Asset } from "expo";
import * as Location from "expo-location";
import * as Permissions from "expo-permissions";
import React from "react";
import { StyleSheet, View } from "react-native";
import RootStackNavigator from "./RootStackNavigator";
import { useTranslation } from 'react-i18next';
export default function App() {
const [appIsReady, setAppIsReady] = React.useState<boolean>(false);
const [location, setLocation] = React.useState<Location.LocationData>();
const [errorMessage, setErrorMessage] = React.useState<string>("");
const { t } = useTranslation();
React.useEffect(() => {
_getLocationAsync();
}, []);
const _loadAppAsync = async (): Promise<void> => {
// require any images like icons in this below array like so:
// require('./assets/images/whatever-icon.png
const images: string[] = [];
const cacheImages = images.map(image => {
return Asset.fromModule(image).downloadAsync();
});
Promise.all(cacheImages);
return;
};
const _getLocationAsync = async () => {
let { status } = await Permissions.askAsync(Permissions.LOCATION);
if (status !== "granted") {
// TODO translate
setErrorMessage("Permission to access location was denied.");
}
let location = await Location.getCurrentPositionAsync({
enableHighAccuracy: false
});
setLocation(location);
};
if (!appIsReady) {
return (
<AppLoading
startAsync={_loadAppAsync}
onError={console.warn}
onFinish={() => setAppIsReady(true)}
/>
);
}
return (
<View style={styles.container}>
<RootStackNavigator screenProps={{t}}/>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#fff"
}
});