material-components-android
material-components-android copied to clipboard
[BottomSheetBehavior] Allow avoiding STATE_HALF_EXPANDED
Is your feature request related to a problem? Please describe. By popular request - https://stackoverflow.com/questions/59487982/android-how-to-disable-state-half-expanded-state-of-a-bottom-sheet:
- have
behavior_fitToContents = false
to try getting the view to have 2 possible states: expanded and collapsed with app defined fixed dimensions. - a third -
STATE_HALF_EXPANDED
state and view height is introduced that's of no use.
Describe the solution you'd like
A behavior_skipHalfExpanded
property/method that would have the behavior never set STATE_HALF_EXPANDED
.
We also happily accept pull requests.
I would also like this feature very much.
I do also have this problem!
eager to have this too
Please add this
Just to let you all know, you can replicate something similar by using this class:
class SkipHalfExpandedBottomSheetBehavior<V: View> : BottomSheetBehavior<V> {
constructor() : super()
constructor(context: Context, attributeSet: AttributeSet?) : super(context, attributeSet)
init {
isFitToContents = false
}
override fun shouldSkipHalfExpandedStateWhenDragging() = true
override fun shouldExpandOnUpwardDrag(
dragDurationMillis: Long,
yPositionPercentage: Float
) = true
}
I don't understand why app:behavior_fitToContents="false" allow us to drag to STATE_HALF_EXPANDED (app:behavior_fitToContents="true" doesn't allow us to drag to STATE_HALF_EXPANDED). The problem is big (https://github.com/material-components/material-components-android/issues/2702, https://github.com/material-components/material-components-android/issues/3018). I would like a convenience method to set the collapsed bottom sheet height to half the height of the screen and provide access to its top actions (https://m2.material.io/components/sheets-bottom > Modal bottom sheet > Behavior > Visibility, https://developer.android.com/reference/com/google/android/material/bottomsheet/BottomSheetBehavior#setPeekHeight(int)).
Most of the existing issues revolve around half-expanded state, collapse state and fit-to-contents. At this point, I believe the BottomSheetBehavior
design should contain or address the following issues:
- A way to disable half-expanded state (it should be acknowledged by the designers that there are use-cases where a half-expanded state is completely useless)
- Proper handling of
fitToContents = false
(currently floats to the top which effectively made it an experimental API rather than a stable one) - Expanded state should take into account the fact that the layout height could be altered dynamically after the sheet is visible
- Any changes to the layout should also check if the scrolling child has altered. But there might also be multiple scrolling child (in a ViewPager, for example). For those cases, how the scrolling child would be determined should also be considered
- In addition to the previous point, there should also be a way to manually update the scrolling child
- Finally, a non-recursive implementation of
findScrollingChild
might be preferred.
All these issues look separate but they're actually part of the same problem. And these changes could be made without altering the existing API/behaviour.
100% agree @MuntashirAkon. BottomSheetBehavior
is honestly one of the most neglected parts of MDC. I really hope that Jetpack Compose will one day provide a proper bottom sheet scaffold with a saner API and far less workarounds to get non-trivial functionality working, but I'm not holding my breath.