清除state.route使用react-navigation删除页面转换

时间:2018-01-05 07:27:40

标签: reactjs react-native redux react-redux react-navigation

出于性能原因,我希望清除state.routes并仅保留currentRouteprevRoutes。我把索引总是放在1上。

但我的问题是幻灯片动画被删除了:(

我的代码:

const navReducer = (state, action) => {
  const nextState = AppNavigator.router.getStateForAction(action, state);

  switch (action.type) {
    case 'Navigation/NAVIGATE':
      const newState = nextState || state;
      const routes = newState.routes;
      const routesCount = routes.length;

      if (routesCount > 2) {
        const newRoutes = routes.slice(-2);
        return { ...newState, ...{ routes: newRoutes, index: 1 } };
      }
      break;
    case 'Navigation/BACK':
      console.log('Push back');
      break;
    default:
      break;
  }

  return nextState || state;
};

任何人都知道我是否可以清除state.routes,但保存默认导航动画?

谢谢!

0 个答案:

没有答案