expo / ex-navigation

Route-centric navigation for React Native
997 stars 201 forks source link

BUG: Removed Navigator is set to currentNavigatorUID #400

Open nordved opened 7 years ago

nordved commented 7 years ago

I have a setting where in one stack there are two SlidingTabNavigation navigators.

Home --> Sliding1 --> Sliding2 --> Item When reaching the Item page, the routes of the stack navigator are all 3 scenes.

Navigating back from the Item scene, the item is popped from the stack navigator's routes and the current navigator is the stack.

Navigating back from Sliding2 removes the Sliding2 navigator from the navigators and then sets it as the current navigator.

This means that navigating back again gives an error finding index of undefined.

deletedsettocurrent

EDIT: stacktrace

Possible Unhandled Promise Rejection (id: 0):
Cannot read property 'index' of undefined TypeError:
Cannot read property 'index' of undefined at http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:91939:25 
at Object.dispatch (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:91996:46) 
at ExNavigationBackButtonManager._callee$ (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:74393:737) 
at tryCatch (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:28274:29) 
at Generator.invoke [as _invoke] (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:28548:12) 
at Generator.prototype.(anonymous function) [as next] (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:28307:13) 
at tryCatch (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:28274:29) 
at invoke (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:28350:12) 
at http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:28395:1 
at tryCallTwo (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:27914:1)
nordved commented 7 years ago

I found the place where the current navigator is set after removing a navigator. If I remove the navigator to be removed from the navigatorsToRestore array, then it (in my case) finds the right slidingTabNavigation to restore and set to current.

The console.log showed that before my edit the two navigatorUIDs were the same.

static [ActionTypes.REMOVE_NAVIGATOR](state, { navigatorUID }) {
    navigatorsToRestore = _.without(navigatorsToRestore, navigatorUID) // remove the removee
    const currentNavigatorUID = (navigatorsToRestore.length && navigatorsToRestore[navigatorsToRestore.length - 1]) ||
      state.navigators[navigatorUID].parentNavigatorUID;
    console.log(navigatorUID, currentNavigatorUID, navigatorsToRestore)
    navigatorsToRestore.pop();
    return {
      ...state,
      currentNavigatorUID,
      navigators: _.omit(state.navigators, navigatorUID),
    };
  }

This seems like a special case fix, it would be much nicer if slidingTabViews were restored when popping on the stack that they are on.

jordanmkoncz commented 7 years ago

I'm having a similar issue, although I'm not using SlidingTabNavigation, I'm using TabNavigation. See https://github.com/exponent/ex-navigation/issues/433. Quite possible that the cause of your issue is the same as mine.