Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict'
- import { Router, Scene, Actions } from 'react-native-router-flux';
- //redux
- import { bindActionCreators } from 'redux';
- import { connect } from 'react-redux';
- import * as actionCreators from '../redux/actions-creators/actions';
- function mapStateToProps(state) {
- return {
- //...
- }
- }
- function mapDispatchToProps(dispatch) {
- return bindActionCreators(actionCreators, dispatch);
- }
- const scenes = Actions.create(
- <Scene
- key="root"
- onRight={() => {
- Actions.profile({});
- }}>
- <Scene
- key="home"
- component={Home}
- title="Home"
- initial={true} />
- <Scene
- key="login"
- component={LoginScreen}
- title="Login" />
- <Scene
- key="editProfile"
- component={EditProfile}
- title="EditProfile"
- onRight={() => {
- _logout(); // this is what i need to do.
- // dispatch is not available here, this gets compiled
- // before the app runs
- Actions.home({}); // works
- }} />
- </Scene>
- );
- //initialize function
- //FIX THIS, BREAKS PERFORMANCE
- var logoutAction = () => {
- };
- function _logout() {
- logoutAction();
- }
- class AppNavigator extends React.Component {
- constructor(props) {
- super(props);
- }
- componentDidMount() {
- logoutAction = this.props.logout; // this "hack" breaks performance
- BackAndroid.addEventListener('hardwareBackPress', function() {
- Actions.pop({});
- return true;
- });
- }
- render() {
- return <Router scenes={scenes} />
- }
- }
- const MainNavigator = connect(mapStateToProps, mapDispatchToProps)(AppNavigator);
- export default MainNavigator;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement