/** |-------------------------------------------------- | Navigator Utils |-------------------------------------------------- */ import { NavigationActions } from 'react-navigation' const reset = (navigation, routeName, params, index, cb) => { const resetAction = NavigationActions.reset({ index: index || 0, actions: [NavigationActions.navigate({ routeName, params })], }) navigation.dispatch(resetAction) cb && cb() } const resets = (navigation, routeNames, index) => { let _action = { index: index, actions: [], } routeNames.forEach(routeName => _action.actions.push(NavigationActions.navigate({ routeName })) ) const resetAction = NavigationActions.reset(_action) navigation.dispatch(resetAction) } const back = (navigation, key) => { const backAction = NavigationActions.back({ key: key, }) navigation.dispatch(backAction) } const action = (navigation, routeName, params) => { const navigationAction = NavigationActions.navigate({ routeName: routeName, params: params || {}, action: NavigationActions.navigate({ routeName }), }) navigation.dispatch(navigationAction) } const setParams = (navigation, key, params) => { const setParamsAction = NavigationActions.setParams({ // these are the new params that will be merged into the existing route params params: params || {}, // The key of the route that should get the new params key: key, }) navigation.dispatch(setParamsAction) } export default { reset, back, action, setParams, resets, }