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
TabNavigator Bottom reset stack when pressing selected tab #933
Comments
You read my mind, I've been working on that all day. Still not quite there. I'll post details. Essentially, you need to customize tabBarComponent and pass along a custom jumpToIndex to the props which will call the proper navigation. |
This is incomplete, it's what I have so far, passed as parameters to TabNavigator (2nd argument):
|
This looks like it works, I tried chaining the routes together, but kept getting an issue with it not finding the subroute in the context of the original (previous) tab. Putting them in sequence seems to work ( the subroute is in the right context), but I'm not sure about a race condition if they're asynchronous
|
@tmaly1980 That works pretty well for me. One problem though is that it resets every time you press the tab when I'm more looking for it only to reset if you are currently on the tab and select the same tab again. But this gets me pretty close, I'll see if I can figure out a way to have this work in my specific case and I'll post what I come up with. |
@RyanMitchellWilson , maybe add to the beginning something like:
It's probably not it, but you get the idea. Just console.log() the objects you have available to figure out what it should be. |
Here is what I ended up with:
My actions are a bit different here but essentially the same logic. I'm using the |
Notice today there is a slight race condition here. While the app is animating to a new tab, if you keep pressing that tab, it will push multiple instances of that tab screen onto the stack. |
Found the fix, just need to use
|
Thanks @RyanMitchellWilson! |
Closing in favour of #314 |
This isn't working for me, do I need to do anything more?
|
@itswaze try using return <TabBarBottom {...props} jumpToIndex={jumpToIndex}/> instead of return <TabView.TabBarBottom {...props} jumpToIndex={jumpToIndex}/> |
@tmaly1980 Please hava a look at this issue: #1755 , We need help. |
@tmaly1980 Hi. When I switched to a new tab, What I expected is that the stack of the tab is reseted. Can you help me with that? |
@tmaly1980, @RyanMitchellWilson great solution you found! Really great work! const MainScreenNavigator = TabNavigator({ |
@valinaga I found a dirty workaround for your usecase:
If you found a cleaner solution let me know :) |
@ou2s hi, yes I finally found something. It works on 1.0.0-beta.21.
|
@valinaga thanks for sharing. However I was not able to run your code successfully... I was able to make it work by doing this:
|
@ou2s depends on what you were looking for. I was trying to avoid reseting the stack if you already on a specific tab. Your version was doing the opposite, if that was what you were looking for. But when you go to a different tab, the corresponding stack won't reset until you press again. |
@valinaga This helped me huge and works great. If only we could remove the animation that happens when the nav of the tab is reset, as though it would appear that it was automatically at the index. Are you aware of anything? Thank you very much! |
@neilhamilton only solution I see is to disable the animation. Dispatching a navigation action will bring animation with it. |
@valinaga thank for your sharing. I changed your code a little bit that won't need to reset the stack, just go back.
|
@tuanmai I ended up also using back, but instead of looping through each index and going back, you can do one fluid back motion by specifying a key to go back from in the Back Action You could modify your code to find the key that is after the initial route and pass that to the back action:
|
Here's another example that resets the stack on each tab change, assuming you have stack navigators for each of your tab screens:
And then in your TabNavigator:
|
It seems that in |
I've been trying all the above solutions and was confused why they don't work. If you came here because jumpToIndex is not a function, please note for react navigator v2, the above is depreciated. You should use
Documentation here -> https://reactnavigation.org/docs/en/bottom-tab-navigator.html |
yeah this is also just implemented by default in react-navigation@^2 |
This is more of a question/feature request than an issue. Is it possible with the TabNavigator to press on the active tab and have it reset it's stack? Much like most iOS TabNavigators if you are a few screens deep on a tab and want to get back to the initial route you can usually just press the current tab again and it will reset your stack. Is this currently possible and if not could this be added to the TabNavigator?
As an example if you have an iOS device just open the app store, navigate to an app then press the active tab and you will see expected behavior.
The text was updated successfully, but these errors were encountered: