FAB doesn't return to initial position after snackbar goes away

112 views Asked by At

I have a FloatingActionButton in a BottomAppBar, both inside of a CoordinatorLayout. When I have a Snackbar coming in, the FAB moves up correctly to make room for it, unfortunately, when the Snackbar slides back out, the FAB moves down more than it should for a few seconds, before autonomously going back to the correct position.

Below is the XML layout:

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout 
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:id="@+id/snackBarLayout"
android:orientation="vertical">

<androidx.viewpager2.widget.ViewPager2
    android:id="@+id/viewPager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginBottom="@dimen/appIntroBottomBarHeight"
    android:orientation="horizontal" />

<com.google.android.material.floatingactionbutton.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:contentDescription="@string/app_name"
    android:src="@drawable/fab_add"
    android:elevation="10dp"
    android:focusable="true"
    android:layout_gravity="top|end"
    app:layout_anchorGravity="top"
    android:theme="@style/ToggleTheme"
    android:layout_marginEnd="20dp"
    app:borderWidth="0dp"
    app:layout_dodgeInsetEdges="bottom"
    android:baselineAlignBottom="true"
    app:elevation="2dp"
    app:layout_anchor="@id/bottomAppBar"
    app:pressedTranslationZ="12dp"
    app:rippleColor="@color/gray" />

<com.google.android.material.bottomappbar.BottomAppBar
    android:id="@+id/bottomAppBar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    app:fabAlignmentMode="end"
    app:fabCradleVerticalOffset="20dp">

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/bottomNavigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginStart="2dp"
        app:layout_dodgeInsetEdges="bottom"
        android:layout_marginEnd="2dp"
        android:background="@drawable/toolbar_background"
        android:elevation="8dp"
        android:foregroundGravity="center"
        android:layout_gravity="bottom"
        app:itemIconTint="@drawable/nav_bottom_selected_item"
        app:itemTextColor="@drawable/nav_bottom_selected_item"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/contactsViewPager"
        app:menu="@menu/bottom_menu" />

</com.google.android.material.bottomappbar.BottomAppBar>

</androidx.coordinatorlayout.widget.CoordinatorLayout>

snackBarLayout is the view on which snack bar is created

0

There are 0 answers