vn-verdnaturachat/app/containers/Routes.js

59 lines
1.3 KiB
JavaScript
Raw Normal View History

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';
import { appInit } from '../actions';
import AuthRoutes from './routes/AuthRoutes';
import PublicRoutes from './routes/PublicRoutes';
import * as NavigationService from './routes/NavigationService';
@connect(
state => ({
login: state.login,
app: state.app,
background: state.app.background
}),
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
}
componentDidMount() {
if (this.props.app.ready) {
2018-03-02 21:31:44 +00:00
return SplashScreen.hide();
}
2018-03-02 21:31:44 +00:00
this.props.appInit();
}
2017-12-20 20:12:49 +00:00
componentWillReceiveProps(nextProps) {
if (nextProps.app.ready && this.props.app.ready !== nextProps.app.ready) {
2017-12-20 20:12:49 +00:00
SplashScreen.hide();
}
}
componentDidUpdate() {
NavigationService.setNavigator(this.navigator);
}
render() {
2017-12-20 20:12:49 +00:00
const { login } = this.props;
if (this.props.app.starting) {
return null;
}
if (!login.token || login.isRegistering) {
return (<PublicRoutes ref={nav => this.navigator = nav} />);
}
return (<AuthRoutes ref={nav => this.navigator = nav} />);
}
}