-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
161 lines (153 loc) · 4.54 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
/**
Unicorn apps for fellow unicorn lovers to come together and watch happy unicorns dance to their fav song.
*/
import React, { Component } from 'react';
import { ActivityIndicator,AsyncStorage,Text,View,YellowBox } from 'react-native';
import { createStackNavigator } from 'react-navigation';
import Icon from 'react-native-vector-icons/FontAwesome';
import Welcome from './src/components/Welcome';
import Login from './src/components/Login';
import Register from './src/components/Register';
// ignoring these for now
YellowBox.ignoreWarnings(['Class RCTCxxModule','Warning: isMounted(...)','Module RCTImageLoader', 'Module RCTVideoManager']);
type Props = {};
export default class App extends Component<Props> {
constructor(props) {
super(props);
this.state = {
registerChecked: false,
registered: false,
nameChecked: false,
name: '',
}
this.checkRegistration();
}
render() { // spinner if still loading, otherwise route to Nav
//return <Nav screenProps={{name: this.state.name}} />;
var appReady = this.state.registerChecked && this.state.nameChecked;
if (!appReady) return (
<View style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}>
<ActivityIndicator size="large" color="#ef8bc9" />
</View>
);
return this.getRoute();
}
async checkRegistration() {
// uncomment line below to wipe storage for testing
// AsyncStorage.clear();
await AsyncStorage.getItem('registered')
.then(val => {
if (val) this.setState({registered: val, registerChecked: true});
else this.setState({registerChecked: true});
})
.catch(e => {
Alert.alert('Start Error', 'Hmm something went wrong initializing the app.');
})
.done();
await AsyncStorage.getItem('name')
.then(val => {
if (val) this.setState({name: val, nameChecked: true});
else this.setState({nameChecked: true});
})
.catch(e => {
Alert.alert('Start Error', 'Hmm something went wrong initializing the app.');
})
.done();
}
getRoute() {
if (this.state.name) { // name implies registration completed
return route = <MainNav screenProps={{name: this.state.name}} />;
}
return <Nav screenProps={{name: this.state.name}} />;
}
}
// navigation objects where order matters
// nested nav objects must be initialized before referencing
const MainNav = createStackNavigator({
Welcome: { screen: Welcome,
navigationOptions: ({ navigation }) => ({
title: 'Welcome',
headerLeft: null,
headerStyle: { backgroundColor: '#948bef' },
headerTintColor: '#fff',
headerTitleStyle: {
fontSize: 20,
fontWeight: 'bold',
fontFamily: 'Avenir',
color: '#fff',
},
}),
},
Register: { screen: Register,
navigationOptions: ({ navigation }) => ({
title: 'Register',
headerLeft: null,
headerStyle: { backgroundColor: '#948bef' },
headerTintColor: '#fff',
headerTitleStyle: {
fontSize: 20,
fontWeight: 'bold',
fontFamily: 'Avenir',
color: '#fff',
},
}),
},
Login: { screen: Login,
navigationOptions: ({ navigation }) => ({
title: 'Login',
headerLeft: null,
headerStyle: { backgroundColor: '#948bef' },
headerTintColor: '#fff',
headerTitleStyle: {
fontSize: 20,
fontWeight: 'bold',
fontFamily: 'Avenir',
color: '#fff',
},
}),
},
});
const Nav = createStackNavigator({
Register: { screen: Register,
navigationOptions: ({ navigation }) => ({
title: 'Register',
headerLeft: null,
headerStyle: { backgroundColor: '#948bef' },
headerTintColor: '#fff',
headerTitleStyle: {
fontSize: 20,
fontWeight: 'bold',
fontFamily: 'Avenir',
color: '#fff',
},
}),
},
Login: { screen: Login,
navigationOptions: ({ navigation }) => ({
title: 'Login',
headerLeft: null,
headerStyle: { backgroundColor: '#948bef' },
headerTintColor: '#fff',
headerTitleStyle: {
fontSize: 20,
fontWeight: 'bold',
fontFamily: 'Avenir',
color: '#fff',
},
}),
},
Welcome: { screen: Welcome,
navigationOptions: ({ navigation }) => ({
title: 'Main',
headerLeft: null,
headerStyle: { backgroundColor: '#948bef' },
headerTintColor: '#fff',
headerTitleStyle: {
fontSize: 20,
fontWeight: 'bold',
fontFamily: 'Avenir',
color: '#fff',
},
}),
},
});