material-components-android icon indicating copy to clipboard operation
material-components-android copied to clipboard

[BottomSheetBehavior] Giving touch priority to a nested bottom sheet

Open OxygenCobalt opened this issue 3 years ago • 0 comments

Is your feature request related to a problem? Please describe. My app uses two bottom sheets, one nested into the other. Overall, there are few issues with it, except for the fact that the container bottom sheet intercepts most touch and nested scrolling events to it, preventing me from swiping up the nested sheet if there is a scrolling view within it, and preventing me from swiping down the nested sheet normally once it is expanded.

Describe the solution you'd like An attribute like behavior_nestedBottomSheetId that allows me to specify the ID of a nested bottom sheet within the layout. The parent bottom sheet would then check for that ID, see if the touch/nested scrolling event actually applies to the nested sheet, and then delegate to the nested sheet instead of consuming the

Describe alternatives you've considered I can hack in a kind of touch priority with the following override in the container bottom sheet:

override fun onInterceptTouchEvent(
    parent: CoordinatorLayout,
    child: V,
    event: MotionEvent
): Boolean = super.onInterceptTouchEvent(parent, child, event) && state != STATE_EXPANDED // Do not consume nested scrolling events when expanded so they are delegated to the nested sheet

And the following code in a BottomSheetCallback:

containerBottomSheetBehavior.isDraggable = nestedBottomSheetBehavior.state == BottomSheetBehavior.STATE_COLLAPSED // if nested sheet is expanded, do not intercept dragging downwards

But I don't really feel like these will work correctly in all cases compared to a native solution for handling touch events.

Additional context I can understand if you reject this, since I think nesting sheets like this is not really expected by the library. If you want me to file more particular bug reports for the issues I encountered, that is also okay.

OxygenCobalt avatar Aug 02 '22 16:08 OxygenCobalt