Advertisement
Guest User

Untitled

a guest
Aug 24th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. const {
  2. StateUtils: NavigationStateUtils
  3. } = NavigationExperimental
  4.  
  5. const initialState = {
  6. index: 0,
  7. key: 'root',
  8. routes: [{
  9. key: 'login',
  10. title: 'Login',
  11. component: Login
  12. }]
  13. }
  14.  
  15. function navigationState (state = initialState, action) {
  16. switch(action.type) {
  17.  
  18. case PUSH_ROUTE:
  19. if (state.routes[state.index].key === (action.route && action.route.key)) return state
  20. return NavigationStateUtils.push(state, action.route)
  21.  
  22. case POP_ROUTE:
  23. if (state.index === 0 || state.routes.length === 1) return state
  24. return NavigationStateUtils.pop(state)
  25.  
  26. default:
  27. return state
  28. }
  29. }
  30.  
  31. handleBackAction() {
  32. if (this.props.navigation.index === 0) {
  33. return false
  34. }
  35. this.props.popRoute()
  36. return true
  37. }
  38.  
  39. _handleNavigate(action) {
  40. switch (action && action.type) {
  41. case 'push':
  42. this.props.pushRoute(action.route)
  43. return true
  44. case 'back':
  45. case 'pop':
  46. return this._handleBackAction()
  47. default:
  48. return false
  49. }
  50. }
  51.  
  52. _navigate(route){
  53. this.props._handleNavigate(route)
  54. }
  55.  
  56. render(){
  57. const route = {
  58. type: 'push',
  59. route: {
  60. key: this.props.navKey,
  61. title: this.props.pageName,
  62. component: this.props.componentName
  63. }
  64. }
  65.  
  66. return(
  67. <TouchableHighlight onPress={() => this._navigate(route)}>
  68. <Text style={styles}>{pr.pageName}</Text>
  69. </TouchableHighlight>
  70. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement