Use BottomNavigationView instead of top tabs for BottomTabs on Android
See original GitHub issueCurrently bottom tabs are hacked on using a TabLayout
instead of using the Material BottomNavigationView
. There are a few important differences between the two and I will try to demonstrate with the twitter example app and the real work Twitter app on Android.
On Android bottom tab bars should follow the material design spec. They do not use a swipeable fragment pager, but rely on the button to transition between tabs. This may seem small but it shows when you compare the current way this library works with the Official Twitter App:
As you can see they have top tabs embedded within the fragments showing on the bottom. This is how a ton of android apps work.
Furthermore, the sizing is wrong and there is currently no way to get rid of the indicator bar on the tab view in this library.
So in total, the height is different than what a native bottom tab bar should be, there shouldnt be a line indicator by default on bottom tabs and the child views should not be swipeable to allow for their children to have top tab views.
I am willing to work on this, but since its a pretty big change I assume you will have some preferences in how it is implemented. Let me know any feedback you have!
Issue Analytics
- State:
- Created 4 years ago
- Comments:28 (28 by maintainers)
Great! I’ve created #341 that implements this basic spec. If you run up the Twitter example and set
swipeable
to false on theTabBar
component then it will render aBottomNavigationView
.I’ve listed all the tasks I can think of in the PR description. Let me know if I’ve missed anything. If you’re interested in working on any of them then create a branch from my PR branch and I’ll merge your work in.
Thanks for the code sample. It helped me think through the problem. I’ve got a clearer idea of the solution now. Let me know what you think.
Spec
We’ll add a
swipeable
prop to theTabBar
component. This will default to true so that it’s backward compatible. If it’s false then, instead of rendering aTabLayout
, we’ll render aBottomNavigationView
. We’ll do this conditional rendering in the javascript. TheTabBar
component will check theswipeable
prop and either render aNVTabLayout
or aNVTabNavigation
native component. The rest of theTabBar
javascript stays the same.On the native side we’ll create a
TabNavigationView
that inherits fromBottomNavigationView
. We don’t want theTabBarView
to worry about how the Tabs are rendered so we’ll create aTabView
interface. Both the existingTabLayoutView
and the newTabNavigationView
will implement this interface. TheTabBarView
will talk to this interface instead of talking directly to theTabLayoutView
like it currently does. An example interface method issetupWithViewPager
.The majority of the work will be implementing the
TabNavigationView
. We can study Android’sTabLayout
to point us in the right direction.If swipeable is set to false then the
TabBarView
component will disable the swiping functionality of theViewPager
.We’ll add a
hideTabs
prop to theTabBar
component. If set to true then it won’t render the tabs.