bufferapp / AdaptableBottomNavigation

A simpler way for implementing the Bottom Navigation View on Android
829 stars 73 forks source link

Question: Disable Swiping Possible in Viewpager? #2

Closed rayliverified closed 7 years ago

rayliverified commented 7 years ago

This library points out a lot of the issues with using a ViewPager and a Bottom Tab Layout. My current understanding of the ViewPager is that it draws some of the views that are not yet visible and allows swiping between pages. Is it possible using the ViewPager to disable swiping between pages and drawing pages that are not yet visible? If not, then this library will be very useful! As it stands, I am not certain whether this library improves upon the ViewPager's performance.

hitherejoe commented 7 years ago

Great question! The main purpose of this library was to decouple the logic for the bottom navigation view, as currently in the support library you can't attach an adapter to the view like you can say, a tab layout. However, this library still allows you to do so.

The ViewSwapper component in this library is a fork of the viewpager, so internally it is the same, it just doesn't draw the views prior to them being shown. You can disable swiping on the viewpager and use setCurrentItem(position, false) to disable smooth scrolling. You can set the offscreen page limit for the viewpager, but this can not be less than 1 - so the view pager will always force you to have another page drawn other than the one being currently viewed. The ViewSwapper however, only shows a single view (the current one) at any given time.

rayliverified commented 7 years ago

@hitherejoe Perfect! What you are saying is that this library takes advantage of existing ViewPager optimizations but further optimizes it for a tabbed bottom bar layout. That's just what I need!

Quick followup --> is it possible to use the ViewSwapper class without using the library's
AdaptableBottomNavigationView.java? I am using my own bottom tab library and there are many other bottom tab libraries out there.

Thanks for the fast response!