Created
June 19, 2017 10:34
-
-
Save nazrdogan/7a587a509bdd17e7cd40e8cafc1dc73a to your computer and use it in GitHub Desktop.
React navigation route reducers
This file contains hidden or 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 { AppNavigator } from '../route'; | |
import { NavigationActions } from 'react-navigation'; | |
export function nav(state = null, action) { | |
let nextState; | |
switch (action.type) { | |
case 'Login': | |
nextState = AppNavigator.router.getStateForAction(NavigationActions.back(), state); | |
break; | |
case 'Logout': | |
/* | |
Key must be null: There is no route defined for. | |
*/ | |
nextState = AppNavigator.router.getStateForAction(NavigationActions.reset({ index: 0, key: null, actions: [NavigationActions.navigate({ routeName: 'Login' })] }), state); | |
break; | |
case 'GO_BACK': | |
nextState = AppNavigator.router.getStateForAction(NavigationActions.back(), state); | |
break; | |
case 'Drawer': | |
nextState = AppNavigator.router.getStateForAction(NavigationActions.reset({ index: 0, key: null, actions: [NavigationActions.navigate({ routeName: 'Drawer' })] }), state); | |
break; | |
case 'GO_TICKET_DETAIL': | |
nextState = AppNavigator.router.getStateForAction(NavigationActions.navigate({ routeName: 'TicketDetailScreen', params: { ticketID: action.payload } }), state); | |
break; | |
case 'OPEN_ASSIGN_MODAL': | |
nextState = AppNavigator.router.getStateForAction(NavigationActions.navigate({ routeName: 'AssignModal', params: { ticketID: action.payload } }), state); | |
break; | |
case 'OPEN_FORWARD_MODAL': | |
nextState = AppNavigator.router.getStateForAction(NavigationActions.navigate({ routeName: 'ForwardModal', params: { ticketID: action.payload } }), state); | |
break; | |
case 'OPEN_CHANGE_STATUS_MODAL': | |
nextState = AppNavigator.router.getStateForAction(NavigationActions.navigate({ routeName: 'ChangeStatusModal', params: { ticketID: action.payload } }), state); | |
break; | |
default: | |
nextState = AppNavigator.router.getStateForAction(action, state); | |
break; | |
} | |
// Simply return the original `state` if `nextState` is null or undefined. | |
return nextState || state; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment