-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
87 lines (75 loc) · 2.12 KB
/
App.js
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import { StatusBar } from 'expo-status-bar';
import { StyleSheet, Text, View } from 'react-native';
import LoginScreen from './App/Screen/#Screen/#Screen';
import { ClerkProvider, SignedIn, SignedOut } from '@clerk/clerk-expo';
import Api from './Utils/Api';
import * as SecureStore from 'expo-secure-store';
import { NavigationContainer } from '@react-navigation/native';
import TabNavigation from './App/Navigation/TabNavigation';
import * as Location from 'expo-location'
import { useEffect, useState } from 'react';
import { UserLocationContext } from './App/Context/UserLocationContext';
const tokenCache = {
async getToken(key){
try{
return SecureStore.getItemAsync(key);
} catch (err) {
return null;
}
},
async saveToken(key, value){
try{
return SecureStore.setItemAsync(key, value);
} catch (err) {
return;
}
}
}
export default function App() {
const [location, setLocation] = useState(null);
const [errorMsg, setErrorMsg]= useState(null);
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);
})();
},[]);
let text = 'Waiting...'
if(errorMsg){
text = errorMsg;
} else if (location) {
text = JSON.stringify(location);
}
return (
<ClerkProvider
publishableKey={Api.CLERK_API_KEY}
tokenCache={tokenCache}
>
<UserLocationContext.Provider value={{location, setLocation}}>
<View style={styles.container}>
<SignedIn>
<NavigationContainer>
<TabNavigation/>
</NavigationContainer>
</SignedIn>
<SignedOut>
<LoginScreen/>
</SignedOut>
<StatusBar style="auto" />
</View>
</UserLocationContext.Provider>
</ClerkProvider>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
paddingTop: 25,
},
});