1

The problem is, after expanding the bottom sheet, the area underneath the sheet where the MaterialToolbar is located can't be used to drag the sheet back down. The rest of the sheet can still be used for dragging.

Complete runnable project is at https://github.com/svenoaks/DragBottomSheet

I used the standard Material3 Android Studio project and modified it like this:

activity_main.xml

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context=".MainActivity">

    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true">

        <com.google.android.material.appbar.MaterialToolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            app:layout_collapseMode="none"
            android:layout_height="128dp" />

    </com.google.android.material.appbar.AppBarLayout>

    <FrameLayout
        android:id="@+id/standard_bottom_sheet"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="?colorSecondary"
        app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"
        app:behavior_hideable="false"
        app:behavior_peekHeight="?actionBarSize">
        <include layout="@layout/content_main" />
    </FrameLayout>


</androidx.coordinatorlayout.widget.CoordinatorLayout>
Steve M
  • 9,296
  • 11
  • 49
  • 98
  • A `NavHostFragment` wrapped into a FrameLayout bottom sheet looks like weird. Do you have a documentation reference to that design? – Zain Jan 03 '23 at 23:18
  • NavHostFragment was only due to starting a new project with Material3 template. I'm currently trying to boil it down into something simpler, having difficulty finding the exact conditions that can cause it. But upgrading from 1.6.1 to 1.7.0 of the material library caused BottomSheetBehavior to stop registering drag events on the Toolbars in the bottom sheet and below in my app as needing to drag the sheet. Will update the question if I have more info. – Steve M Jan 04 '23 at 16:22

1 Answers1

0

Cause:

This behavior has nothing to do with Material3, replacing the MaterialToolbar with something else like Toolbar or even a LinearLayout you'd get the same behavior.

The dragging behavior of the Bottom sheet is blocked because of the FirstFragement's NestedScrollView nested scrolling behavior which catches the drag event instead of the bottom sheet.

Two ways to solve this:

  1. Replace the NestedScrollView with the normal ScrollView which doesn't have the nested scrolling behavior by default.
  2. Programmatically disable the nested scrolling of the NestedScrollView:
<androidx.core.widget.NestedScrollView
    ....
    android:id="@+id/nested_scroll_view">
class FirstFragment : Fragment() {
    // ....
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        binding.nestedScrollView.isNestedScrollingEnabled = false
    }
}

Don't set that in layout to avoid InflateException

Side note: you'd add some android:elevation to the bottom sheet to avoid obscuring it by the toolbar.

Zain
  • 37,492
  • 7
  • 60
  • 84
  • 1
    My question was pretty bad and didn't reflect the actual problem I had, but I'm giving the bounty since this answered the question I asked. In my actual layout, it was similar, it was catching some nested scroll events from within the sheet it self (probably a bug that dragging the toolbar was working at all since it was not within the bounds of the nested)...upgrading from the material lib 1.6.1 to 1.7.0 fixed this probable bug and made dragging the toolbar stop working until I figured out what the actual problem was, which was an invisible view on top of everything. – Steve M Jan 07 '23 at 21:21