@@ -307,6 +307,7 @@ void onLayout(@NonNull View bottomSheet) {}
307307 private boolean draggable = true ;
308308
309309 private boolean draggableOnNestedScroll = true ;
310+ private boolean draggableOnNestedScrollLastDragIgnored ;
310311
311312 @ State int state = STATE_COLLAPSED ;
312313
@@ -744,12 +745,14 @@ public void onNestedPreScroll(
744745 if (isNestedScrollingCheckEnabled () && target != scrollingChild ) {
745746 return ;
746747 }
747- if (!draggableOnNestedScroll && target == scrollingChild ) {
748- return ;
749- }
750748 int currentTop = child .getTop ();
751749 int newTop = currentTop - dy ;
752- if (dy > 0 ) { // Upward
750+ if (dy > 0 ) { // Upward swipe
751+ if (!draggableOnNestedScroll && target == scrollingChild && target .canScrollVertically (1 )) {
752+ // Prevent dragging if draggableOnNestedScroll=false and we can scroll the scrolling child.
753+ draggableOnNestedScrollLastDragIgnored = true ;
754+ return ;
755+ }
753756 if (newTop < getExpandedOffset ()) {
754757 consumed [1 ] = currentTop - getExpandedOffset ();
755758 ViewCompat .offsetTopAndBottom (child , -consumed [1 ]);
@@ -764,8 +767,14 @@ public void onNestedPreScroll(
764767 ViewCompat .offsetTopAndBottom (child , -dy );
765768 setStateInternal (STATE_DRAGGING );
766769 }
767- } else if (dy < 0 ) { // Downward
768- if (!target .canScrollVertically (-1 )) {
770+ } else if (dy < 0 ) { // Downward swipe
771+ boolean canScrollUp = target .canScrollVertically (-1 );
772+ if (!draggableOnNestedScroll && target == scrollingChild && canScrollUp ) {
773+ // Prevent dragging if draggableOnNestedScroll=false and we can scroll the scrolling child.
774+ draggableOnNestedScrollLastDragIgnored = true ;
775+ return ;
776+ }
777+ if (!canScrollUp ) {
769778 if (newTop <= collapsedOffset || canBeHiddenByDragging ()) {
770779 if (!draggable ) {
771780 // Prevent dragging
@@ -785,6 +794,7 @@ public void onNestedPreScroll(
785794 dispatchOnSlide (child .getTop ());
786795 lastNestedScrollDy = dy ;
787796 nestedScrolled = true ;
797+ draggableOnNestedScrollLastDragIgnored = false ;
788798 }
789799
790800 @ Override
@@ -885,7 +895,7 @@ public boolean onNestedPreFling(
885895
886896 if (isNestedScrollingCheckEnabled () && nestedScrollingChildRef != null ) {
887897 return target == nestedScrollingChildRef .get ()
888- && ((state != STATE_EXPANDED && draggableOnNestedScroll )
898+ && ((state != STATE_EXPANDED && ! draggableOnNestedScrollLastDragIgnored )
889899 || super .onNestedPreFling (coordinatorLayout , child , target , velocityX , velocityY ));
890900 } else {
891901 return false ;
0 commit comments