-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
62 lines (55 loc) · 1.72 KB
/
App.js
File metadata and controls
62 lines (55 loc) · 1.72 KB
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
import React, { useEffect } from 'react';
import * as Location from 'expo-location';
import {Provider as StoreProvider} from 'react-redux';
import { DefaultTheme, Provider as PaperProvider } from 'react-native-paper';
import AppNav from './src/components/AppNav';
import { loadCurrentLocation, setMapRegion } from './src/redux/actions';
import store from './src/redux/store/configureStore';
const theme = {
...DefaultTheme,
roundness: 2,
colors: {
...DefaultTheme.colors,
primary: '#000000',
// accent: '#ffffff',
},
};
const defaultLocation = {
latitude: 37,
longitude: -122,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421
}
export default function App() {
useEffect(() => {
(async () => {
let { status } = await Location.requestForegroundPermissionsAsync()
if (status !== 'granted') {
store.dispatch(loadCurrentLocation(defaultLocation));
store.dispatch(setMapRegion(defaultLocation.latitude, defaultLocation.longitude));
}
await Location.getCurrentPositionAsync({})
.then((location)=> {
store.dispatch(loadCurrentLocation({
latitude: location.coords.latitude,
longitude: location.coords.longitude,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421
}));
store.dispatch(setMapRegion(location.coords.latitude, location.coords.longitude));
}
)
.catch((error)=> {
store.dispatch(loadCurrentLocation(defaultLocation));
store.dispatch(setMapRegion(defaultLocation.latitude, defaultLocation.longitude));
});
})();
});
return (
<StoreProvider store={store}>
<PaperProvider theme={theme}>
<AppNav />
</PaperProvider>
</StoreProvider>
);
}