forked from IPourLIfe/LifeStrengths
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
77 lines (65 loc) · 1.75 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
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import PubSub from 'pubsub-js';
import React, {Component} from 'react';
import {View, Text} from 'react-native';
import RootTabs from './RootTabs';
import Login from './Login';
import * as Authentication from './lib/Authentication';
import {setTheme} from 'react-native-material-kit';
setTheme({
checkboxStyle: {
fillColor: '#FFB100',
borderOnColor: '#FFB100',
borderOffColor: '#FFB100',
rippleColor: `rgba(255, 177, 0,.15)`,
}
});
export default class App extends Component<{}> {
constructor(props) {
super(props);
this.state = {
hasLoggedIn: false,
profile: null
};
}
async componentDidMount() {
PubSub.subscribe(Authentication.LOGIN_SUCCESS, this.onLogin.bind(this));
PubSub.subscribe(Authentication.LOGOUT, this.onLogout.bind(this));
const profile = await Authentication.getProfile();
if (profile) {
this.onLogin();
}
}
async onLogin() {
const profile = await Authentication.getProfile();
this.setState(() => {
return {
profile,
hasLoggedIn: true
};
});
}
onLogout() {
this.setState(() => {
return {
profile: null,
hasLoggedIn: false
};
});
}
render() {
if (!this.state.hasLoggedIn) {
return <Login/>;
}
return (
<View style={{flex: 1}}>
<View style={{height: 20, width: '100%', backgroundColor: '#0097A7'}}/>
<RootTabs style={{flex: 1}}/>
</View>
);
}
}