-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
152 lines (130 loc) · 3.52 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import React,{useState} from 'react';
import {useEffect} from 'react';
import { createAppContainer,addNavigationHelpers } from 'react-navigation';
import { createStackNavigator } from 'react-navigation-stack';
import { createBottomTabNavigator } from 'react-navigation-tabs';
import List_MapScreen from './List_MapScreen.js';
import HomeScreen from './HomeScreen.js';
import MapScreen from './MapScreen.js';
import ListScreen from './ListScreen.js';
import store from './chatStore.js';
import { connect } from 'react-redux';
import { Provider } from 'react-redux';
import * as Permissions from 'expo-permissions';
import * as Location from 'expo-location';
import {fetchPoints} from './setThunk.js';
import {
Alert,
AppRegistry,
} from 'react-native';
//no warning spam please
console.disableYellowBox = true;
//Redux connect tab screens
let ListContainer = connect(state => ({ points: state }))(ListScreen);
let MapContainer = connect(state => ({ points: state }))(MapScreen);
//routes/stacks..navigation in general (<a> is so much better)
const ListMapStack1 = createStackNavigator({
Map: {
screen: MapContainer,
navigationOptions: () => ({
header: null,
}),
},
List: {
screen: ListContainer,
navigationOptions: () => ({
header: null,
}),
},
}, {
initialRouteName: 'Map',
});
const ListMapStack2 = createStackNavigator({
Map: {
screen: MapContainer,
navigationOptions: () => ({
header: null,
}),
},
List: {
screen: ListContainer,
navigationOptions: () => ({
header: null,
}),
},
}, {
initialRouteName: 'List',
});
//stack navigator and appcontainer for the App component
const RootStack = createStackNavigator({
Home: {
screen: HomeScreen,
navigationOptions: () => ({
title: 'Welcome to POIS',
headerStyle: {
backgroundColor: '#80DEEA'
},
headerTitleStyle: {
color: '#E0F7FA'
},
}),
},
List_Map: {
screen: createBottomTabNavigator({
List: ListMapStack2,
Map: ListMapStack1,
}, {
initialRouteName: 'List',
tabBarOptions: {
activeTintColor: '#0097A7',
inactiveTintColor: '#E0F7FA',
labelStyle: {
fontSize: 17,
fontWeight: '500',
marginBottom: 10,
},
style: {
backgroundColor: '#80DEEA',
},
}
}),
navigationOptions: () => ({
title: 'List/Map',
headerStyle: {
backgroundColor: '#80DEEA'
},
headerTitleStyle: {
color: '#E0F7FA'
},
headerTintColor: '#E0F7FA',
}),
},
});
const AppContainer = createAppContainer(RootStack);
export default function App() {
const [userLoc,setUserLoc]=useState({})
useEffect(() => {
//when you open the app,ill get your location,if you allow it
this._getLocationAsync();
}, []);
useEffect(() => {
//after i get the location i fetch the points from the api using middleware,store
store.dispatch(fetchPoints());
}, [userLoc])
_getLocationAsync = async () => {
let {status} = await Permissions.askAsync(Permissions.LOCATION);
if (status !== 'granted') {
setUserLoc('false');
Alert.alert('Some services may not work correctly')
}
let location = await Location.getCurrentPositionAsync({});
setUserLoc( location.coords );
};
return (
<Provider store={store}>
<AppContainer screenProps={userLoc} />
</Provider>
);
}
//----------------------------------------------------------
AppRegistry.registerComponent("NCAPRNRedux", () => App);