How do we call the specific type of action in react-navigation?

余生长醉 提交于 2019-12-01 12:06:41

问题


How to call action using NavigationAction???

Here if the user doesn't have a token, it goes back to the initial page. I want to reset(initialize) the MainTabNavigator.

componentWillReceiveProps(nextProps) {

    if ( nextProps.token == undefined || _.isNil(nextProps.token) ) {
      const backAction = NavigationActions.back({
        key: null
      })
      nextProps.navigation.dispatch(backAction);

Here is MainTabNavigator. I added route to reset everything when 'MyCompleteReset' is triggered.

export default TabNavigator({ ........ });

const navigator = MainTabNavigator;
const defaultGetStateForAction = navigator.router.getStateForAction

navigator.router.getStateForAction = (action, state) => {
  if (action.type === 'MyCompleteReset') {
     // For your custom action, reset it all
     return defaultGetStateForAction(NavigationActions.init())
  }
  // Handle all other actions with the default handler
  return defaultGetStateForAction(action, state)
}

How do we call the MyCopmleteReset action???

来源:https://stackoverflow.com/questions/48059045/how-do-we-call-the-specific-type-of-action-in-react-navigation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!