-
-
Save yavorski/7aacbce5c871bbd38334a86a777e912b to your computer and use it in GitHub Desktop.
React Navigation: Parallel Navigators in React Native in a nutshell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import { AppRegistry } from 'react-native' | |
import setup from './setup' | |
AppRegistry.registerComponent('ReactNavigationTest', setup) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import { Text, View, Button } from 'react-native' | |
import { connect } from 'react-redux' | |
class Login extends React.Component { | |
render() { | |
return ( | |
<View> | |
<Text>Name, Password</Text> | |
<Button onPress={() => this.props.login()} title="Login" /> | |
<Button onPress={() => this.props.navigation.navigate('Register')} title="Register" /> | |
<Button onPress={() => this.props.navigation.navigate('PwdForgot')} title="Forget Password" /> | |
<Button onPress={() => this.props.navigation.navigate('Tour')} title="Tour" /> | |
</View> | |
) | |
} | |
} | |
function bindActions(dispatch) { | |
return { | |
login: () => dispatch({type:'LOGIN'}), | |
} | |
} | |
const mapStateToProps = state => ({}) | |
export default connect(mapStateToProps, bindActions)(Login) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { Text, View, Button } from 'react-native'; | |
import { connect } from 'react-redux' | |
class Overview extends React.Component { | |
static navigationOptions = { | |
drawer: () => ({ | |
label: 'My Overview', | |
}) | |
} | |
render() { | |
return ( | |
<View> | |
<Text>Something special</Text> | |
<Button onPress={() => this.props.navigation.navigate('DrawerOpen')} title="Menu" /> | |
<Button onPress={() => this.props.logout()} title="Logout" /> | |
</View> | |
); | |
} | |
} | |
function bindActions(dispatch) { | |
return { | |
logout: () => dispatch({type:'LOGOUT'}), | |
} | |
} | |
const mapStateToProps = state => ({}) | |
export default connect(mapStateToProps, bindActions)(Ueberblick) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react' | |
import { Provider } from 'react-redux' | |
import Navigator from './navigator' | |
import { createStore } from 'redux'; | |
function loginReducer(state = false, action) { | |
switch (action.type) { | |
case 'LOGIN': return true | |
case 'LOGOUT': return false | |
default: return state | |
} | |
} | |
const store = createStore(loginReducer, false); | |
function setup():React.Component { | |
class Root extends Component { | |
constructor() { | |
super() | |
this.state = { store } | |
} | |
render() { | |
return ( | |
<Provider store={this.state.store}> | |
<Navigator /> | |
</Provider> | |
) | |
} | |
} | |
return Root | |
} | |
export default setup |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment