expo / ex-navigation

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

jumpToTab with NavigationActions #377

Closed eduedix closed 7 years ago

eduedix commented 7 years ago

I want to call jumpToTab action in a redux middleware. I would be grateful if you gave me a hand to resolve this. My TabNavigation is root and i want to jump to Tab tab1. I have tried this without success: store.dispatch(NavigationActions.jumpToTab('root', 'tab1'))

Any idea on how to jumpToTab using NavigationActions?

mantas-janulionis commented 7 years ago

+1. I have the same issue. I noticed that ActionTypes.JUMP_TO_TAB is dispatched, however ActionTypes.SET_CURRENT_NAVIGATOR is not

In some cases I did a workaround with

this.props.navigation.performAction(({ tabs }) => {
      tabs('root').jumpToTab('tab1');
    });

But If I want to call this method from anywhere outside of react component, it doesn't seem to be working. To me, it looks a like a bug

eduedix commented 7 years ago

@mantas-janulionis this worked: store.dispatch(NavigationActions.jumpToTab('root', {key: 'tab1'}))

i think a documentation update is necessary.

mikemurray commented 7 years ago

@eduedix Solved my issue as well! Seems this PR has the updates needed for the documentation: https://github.com/exponent/ex-navigation/pull/359

eduedix commented 7 years ago

@mikemurray thanks for the link 👍

mypark commented 7 years ago

I'm getting a Navigator does not exist error even if I'm trying to call it from a component. Is there an example implementation of tabs('root').jumpToTab('tab1');

this.props.navigation.performAction(({ tabs }) => {
      tabs('root').jumpToTab('tab1');
    });
eduedix commented 7 years ago

@mypark Is the navigatorUID called root in the element TabNavigation ?

mypark commented 7 years ago

That's was the issue thanks. I was only setting Id