-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
108 lines (83 loc) · 2.7 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import React, { useEffect, useState} from 'react';
import { Text, View, StyleSheet, ActivityIndicator } from 'react-native';
import { NavigationContainer, DefaultTheme } from '@react-navigation/native';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import HomeScreen from './Screens/HomeScreen';
import MapScreen from './Screens/MapScreen';
import { MaterialCommunityIcons } from '@expo/vector-icons';
import { MaterialIcons } from '@expo/vector-icons';
import * as Location from 'expo-location';
const styles = StyleSheet.create({
error: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
}
})
const MyTheme = {
...DefaultTheme,
dark: true,
colors: {
...DefaultTheme.colors,
//primary: '#2d545e',
background: "#393f4d",
card: '#1d1e22',
text: '#dcdcdc'
}
}
const Tab = createBottomTabNavigator();
export default function App() {
const [errorMessage, setErrorMessage] = useState('')
const [coordinates,setCoordinates] = useState(null)
const getPermisions = async ()=> {
let {status} = await Location.requestPermissionsAsync();
if(status !== 'granted'){
setErrorMessage('Permision to access location was denied');
return
}
let location = await Location.getCurrentPositionAsync({});
setCoordinates({lat: location.coords.latitude,lon: location.coords.longitude})
}
useEffect(()=>{
getPermisions()
},[])
if(coordinates){
return (
<NavigationContainer theme={MyTheme}>
<Tab.Navigator screenOptions={({route})=>({
tabBarIcon: ({focused, color,size}) => {
let iconName;
if(route.name === 'Home'){
iconName = 'weather-partly-snowy-rainy';
} else if(route.name === 'Map') {
iconName = 'map-marker-check';
}
return <MaterialCommunityIcons name={iconName} size={size} color={color} />
}
})}
tabBarOptions={{
activeTintColor: 'tomato',
inactiveTintColor: 'gray',
}} >
<Tab.Screen name="Home" children={()=> <HomeScreen coordinates={coordinates} setCoordinates={setCoordinates} />} />
<Tab.Screen name="Map" children={()=> <MapScreen lat={coordinates.lat} lon={coordinates.lon} />} />
</Tab.Navigator>
</NavigationContainer>
)
}
else if(errorMessage) {
return <View style={styles.error}>
<Text>
{errorMessage}
</Text>
<MaterialIcons name="error-outline" size={100} color="red" />
</View>
}
return (<View>
<ActivityIndicator />
</View>)
}
/*export default function App() {
return (<Navigation />)
}
*/