2017-09-21 17:08:00 +00:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import React from 'react';
|
|
|
|
import { bindActionCreators } from 'redux';
|
|
|
|
import { connect } from 'react-redux';
|
2017-12-20 20:12:49 +00:00
|
|
|
import SplashScreen from 'react-native-splash-screen';
|
2017-09-21 17:08:00 +00:00
|
|
|
import { appInit } from '../actions';
|
|
|
|
|
|
|
|
import AuthRoutes from './routes/AuthRoutes';
|
|
|
|
import PublicRoutes from './routes/PublicRoutes';
|
2017-11-13 13:35:01 +00:00
|
|
|
import * as NavigationService from './routes/NavigationService';
|
2017-09-21 17:08:00 +00:00
|
|
|
|
|
|
|
@connect(
|
|
|
|
state => ({
|
|
|
|
login: state.login,
|
2017-12-01 15:06:56 +00:00
|
|
|
app: state.app,
|
|
|
|
background: state.app.background
|
2017-09-21 17:08:00 +00:00
|
|
|
}),
|
|
|
|
dispatch => bindActionCreators({
|
|
|
|
appInit
|
|
|
|
}, dispatch)
|
|
|
|
)
|
|
|
|
export default class Routes extends React.Component {
|
|
|
|
static propTypes = {
|
|
|
|
login: PropTypes.object.isRequired,
|
|
|
|
app: PropTypes.object.isRequired,
|
|
|
|
appInit: PropTypes.func.isRequired
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillMount() {
|
2017-12-01 15:06:56 +00:00
|
|
|
return !this.props.app.ready && this.props.appInit();
|
2017-09-21 17:08:00 +00:00
|
|
|
}
|
2017-11-13 13:35:01 +00:00
|
|
|
|
2017-12-21 19:17:41 +00:00
|
|
|
componentDidMount() {
|
|
|
|
if (!this.props.app.starting) {
|
|
|
|
SplashScreen.hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-20 20:12:49 +00:00
|
|
|
componentWillReceiveProps(nextProps) {
|
|
|
|
if (!nextProps.app.starting && this.props.app.starting !== nextProps.app.starting) {
|
|
|
|
SplashScreen.hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-13 13:35:01 +00:00
|
|
|
componentDidUpdate() {
|
|
|
|
NavigationService.setNavigator(this.navigator);
|
|
|
|
}
|
2017-11-13 13:53:45 +00:00
|
|
|
|
2017-09-21 17:08:00 +00:00
|
|
|
render() {
|
2017-12-20 20:12:49 +00:00
|
|
|
const { login } = this.props;
|
2017-09-21 17:08:00 +00:00
|
|
|
|
2017-12-20 19:20:06 +00:00
|
|
|
if (!login.token || login.isRegistering) {
|
|
|
|
return (<PublicRoutes ref={nav => this.navigator = nav} />);
|
2017-09-21 17:08:00 +00:00
|
|
|
}
|
2017-12-20 19:20:06 +00:00
|
|
|
return (<AuthRoutes ref={nav => this.navigator = nav} />);
|
2017-09-21 17:08:00 +00:00
|
|
|
}
|
|
|
|
}
|