This repository was archived by the owner on Feb 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathAppContainer.js
97 lines (82 loc) · 2.16 KB
/
AppContainer.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
import React from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import {
BackHandler,
StyleSheet
} from 'react-native';
import { Navigator } from 'react-native-deprecated-custom-components';
import Constants from './Utils/Constants';
import NavigationBar from './Navigation/NavigationBar';
import SceneContainer from './Navigation/SceneContainer';
import SettingUp from './Components/SettingUp';
import RouteMapper from './Navigation/RouteMapper';
import Routes from './Navigation/Routes';
const styles = StyleSheet.create({
navbar: {
backgroundColor: Constants.NAVBAR_BG,
flexDirection: 'row',
justifyContent: 'center',
}
});
class AppContainer extends React.Component {
static propTypes = {
isLoggedIn: PropTypes.bool.isRequired,
loaded: PropTypes.bool.isRequired,
};
constructor(props) {
super(props);
this.navigator;
}
componentWillMount() {
BackHandler.addEventListener('hardwareBackPress', () => {
if (this.navigator && this.navigator.getCurrentRoutes().length > 1) {
this.navigator.pop();
return true;
}
return false;
});
}
renderScene(route, navigator) {
this.navigator = navigator;
return (
<SceneContainer
title={route.title}
route={route}
navigator={navigator}
onBack={() => {
if (route.index > 0) {
navigator.pop();
}
}}
{...this.props}
/>
);
}
_getInitialRoute() {
if (this.props.isLoggedIn) {
return Routes.Notifications();
}
return Routes.LoginView();
}
render() {
if (!this.props.loaded) {
return <SettingUp />;
}
const initialRoute = this._getInitialRoute();
return (
<Navigator
initialRoute={initialRoute}
renderScene={this.renderScene.bind(this)}
navigationBar={<NavigationBar style={styles.navbar} routeMapper={RouteMapper} />}
/>
);
}
}
function mapStateToProps(state) {
return {
loaded: state.settings.get('loaded', false),
isLoggedIn: state.auth.get('token') !== null
};
}
export default connect(mapStateToProps, null)(AppContainer);