Skip to content

Instantly share code, notes, and snippets.

@sirdlx
Created March 19, 2017 22:53
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sirdlx/039cf28a7ea49c4b691f69a6ab380997 to your computer and use it in GitHub Desktop.
Save sirdlx/039cf28a7ea49c4b691f69a6ab380997 to your computer and use it in GitHub Desktop.
Alternative to react-navigation's replace action
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View
} from 'react-native';
import setup from './src/screens/setup'
AppRegistry.registerComponent('splash_app', () => setup);
import {Router, Scene, StackNavigator, TabNavigator, CardStack} from 'react-navigation';
import Login from './loginScreen'
import Home from './homeScreen'
import Splash from './splashScreen'
import Settings from './settingsScreen'
import Profile from './profileScreen'
const MainNavigator = TabNavigator({
Home: {
screen: Home,
path: 'home'
},
Profile: {
screen: Profile,
path: 'profile'
}
}, {
initialRouteName: 'Home',
tabBarPosition: 'bottom',
tabBarOptions: {
showLabel: false,
showIcon: true,
activeTintColor: 'red',
labelStyle: {
fontWeight: 'bold',
color: 'black'
},
style: {
backgroundColor: 'white'
},
indicatorStyle: {
backgroundColor: 'red'
}
}
});
export default MainNavigator
import {StackNavigator} from 'react-navigation'
// import Register from './screenRegister'
import Login from './loginScreen'
// import PwdForget from './screenPwdforget'
// import Tour from './screenTour'
const OnboardingNavigator = StackNavigator({
Login: {
screen: Login
},
// Not implimented yet! :(
// Register: {
// screen: Register
// },
// PwdForgot: {
// screen: PwdForgot
// },
// Tour: {
// screen: Tour
// }
}, {initialRouteName: 'Login'})
export default OnboardingNavigator
import React, {Component} from 'react'
import {connect} from 'react-redux'
import {bindActionCreators} from 'redux'
import OnboardingNavigator from './navigationOnboarding'
import MainNavigator from './navigationMain'
import Splash from './splashScreen'
import * as actions from '../actions'
class Navigator extends Component {
constructor(props) {
super(props)
// console.log(props);
if (props.user.loginState === 'LOGGEDIN_CHECKING') {
this.props.actions.startListeningToAuth();
}
}
render() {
switch (this.props.user.loginState) {
case 'LOGGEDIN':
return (<MainNavigator/>);
break;
case 'LOGGEDOUT':
return (<OnboardingNavigator/>);
break;
default:
return (
<Splash></Splash>
);
}
}
}
function mapDispatchToProps(dispatch) {
return {
actions: bindActionCreators(actions, dispatch)
}
}
const mapStateToProps = state => (state)
export default connect(mapStateToProps, mapDispatchToProps)(Navigator)
import React, {Component} from 'react'
import {Provider} from 'react-redux'
import Navigator from './navigator'
import {
createStore,
applyMiddleware,
combineReducers
} from 'redux'
import thunk from 'redux-thunk'
import rootReducer from '../reducers'
const store = createStore(rootReducer, undefined, applyMiddleware(thunk))
class setup extends Component {
render() {
return (
<Provider store={store}>
<Navigator/>
</Provider>
)
}
}
export default setup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment