|
| 1 | +import React, { Component } from 'react'; |
| 2 | +import PropTypes from 'prop-types'; |
| 3 | +import { View, StatusBar } from 'react-native'; |
| 4 | +import { connect } from 'react-redux'; |
| 5 | +import { Router, Scene } from 'react-native-router-flux'; |
| 6 | +import CardStackStyleInterpolator from 'react-navigation/src/views/CardStack/CardStackStyleInterpolator'; |
| 7 | + |
| 8 | +import LoginScreen from 'src/containers/LoginScreen'; |
| 9 | +import SignUpScreen from 'src/containers/SignUpScreen'; |
| 10 | +import HomeScreen from 'src/containers/HomeScreen'; |
| 11 | + |
| 12 | +import LoadingIndicator from 'src/components/LoadingIndicator'; |
| 13 | +import { isUserSignedIn } from 'src/state/actions/auth'; |
| 14 | + |
| 15 | +import { colors } from 'src/theme'; |
| 16 | +import styles from './styles/RootContainerStyles'; |
| 17 | + |
| 18 | + |
| 19 | +class RootContainer extends Component { |
| 20 | + componentWillMount() { |
| 21 | + this.props.isUserSignedIn(this.props.token); |
| 22 | + } |
| 23 | + |
| 24 | + render() { |
| 25 | + const { user, authenticated } = this.props; |
| 26 | + if (user && !authenticated) return <LoadingIndicator />; |
| 27 | + |
| 28 | + return ( |
| 29 | + <View style={styles.container}> |
| 30 | + <StatusBar translucent backgroundColor={colors.statusBarTranslucent} /> |
| 31 | + <Router> |
| 32 | + <Scene key="root" navigationBarStyle={styles.header} > |
| 33 | + <Scene |
| 34 | + key="auth" |
| 35 | + hideNavBar |
| 36 | + initial={!authenticated} |
| 37 | + transitionConfig={ |
| 38 | + () => ({ screenInterpolator: CardStackStyleInterpolator.forHorizontal }) |
| 39 | + } |
| 40 | + > |
| 41 | + <Scene key="login" title="Log In" component={LoginScreen} /> |
| 42 | + <Scene key="signup" title="Sign Up" component={SignUpScreen} /> |
| 43 | + </Scene> |
| 44 | + <Scene key="main" hideNavBar initial={authenticated}> |
| 45 | + <Scene key="home" initial title="Home" component={HomeScreen} /> |
| 46 | + </Scene> |
| 47 | + </Scene> |
| 48 | + </Router> |
| 49 | + </View> |
| 50 | + ); |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +RootContainer.propTypes = { |
| 55 | + user: PropTypes.object, |
| 56 | + token: PropTypes.string, |
| 57 | + authenticated: PropTypes.bool, |
| 58 | + isUserSignedIn: PropTypes.func, |
| 59 | +}; |
| 60 | + |
| 61 | +const mapStateToProps = (state) => { |
| 62 | + return { |
| 63 | + user: state.auth.user, |
| 64 | + token: state.auth.token, |
| 65 | + authenticated: state.auth.authenticated, |
| 66 | + }; |
| 67 | +}; |
| 68 | + |
| 69 | +export default connect(mapStateToProps, { isUserSignedIn })(RootContainer); |
0 commit comments