-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.android.js
83 lines (78 loc) · 2.25 KB
/
index.android.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
/**
* Sample React Native Login App
* Author:Saurabh Mhatre
*
*/
import React, { Component } from 'react';
import {
AppRegistry,
ActivityIndicator,
AsyncStorage,
StyleSheet,
Navigator,
Text,
View,
ToolbarAndroid
} from 'react-native';
//Pages
import Signup from './src/pages/Signup';
import Login from './src/pages/Login';
import Account from './src/pages/Main';
import styles from './src/styles/mainstyle.js'
import * as firebase from 'firebase'; // Initialize Firebase
var fireBaseconfig = {
//your credentials here
};
// firebase.initializeApp(fireBaseconfig);
const firebaseApp = firebase.initializeApp(fireBaseconfig);
export class todo extends Component {
constructor(props){
super(props);
this.state={
openingPage: null
}
}
componentWillMount(){
//Check if userData is stored on device else open Login
AsyncStorage.getItem('userData').then((user_data_json) => {
let user_data = JSON.parse(user_data_json);
let openingPage = {openingPage: Login};
if(user_data != null){
this.setState({openingPage:Account});
}else{
this.setState(openingPage);
}
});
}
render() {
if (this.state.openingPage) {
return (
// Take the user to whatever page we set the state to.
// We will use a transition where the new page will slide in from the Left.
<Navigator
initialRoute={{component: this.state.openingPage}}
configureScene={() => {
return Navigator.SceneConfigs.HorizontalSwipeJumpFromLeft;
}}
renderScene={(route, navigator) => {
if(route.component){
// Pass the navigator the the page so it can navigate as well.
// Pass firebaseApp so it can make calls to firebase.
return React.createElement(route.component, { navigator, firebaseApp});
}
}} />
);
} else {
return (
// Our default loading view while waiting to hear back from firebase
<View style={styles.container}>
<ToolbarAndroid title="Login" />
<View style={styles.body}>
<ActivityIndicator size="large" />
</View>
</View>
);
}
}
}
AppRegistry.registerComponent('todo', () => todo);