title: Allow NestedScrollView to scroll completely inside a BottomSheet with a Custom Behaviour
body: <p>I have a bottom sheet with a child NestedScrollView. I want to scroll the entire NestedScrollView all the way to bottom without sliding the bottom sheet to up side.</p>
  
  <p>If user wants the bottom sheet to go all the way up they have to use the anchor no other way.</p>
  
  <p>Now when use start scrolling down, after the entire content is scrolled i want the bottom sheet to hide on next scroll action.</p>
  
  <p>As default bottom sheet behavior doesn't allow that  I have created my own custom behavior and overidden the onNestedScroll() and onNestedPreScroll(). </p>
  
  <p>There are two issue I am facing:</p>
  
  <p>1 : The Nestedscrollview scrolls partially and stops because with respect to bottom sheet it sees there is no more content to scroll. I have to slide up the sheet in order to see the rest content. Means I cannot see the last item inside the NestedScrollView without expanding the sheet.</p>
  
  <p>2: How can I detect whether the NestedScrollChild is scrolling up or scrolling down. Because I want the BottomSheet to intercept events once the scrollview finished scrolling its content. I tried onNestedPreScroll but seems like it is not necessarily triggered every time a child is being scroll. Is attaching a listener to scrollview is the only solution?</p>
  
  <p>Link to see the issue in GIF 
  <a href="https://photos.app.goo.gl/RPmDFEtR9TbGHrau6" rel="noreferrer">https://photos.app.goo.gl/RPmDFEtR9TbGHrau6</a></p>
  
  <p>Below is my layout and behavior class.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  </code></pre>
  
  <p></p>
  
  <pre><code>&lt;com.google.android.material.appbar.AppBarLayout
          android:id="@+id/appBar"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:theme="@style/ThemeOverlay.AppCompat.ActionBar"&gt;
  
      &lt;androidx.appcompat.widget.Toolbar
              android:id="@+id/toolbar"
              android:layout_width="match_parent"
              android:layout_height="?attr/actionBarSize"
              android:background="?attr/colorPrimary"
      /&gt;
  &lt;/com.google.android.material.appbar.AppBarLayout&gt;
  </code></pre>
  
    -->
  
  <pre><code>&lt;androidx.constraintlayout.widget.ConstraintLayout
          android:id="@+id/bs"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:background="@drawable/bottom_sheet_background_shaded"
          android:elevation="10dp"
          app:behavior_hideable="false"
          app:behavior_peekHeight="35dp"
          app:behavior_fitToContents="false"
          app:layout_behavior="com.pyus13.bottomsheetsample.MyBottomSheetBehaviour"&gt;
  
      &lt;ImageView
              android:id="@+id/anchor"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_gravity="center_horizontal"
              android:layout_marginTop="1dp"
              android:src="@drawable/bottom_sheet_anchor_holder"
              app:layout_constraintBottom_toTopOf="@+id/main_container"
              app:layout_constraintEnd_toEndOf="parent"
              app:layout_constraintStart_toStartOf="parent"
              app:layout_constraintTop_toTopOf="parent"/&gt;
  
      &lt;androidx.core.widget.NestedScrollView
              android:id="@+id/main_container"
              android:layout_width="0dp"
              android:layout_height="wrap_content"
              android:layout_marginTop="15dp"
              android:clipToPadding="false"
              android:elevation="5dp"
              android:gravity="center"
              android:paddingTop="20dp"
              app:layout_behavior="@string/appbar_scrolling_view_behavior"
              app:layout_constraintBottom_toBottomOf="parent"
              app:layout_constraintEnd_toEndOf="parent"
              app:layout_constraintStart_toStartOf="parent"
              app:layout_constraintTop_toBottomOf="@id/anchor"&gt;
  
          &lt;LinearLayout
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:orientation="vertical"&gt;
  
              &lt;Button
                      android:id="@+id/change_title"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_gravity="center"
                      android:text="Title 1"/&gt;
  
              &lt;Button
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_gravity="center"
                      android:text="Title 2"/&gt;
  
              &lt;Button
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_gravity="center"
                      android:text="Page 3"/&gt;
  
              &lt;Button
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_gravity="center"
                      android:text="Page 4"/&gt;
  
              &lt;Button
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_gravity="center"
                      android:text="Page 5"/&gt;
  
              &lt;Button
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_gravity="center"
                      android:text="Change Title"/&gt;
  
              &lt;Button
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_gravity="center"
                      android:text="Change Title"/&gt;
  
              &lt;Button
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_gravity="center"
                      android:text="Change Title"/&gt;
  
              &lt;Button
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_gravity="center"
                      android:text="Change Title"/&gt;
  
              &lt;Button
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_gravity="center"
                      android:text="Change Title"/&gt;
  
              &lt;Button
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_gravity="center"
                      android:text="Change Title"/&gt;
  
              &lt;Button
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_gravity="center"
                      android:text="Change Title"/&gt;
  
              &lt;Button
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_gravity="center"
                      android:text="Change Title"/&gt;
  
              &lt;Button
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_gravity="center"
                      android:text="Change Title"/&gt;
  
              &lt;Button
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_gravity="center"
                      android:text="Change Title"/&gt;
  
              &lt;Button
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_gravity="center"
                      android:text="Change Title"/&gt;
  
              &lt;Button
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_gravity="center"
                      android:text="Change Title"/&gt;
  
              &lt;Button
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_gravity="center"
                      android:text="Change Title"/&gt;
  
  
          &lt;/LinearLayout&gt;
  
      &lt;/androidx.core.widget.NestedScrollView&gt;
  
  &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
  </code></pre>
  
  <p></p>
  
  <p>My Behavior class:</p>
  
  <pre><code>class MyBottomSheetBehaviour&lt;V : View&gt; @JvmOverloads constructor(
      context: Context? = null, attrs: AttributeSet? = null) : BottomSheetBehavior&lt;V&gt;(context, attrs) {
  
  private var isScrollingDown = false
  
  
  override fun onInterceptTouchEvent(parent: CoordinatorLayout, child: V, event: MotionEvent): Boolean {
      if (state == STATE_COLLAPSED || state == STATE_HALF_EXPANDED) {
          return false
      }
      return super.onInterceptTouchEvent(parent, child, event)
  }
  
  override fun onStartNestedScroll(coordinatorLayout: CoordinatorLayout, child: V, directTargetChild: View, target: View, axes: Int, type: Int): Boolean {
      Log.d("Scroll", "OnNestedScroll EVent $child $target $axes $type")
      if (state == STATE_COLLAPSED || state == STATE_HALF_EXPANDED) {
          if (target.canScrollVertically(1) || target.canScrollVertically(-1)) {
              return false
          }
      }
      return super.onStartNestedScroll(coordinatorLayout, child, directTargetChild, target, axes, type)
  }
  
  override fun onNestedPreScroll(coordinatorLayout: CoordinatorLayout, child: V, target: View, dx: Int, dy: Int, consumed: IntArray, type: Int) {
      isScrollingDown = dy &gt; 0
      super.onNestedPreScroll(coordinatorLayout, child, target, dx, dy, consumed, type)
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I want a behavior like this if someone can help would really be appreciated.</p>
  
  <p><a href="https://i.stack.imgur.com/yhsTR.png" rel="noreferrer"><img src="https://i.stack.imgur.com/yhsTR.png" alt="enter image description here"></a></p>