Advertisement
Guest User

Untitled

a guest
Jul 28th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. 'use strict'
  2. import { Router, Scene, Actions } from 'react-native-router-flux';
  3. //redux
  4. import { bindActionCreators } from 'redux';
  5. import { connect } from 'react-redux';
  6. import * as actionCreators from '../redux/actions-creators/actions';
  7. function mapStateToProps(state) {
  8. return {
  9. //...
  10. }
  11. }
  12. function mapDispatchToProps(dispatch) {
  13. return bindActionCreators(actionCreators, dispatch);
  14. }
  15. const scenes = Actions.create(
  16. <Scene
  17. key="root"
  18. onRight={() => {
  19. Actions.profile({});
  20. }}>
  21. <Scene
  22. key="home"
  23. component={Home}
  24. title="Home"
  25. initial={true} />
  26. <Scene
  27. key="login"
  28. component={LoginScreen}
  29. title="Login" />
  30. <Scene
  31. key="editProfile"
  32. component={EditProfile}
  33. title="EditProfile"
  34. onRight={() => {
  35. _logout(); // this is what i need to do.
  36. // dispatch is not available here, this gets compiled
  37. // before the app runs
  38. Actions.home({}); // works
  39. }} />
  40. </Scene>
  41. );
  42. //initialize function
  43. //FIX THIS, BREAKS PERFORMANCE
  44. var logoutAction = () => {
  45. };
  46. function _logout() {
  47. logoutAction();
  48. }
  49. class AppNavigator extends React.Component {
  50. constructor(props) {
  51. super(props);
  52. }
  53. componentDidMount() {
  54. logoutAction = this.props.logout; // this "hack" breaks performance
  55. BackAndroid.addEventListener('hardwareBackPress', function() {
  56. Actions.pop({});
  57. return true;
  58. });
  59. }
  60. render() {
  61. return <Router scenes={scenes} />
  62. }
  63. }
  64. const MainNavigator = connect(mapStateToProps, mapDispatchToProps)(AppNavigator);
  65. export default MainNavigator;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement