material-components / material-components/material-components-android
[BottomSheetBehavior] Collapse/Expand threshold is different for NestedScrollView
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 17.4k
- Forks
- 3.2k
- PR merge metrics
- No merged PRs in 30d
Description
**Description:**
When dragging a bottom sheet (without flinging it) and then letting go, the expand/collapse behavior is different based on if the user started the drag from within a NestedScrollView versus any other type of View.
When starting a drag from outside of a NestedScrollView the BottomSheetBehavior appears to take the velocity of the pointer into account (both horizontal and vertical) when determining to expand or collapse. If there is no vertical velocity or if there is more horizontal velocity than vertical then the bottom sheet will move to whichever of the expand or collapse positions is closest.
When starting a drag from within a NestedScrollView the BottomSheetBehavior doesn't appear to take the pointer velocity into account. All movement is treated as if the user was flinging the view so any slight movement in the upward direction will expand the bottom sheet and any movement in the downward direction will collapse the bottom sheet.
**Expected behavior:**
I was expecting the expand/collapse behavior to be the same between NestedScrollView Views and other types of Views. The current behavior makes user interaction within a NestedScrollView overly sensitive. If a user swipes horizontally on a control within a NestedScrollView it may expand/collapse the bottom sheet unexpectedly if there is any amount of upward or downward motion.
**Source code:**
I posted about this issue on StackOverflow. Sample code that illustrates this issue can be found there:
https://stackoverflow.com/questions/60284004/bottomsheet-has-no-drag-threshold-when-user-initiates-drag-from-within-nestedscr
It looks like it's this check in the onViewReleased method that results in the desired behavior which is not present in the onStopNestedScroll method:
https://github.com/material-components/material-components-android/blob/8e8d20c94f3573f7f7418f3971fbbc41a4fa83bd/lib/java/com/google/android/material/bottomsheet/BottomSheetBehavior.java#L1345-L1347
**Android API version:** 28
**Material Library version:** com.google.android.material:material:1.2.0-alpha04
**Device:** Pixel
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 lib/java/com/google/android/material/bottomsheet/BottomSheetBehavior.java, comparing the onViewReleased check cited in the issue with onStopNestedScroll. Reproduce the NestedScrollView case using the linked StackOverflow sample, then verify that horizontal or low-vertical-velocity drags use the same expand/collapse threshold as other views without accidental state changes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, java
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100