@@ -306,6 +306,8 @@ void onLayout(@NonNull View bottomSheet) {}
306306
307307 private boolean draggable = true ;
308308
309+ private boolean draggableOnNestedScroll = true ;
310+
309311 @ State int state = STATE_COLLAPSED ;
310312
311313 @ State int lastStableState = STATE_COLLAPSED ;
@@ -398,6 +400,9 @@ public BottomSheetBehavior(@NonNull Context context, @Nullable AttributeSet attr
398400 setSkipCollapsed (
399401 a .getBoolean (R .styleable .BottomSheetBehavior_Layout_behavior_skipCollapsed , false ));
400402 setDraggable (a .getBoolean (R .styleable .BottomSheetBehavior_Layout_behavior_draggable , true ));
403+ setDraggableOnNestedScroll (
404+ a .getBoolean (
405+ R .styleable .BottomSheetBehavior_Layout_behavior_draggableOnNestedScroll , true ));
401406 setSaveFlags (a .getInt (R .styleable .BottomSheetBehavior_Layout_behavior_saveFlags , SAVE_NONE ));
402407 setHalfExpandedRatio (
403408 a .getFloat (R .styleable .BottomSheetBehavior_Layout_behavior_halfExpandedRatio , 0.5f ));
@@ -739,6 +744,9 @@ public void onNestedPreScroll(
739744 if (isNestedScrollingCheckEnabled () && target != scrollingChild ) {
740745 return ;
741746 }
747+ if (!draggableOnNestedScroll && target == scrollingChild ) {
748+ return ;
749+ }
742750 int currentTop = child .getTop ();
743751 int newTop = currentTop - dy ;
744752 if (dy > 0 ) { // Upward
@@ -877,7 +885,7 @@ public boolean onNestedPreFling(
877885
878886 if (isNestedScrollingCheckEnabled () && nestedScrollingChildRef != null ) {
879887 return target == nestedScrollingChildRef .get ()
880- && (state != STATE_EXPANDED
888+ && (( state != STATE_EXPANDED && draggableOnNestedScroll )
881889 || super .onNestedPreFling (coordinatorLayout , child , target , velocityX , velocityY ));
882890 } else {
883891 return false ;
@@ -1170,7 +1178,7 @@ public boolean getSkipCollapsed() {
11701178 }
11711179
11721180 /**
1173- * Sets whether this bottom sheet is can be collapsed/expanded by dragging. Note: When disabling
1181+ * Sets whether this bottom sheet can be collapsed/expanded by dragging. Note: When disabling
11741182 * dragging, an app will require to implement a custom way to expand/collapse the bottom sheet
11751183 *
11761184 * @param draggable {@code false} to prevent dragging the sheet to collapse and expand
@@ -1184,6 +1192,22 @@ public boolean isDraggable() {
11841192 return draggable ;
11851193 }
11861194
1195+ /**
1196+ * Sets whether this bottom sheet can be collapsed/expanded by dragging on the nested scrolling
1197+ * child view. Default is true.
1198+ *
1199+ * @param draggableOnNestedScroll {@code false} to prevent dragging the nested scrolling child
1200+ * view to collapse and expand the sheet
1201+ * @attr ref com.google.android.material.R.styleable#BottomSheetBehavior_Layout_behavior_draggableOnNestedScroll
1202+ */
1203+ public void setDraggableOnNestedScroll (boolean draggableOnNestedScroll ) {
1204+ this .draggableOnNestedScroll = draggableOnNestedScroll ;
1205+ }
1206+
1207+ public boolean isDraggableOnNestedScroll () {
1208+ return draggableOnNestedScroll ;
1209+ }
1210+
11871211 /*
11881212 * Sets the velocity threshold considered significant enough to trigger a slide
11891213 * to the next stable state.
0 commit comments