question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use BottomNavigationView instead of top tabs for BottomTabs on Android

See original GitHub issue

Currently 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:

Screenshot_1577388337

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:closed
  • Created 4 years ago
  • Comments:28 (28 by maintainers)

github_iconTop GitHub Comments

1reaction
grahammendickcommented, Dec 31, 2019

Great! I’ve created #341 that implements this basic spec. If you run up the Twitter example and set swipeable to false on the TabBar component then it will render a BottomNavigationView.

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.

1reaction
grahammendickcommented, Dec 31, 2019

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 the TabBar component. This will default to true so that it’s backward compatible. If it’s false then, instead of rendering a TabLayout, we’ll render a BottomNavigationView. We’ll do this conditional rendering in the javascript. The TabBar component will check the swipeable prop and either render a NVTabLayout or a NVTabNavigation native component. The rest of the TabBar javascript stays the same.

On the native side we’ll create a TabNavigationView that inherits from BottomNavigationView. We don’t want the TabBarView to worry about how the Tabs are rendered so we’ll create a TabView interface. Both the existing TabLayoutView and the new TabNavigationView will implement this interface. The TabBarView will talk to this interface instead of talking directly to the TabLayoutView like it currently does. An example interface method is setupWithViewPager.

The majority of the work will be implementing the TabNavigationView. We can study Android’s TabLayout to point us in the right direction.

If swipeable is set to false then the TabBarView component will disable the swiping functionality of the ViewPager.

We’ll add a hideTabs prop to the TabBar component. If set to true then it won’t render the tabs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Switch tab on button click with Bottom Navigation and ...
I have a very simple app that consists of three Fragments and a Bottom Navigation bar, created by using "New ...
Read more >
Android Studio Tutorial - Bottom Navigation Bar / View / Tabs ...
Hello guys, in this android studio tutorial video I will show you how to add a bottom navigation view /bar in the android...
Read more >
Android UX - When to use Bottom navigation and when to use ...
If there are fewer than three destinations, consider using tabs instead. Use Navigation drawer: If your top-level navigation has more than ...
Read more >
Accessible Bottom Tab Navigation on Android
Accessible Bottom Tab Navigation on Android ... Bottom tabs have become such a popular mode of navigation in mobile apps that they've gotten...
Read more >
Bottom Tabs Navigator | React Navigation
A simple tab bar on the bottom of the screen that lets you switch between different routes. Routes are lazily initialized -- their...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found