Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change tab programmatically #2368

Closed
onrige opened this issue Sep 11, 2017 · 5 comments
Closed

Change tab programmatically #2368

onrige opened this issue Sep 11, 2017 · 5 comments

Comments

@onrige
Copy link
Collaborator

onrige commented Sep 11, 2017

In previous version it was able to change current tab programmatically by Actions.refresh({ key: 'tab_1' }), but now it doesn't work. According to the docs I guess it doesn't work because of refresh action now refreshing only current scene. So may be someone know the solution?

UPD: Fine, I found the solution and it's was easy. If someone will have the same problem - just use default syntax to navigate between scenes (Actions.tab_1() for example).

@onrige onrige closed this as completed Sep 12, 2017
@fxhereng
Copy link

What's your tabs configuration?

Because If I do your solution, it recreates a new scene and stacked it up, and what I want to do is to jump to the existing tab (like when you click manually on the tab).

Thanks,

@onrige
Copy link
Collaborator Author

onrige commented Sep 28, 2017

@fxhereng I don't understand how does tab switch via my solution can create a new scenes stack :) Could you show me your scenes?
In my case it was something like this:

<Scene key="root">
    <Tabs key="tabs">
        <Scene key="tabs_tab1" />
        <Scene key="tabs_tab2" />
    </Tabs>
</Scene>

So if I will use Actions.tabs_tab2() somewhere - I will navigate to this tab.
Anyway if you have the problem with stacked navbar may be you will need to try wrap or hideNavBar property.

@fxhereng
Copy link

fxhereng commented Sep 28, 2017

Thanks for answering!

When doing Actions.tabs_tab2() it creates a new tab scene and add it to the tab's navigation stack. So I have, after it, two scenes tabs_tab2, and I don't want that kind of behavior.

I found out that the jumpoption is doing the same, it creates a new tab instead of jumping to the existing one.

The resetoption makes app crash.

Finally the solution I found was to do an Actions.replace('tabs_tab2'), it goes to the tab2 and doesn't add up scene to the stack navigation. It refreshes the scene as well, in my case I didn't care but it can be useful too.

Cheers,

EDIT: I have the version 4.0.0-beta21, maybe the behavior could have change in between

@onrige
Copy link
Collaborator Author

onrige commented Sep 28, 2017

Interesting. In my case it works good. Could you give an example with such problem? It's probably a bug because I don't understand how scene change functionality can do something like this. o_O

@fxhereng
Copy link

fxhereng commented Sep 28, 2017

Pretty similar with yours:

version: 4.0.0-beta21

<Scene key="root">
    <Tabs key="tabs" showLabel={true} swipeEnabled={false} lazy={true} backBehavior={'initialRoute'}>
        <Scene key="tabs_tab1" />
        <Scene key="tabs_tab2" />
    </Tabs>
</Scene>

Doing Actions.tabs_tab2() or Actions.jump('tabs_tab2') adds scene to the navigation stack and duplicates scene.

Actions.replace('tabs_tab2')avoids duplicating the scenes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants