Navigation Experimental不会卸载组件

时间:2017-02-15 11:14:42

标签: react-native

我正在使用导航实验来反应本机应用程序的导航。当我在我的堆栈中推送一个重复的路由时,我正在检查它是否已经存在于我的堆栈中,如果它确实我使用NavigationUtils的replaceAt()用新路由替换该页面,但是当我这样做时我的组件没有卸载。

预期行为:当我替换已经存在于我的堆栈中的路由时,我的导航实验应该卸载当前路由并应该用新路由替换它并再次安装该组件。

我的导航减速机就是这个。

 const initialNavState = {
       index: 0,
       routes: [{key:'Second',title:'Second'}],

     }

 export default function navigationState(state = initialNavState, action) {
      console.log('current routes:',state);

      switch (action.type) {

        case NAV_PUSH:

           console.log('Page requested to open :',action.state.key)

          // trying to push the route where we already are, no need to change a thing
           if (state.routes[state.index].key === (action.state.key && action.state.key)) return state;

         // ensure no duplicate keys

           const index=NavigationStateUtils.indexOf(state, action.state.key);
           console.log('DoesPage existed already in stack (index value if exists and -1 it doesnt):',index);

           if(index > -1)
            {
               console.log('got index in stack, goin to replace it',index)
               return  NavigationStateUtils.replaceAt(state,action.state.key,action.state);
            }


          return NavigationStateUtils.push(state, action.state);

       case NAV_POP:
                    if (state.index === 0 || state.routes.length === 1) return state
                       return NavigationStateUtils.pop(state)

       case NAV_JUMP_TO_KEY:
                       return NavigationStateUtils.jumpTo(state, action.key)

       case NAV_JUMP_TO_INDEX:
                       return NavigationStateUtils.jumpToIndex(state, action.index)

       case NAV_RESET:
                       return {
        ...state,
        index: action.index,
        routes: action.routes
    }

          default:return state
   }
  }

请告诉我实施中出错的地方。

0 个答案:

没有答案