-
Notifications
You must be signed in to change notification settings - Fork 3
/
App.js
54 lines (47 loc) · 1.48 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
import Scan from './Scan';
import AsyncStorage from '@react-native-community/async-storage';
import CreateAccount from './CreateAccount';
import Preferences from './Preferences';
import Dietary from './Dietary';
import React, {Component} from 'react';
import {View, StyleSheet, StatusBar} from 'react-native';
import { createAppContainer, createSwitchNavigator } from 'react-navigation';
const RegistrationStack = createSwitchNavigator({
CreateAccount: CreateAccount,
Dietary: Dietary,
Preferences: Preferences,
Scan: Scan,
})
const RegistrationContainer = createAppContainer(RegistrationStack, {
initialRouteName: 'CreateAccount',
})
export default class App extends Component {
constructor(props) {
super(props);
this.state = {'logged_in' : false};
this.loadInitialScreen = this.loadInitialScreen.bind(this);
this.loadInitialScreen();
}
loadInitialScreen = async () => {
try{
const value = await AsyncStorage.getItem('@username')
if(value !== null) {
this.setState({'logged_in' : true})
} else {
this.setState({'logged_in' : false})
}
} catch (e) {
this.setState({'logged_in' : false})
}
}
render() {
return(
this.state.logged_in ? <View style = {styles.container}><StatusBar hidden /><Scan /></View> : <View style = {styles.container}><StatusBar hidden /><RegistrationContainer /></View>
);
}
}
const styles = StyleSheet.create({
container: {
...StyleSheet.absoluteFillObject,
}
})