material-components / material-components/material-components-android
[BottomSheetBehavior] Giving touch priority to a nested bottom sheet
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 17.4k
- Forks
- 3.2k
- PR merge metrics
- No merged PRs in 30d
Description
**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:
```kotlin
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`:
```kotlin
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with BottomSheetBehavior.onInterceptTouchEvent and the nested scrolling behavior described in the issue. Trace how a parent and nested bottom sheet receive touch and scroll events, then define and test the proposed nested-sheet priority behavior, including expanded and collapsed states.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, kotlin
- Domain
- mobile
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100