-
Notifications
You must be signed in to change notification settings - Fork 8
/
App.js
221 lines (197 loc) · 6.6 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
import React, { Component } from 'react';
import { Platform, ActivityIndicator, StyleSheet, StatusBar } from 'react-native';
import { Container, Item } from 'native-base';
import { StackActions, NavigationActions } from 'react-navigation';
import {createStackNavigator, createAppContainer} from 'react-navigation';
import { fromLeft, fromTop, fromRight } from 'react-navigation-transitions';
import * as Animatable from 'react-native-animatable';
import { Col, Grid } from 'react-native-easy-grid';
import Expo, { Location, Permissions } from 'expo';
import {authInfo} from './App.js'
import { Auth } from 'aws-amplify';
import Amplify from '@aws-amplify/core'
import awsmobile from './aws-exports'
Amplify.configure(awsmobile)
import createStore from 'pure-store';
import ConfirmCode from './src/components/confirmcode/confirmcode.component';
import ForgotPassword from './src/components/forgotpassword/forgotpassword.component';
import SignUp from './src/components/signup/signup.component';
import ChangePassword from './src/components/changepassword/changepassword.component';
// import TestMain from './testmain.component';
import SignIn from './src/components/signin/signin.component';
import MapNav from './router';
AnimatedLoading = Animatable.createAnimatableComponent(ActivityIndicator);
AnimatedItem = Animatable.createAnimatableComponent(Item);
export const store = createStore({
initialMarkers: [],
markers: [],
currentUser: '',
currentUserId: '',
myMarkers: undefined,
region: {
latitude: 36.811998,
longitude: -119.748398,
latitudeDelta: 0.0422,
longitudeDelta: 0.0221,
},
pinLink: { // Used for map-link: opening pins in uber, lyft, waze, etc..
name: undefined,
latitude: undefined,
longitude: undefined
},
pinInfo: {
userId: '',
eventName: '',
eventType: 'General',
description: '',
startTime: '',
endTime: '',
latitude: undefined,
longitude: undefined
}
});
class Loading extends Component {
constructor(props){
super(props);
this.state = {
loading: true,
};
}
static navigationOptions = {
header: null
};
_getLocationAsync = async () => {
let { status } = await Permissions.askAsync(Permissions.LOCATION);
if (status !== 'granted') {
this.setState({
errorMessage: 'Permission to access location was denied',
});
}
let location = await Location.getCurrentPositionAsync({});
// console.log('User location: ', location.coords);
store.update({
userLocation: location.coords,
region: {
...store.state.region,
latitude: location.coords.latitude,
longitude: location.coords.longitude,
}
});
};
// Needed for Native-Base Buttons
async componentDidMount() {
await Expo.Font.loadAsync({
Roboto: require("native-base/Fonts/Roboto.ttf"),
Roboto_medium: require("native-base/Fonts/Roboto_medium.ttf"),
Ionicons: require("@expo/vector-icons/fonts/Ionicons.ttf")
});
const session = Auth.currentAuthenticatedUser({
bypassCache: true // Optional, By default is false. If set to true, this call will send a request to Cognito to get the latest user data
}).then(async (user) => {
console.log('User is logged in:', user.username);
this._getLocationAsync();
await Auth.currentCredentials().then((response) => {
console.log(response.data.IdentityId);
store.update({
currentUserId: response.data.IdentityId,
currentUser: user.username
});
});
setTimeout(() => {this.refs.title.bounceOutLeft();}, 500);
setTimeout(() => {this.refs.loading.bounceOutLeft();}, 500);
setTimeout(() => {
const resetAction = StackActions.reset({
index: 0,
actions: [
NavigationActions.navigate({ routeName: 'Map' }),
],
});
this.props.navigation.dispatch(resetAction);
}, 1000);
})
.catch((err) => {
console.log('Error:',err);
setTimeout(() => {this.refs.title.bounceOutRight();}, 500);
setTimeout(() => {this.refs.loading.bounceOutRight();}, 500);
setTimeout(() => {this.props.navigation.navigate('SignIn');}, 1000);
});
this.setState({ loading: false });
}
render() {
if (this.state.loading) {
return <Expo.AppLoading />;
}
return (
<Container>
<StatusBar hidden/>
<Grid>
<Col size={10.5} style={{ backgroundColor: '#03a9f4', justifyContent: 'center', alignItems: 'center'}}>
<Animatable.Text ref="title" style={styles.title}>Loading</Animatable.Text>
<AnimatedLoading ref="loading" style={{bottom: 50, backgroundColor: '#03a9f4'}} size="large" color="white"/>
</Col>
</Grid>
</Container>
);
}
}
const handleCustomTransition = ({ scenes }) => {
const prevScene = scenes[scenes.length - 2];
const nextScene = scenes[scenes.length - 1];
// Custom transitions go there
if (prevScene
&& prevScene.route.routeName === 'SignUp'
&& nextScene.route.routeName === 'ConfirmCode') {
return fromTop();
} else if (prevScene
&& prevScene.route.routeName === 'SignIn'
&& nextScene.route.routeName === 'ForgotPassword') {
return fromTop();
} else if (prevScene
&& prevScene.route.routeName === 'ForgotPassword'
&& nextScene.route.routeName === 'ChangePassword') {
return fromRight();
} else if (prevScene
&& prevScene.route.routeName === 'Loading'
&& nextScene.route.routeName === 'SignIn') {
return fromLeft();
} else if (prevScene
&& prevScene.route.routeName === 'Loading'
&& nextScene.route.routeName === 'Map') {
return fromRight();
} else if (prevScene
&& prevScene.route.routeName === 'SignIn'
&& nextScene.route.routeName === 'Map') {
return fromRight();
}
return fromLeft();
};
const MainNavigator = createStackNavigator(
{
Loading: {screen: Loading},
// Test: {screen: TestMain},
SignIn: {screen: SignIn},
SignUp: {screen: SignUp},
ConfirmCode: {screen: ConfirmCode},
ForgotPassword: {screen: ForgotPassword},
ChangePassword: {screen: ChangePassword},
Map: MapNav,
},
{
initialRoute: 'Loading',
transitionConfig: (nav) => handleCustomTransition(nav),
navigationOptions: {
headerVisible: false,
}
},
);
const AppContainer = createAppContainer(MainNavigator);
export default AppContainer;
const styles = StyleSheet.create({
title: {
color: 'white',
fontSize: 60,
fontFamily: Platform.OS === 'ios' ? 'HelveticaNeue-Light' : 'sans-serif-thin',
fontWeight: Platform.OS === 'ios' ? "100" : 'normal',
bottom: 70
},
});