-
-
Save ronnyhartenstein/1ef30c90f530f99430969925198d6970 to your computer and use it in GitHub Desktop.
import React from 'react' | |
import { AppRegistry } from 'react-native' | |
import setup from './setup' | |
AppRegistry.registerComponent('ReactNavigationTest', setup) |
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) |
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) |
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 |
HI @ronnyhartenstein this is great, I'm trying to use this gist for a sample app I'm building but I can't get it to work. I'm getting this error
ExceptionsManager.js:63 setup(...): A valid React element (or null) must be returned. You may have returned undefined, an array or some other invalid object.
so far I'm using your code, and then I'll try to make my modifications.
Do you know what's going on or what am I missing here?
@ronnyhartenstein This is excellent. Clean, straightforward and flexible. I'm wondering why it isnt more widely accepted as a suitable solution? Have you found any shortcomings i.e. deep linking, navigating based on push notification payloads (after verifying they are logged in), etc? Thanks again!
how would you logout from the MainNavigator and redirect to the Login screen found in the OnboardingNavigator using redux?
Sometimes I am getting weird errors when transitioning between screens this way. Had to add setTimeout which is beyond hackish
Example for a parallel React Navigation onboarding
StackNavigation
next to a main appDrawerNavigation
.Targets these issues: