ibrahimsn98 / SmoothBottomBar

A lightweight Android material bottom navigation bar library
MIT License
1.97k stars 255 forks source link

Set up with viewPager ? #50

Open LassassinX opened 4 years ago

LassassinX commented 4 years ago

Anyway to set this bottom bar with a viewpager ? So that I can swipe back and forth between fragments ?

brookmg commented 4 years ago

You can check the following code out for inspiration.

        mainViewPager.addOnPageChangeListener(object : OnPageChangeListener {
            override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {}
            override fun onPageSelected(position: Int) {
                bottomBar.setActiveItem(position)
            }

            override fun onPageScrollStateChanged(state: Int) {}
        })

        bottomBar.onItemSelected = { i: Int -> mainViewPager.currentItem = i }

Integration in the lib itself like the TabLayout might be interesting to do. But the above works well for now.

LassassinX commented 4 years ago

That is great! Can I get an example in java ? I'm pretty new

LassassinX commented 4 years ago

Okay so I've implemented this. However, the responsiveness is not good. The tab items change way after the viewpager has set a page, making it look very unresponsive. Will this feature be integrated into the library soon so that the animation is smoother ? TIA

       viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
                @Override
                  public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
                  smoothBottomBar.setItemActiveIndex(position);
        }