aurelhubert / ahbottomnavigation

A library to reproduce the behavior of the Bottom Navigation guidelines from Material Design.
3.83k stars 682 forks source link

hide/show when recycler scroll inside Conductor view doesn't work #374

Open douglasalipio opened 6 years ago

douglasalipio commented 6 years ago

@jahirfiquitiva said in this issue here

If you use the RecyclerView inside a CoordinatorLayout this should suffice: bottomNavigation.setBehaviorTranslationEnabled(true);

I have a recyclerView inside a CoordinatorLayout but it does't work. Am I forgetting something?

MainActivity

override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.main_view)
        initRoute(savedInstanceState)
        initNavBar()
 }
val navigationAdapter = AHBottomNavigationAdapter(this, R.menu.navigation)
        navigation?.let { safeNave ->
            navigationAdapter.setupWithBottomNavigation(safeNave)
            safeNave.isBehaviorTranslationEnabled = true
            safeNave.setOnTabSelectedListener { position, wasSelected ->

                when (position) {
                    1 -> router.pushController(RouterTransaction.with(FeedController()))

                    2 -> router.pushController(RouterTransaction.with(HostFormController()))

                    3 -> router.pushController(RouterTransaction.with(ContentController()))

                    4 -> router.pushController(RouterTransaction.with(LessonController()))

                    5 -> router.pushController(RouterTransaction.with(AccountController()))

                }
                true
            }
    }

Main XML

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="org.secfirst.umbrella.feature.feed.FeedController">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        app:layout_dodgeInsetEdges="bottom">

        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <android.support.v7.widget.Toolbar
                android:id="@+id/mainToolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
        </android.support.design.widget.AppBarLayout>

        <com.bluelinelabs.conductor.ChangeHandlerFrameLayout
            android:id="@+id/baseContainer"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />

    </LinearLayout>

    <com.aurelhubert.ahbottomnavigation.AHBottomNavigation
        android:id="@+id/navigation"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginEnd="0dp"
        android:layout_marginStart="0dp"
        android:background="?android:attr/windowBackground"
        android:fitsSystemWindows="true"
        app:layout_behavior="org.secfirst.umbrella.component.BottomNavigationBehavior"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_insetEdge="bottom"
        app:layout_scrollFlags="scroll|enterAlways"
        app:menu="@menu/navigation" />
</android.support.constraint.ConstraintLayout>

And finnaly, the recycler who has ID activeFormRecycleView that might hide/show the menu.

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#e5e5e5"
    android:orientation="vertical">

    <TextView
        android:id="@+id/titleAllForm"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="4dp"
        android:layout_marginLeft="5dp"
        android:layout_marginStart="5dp"
        android:padding="5dp"
        android:text="@string/message_title_all_forms"
        android:textSize="14sp"
        app:layout_constraintBottom_toTopOf="@+id/allFormRecycleView"
        app:layout_constraintStart_toStartOf="@+id/allFormRecycleView"
        app:layout_constraintTop_toTopOf="parent" />

    <android.support.v7.widget.RecyclerView
        android:id="@+id/allFormRecycleView"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/titleAllForm" />

    <TextView
        android:id="@+id/titleActiveForm"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_marginStart="10dp"
        android:layout_marginTop="50dp"
        android:padding="5dp"
        android:text="@string/message_title_active_forms"
        android:textSize="14sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <android.support.v7.widget.RecyclerView
        android:id="@+id/activeFormRecycleView"
        android:layout_width="match_parent"
        android:layout_height="242dp"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent" />

</android.support.constraint.ConstraintLayout>
jahirfiquitiva commented 6 years ago

Your AHBottomNavigation has this layout_behavior:

    app:layout_behavior="org.secfirst.umbrella.component.BottomNavigationBehavior"

It probably is overriding the required behavior or conflicting with the library

Also, having 2 RecyclerViews in the same layout isn't recommended and it could also be the cause of the issue. Try using a single RecyclerView that is sectioned. You can use this library, or create your own implementation

douglasalipio commented 6 years ago

@jahirfiquitiva totally make sense. The problem was two recycleView. I got rid of one of them and works fine. Thanks.