Skip to content
This repository was archived by the owner on Jan 8, 2021. It is now read-only.

Commit 30cadcd

Browse files
author
andela-akhenda
committed
feat(navigation): create the root container
1 parent b13309d commit 30cadcd

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-0
lines changed

src/containers/RootContainer.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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);
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { StyleSheet } from 'react-native';
2+
3+
import { colors } from 'src/theme';
4+
5+
const styles = StyleSheet.create({
6+
activityIndicator: {
7+
flex: 1,
8+
alignItems: 'center',
9+
justifyContent: 'center',
10+
},
11+
container: {
12+
flex: 1,
13+
},
14+
header: {
15+
backgroundColor: colors.secondary.main,
16+
},
17+
headerTitle: {
18+
color: colors.primary.text,
19+
},
20+
});
21+
22+
export default styles;

0 commit comments

Comments
 (0)