Closed yunussim closed 7 years ago
I don't know how React Native's built in Navigator actually works, but I think the Problem is that the activeTab of the BottomNavigation isn't stored in your state, thus – if the Navigator ever feels like he wants to re-mount the navigationBar – the BottomNavigation loses its activeTab.
I think that's the Problem. Not 100% sure. To solve it, use it like this:
Store the activeTab
inside your state, and pass it to the Bottom Navigation like this:
<BottomNavigation activeTab={this.state.activeTab}>
Update the state in your _handleTabChange
, but maybe you shouldn't use setState
in this case, since this would cause a rerender (and thus calling _handleTabChange
again and again and again...). You could simply use this.state.activeTab = newTabIndex
instead of setState.
This way your Navigator can re-mount the BottomNavigation without losing its state.
@yunussim Were you able to solve your problem?
@timomeh no I can't. It seems like every time I changed the tab twice, it called to change the tab to the first one automatically. I did not know what happened, but it does happen when I update the navigator, and it does not happen if I do something else that doesn't update my navigator.
so here's the flow
tab at 0 navigator push the first one newtabindex at 1 navigator push the second one newtabindex at 2 newtabindex at 0 navigator push the first one
is it memory problem ? Because if I use regular view as my bottomnavigation (view, and text only) it does not have any problem at all.
Thank you for your support though!
If you use a regular view, the onTabChange
event from the BottomNavigation doesn't get triggered. That's the Problem here. You'd have to figure out why onTabChange
get's called if it shouldn't.
The onTabChange
event get's fired in two cases:
activeTab
prop changesI would highly advise you to replace your Navigator. The old Navigation Module from React Native was deprecated many months ago. You would save time and write better code if you use something like react-navigation.
Since this is an Issue related to the Navigator/your Code, I can't help you and have to close this issue.
Hi, I'm practically new on react-native, and I got to see this great bottom navigation, however there's a little problem with the onTabChange behaviour
I put the BottomNavigation as the navigationBar in my Navigator.
I made 3 Tabs. When I change from the 1st to the 2nd tab, it is okay. The navigator shows the 2nd page without any problem. However when I change the tab from the 2nd to the 3rd, it will go back to the 1st tab right away. It is fine if I only use alert to show the newtab, but when I make update on the navigator, it will do the weird behaviour.
here's my code :