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

[BottomSheetBehavior] Allow avoiding STATE_HALF_EXPANDED

Open Mugurell opened this issue 4 years ago • 5 comments

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.

Mugurell avatar Oct 19 '20 17:10 Mugurell

I would also like this feature very much.

bknmjolner avatar Mar 10 '21 10:03 bknmjolner

I do also have this problem!

mortenholmgaard avatar Mar 10 '21 10:03 mortenholmgaard

eager to have this too

DanteAndroid avatar Jan 04 '22 10:01 DanteAndroid

Please add this

VITYQ avatar Feb 15 '22 16:02 VITYQ

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
}

OxygenCobalt avatar Jun 27 '22 17:06 OxygenCobalt

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)).

manabu-nakamura avatar Nov 16 '22 06:11 manabu-nakamura

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:

  1. 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)
  2. Proper handling of fitToContents = false (currently floats to the top which effectively made it an experimental API rather than a stable one)
  3. Expanded state should take into account the fact that the layout height could be altered dynamically after the sheet is visible
  4. 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
  5. In addition to the previous point, there should also be a way to manually update the scrolling child
  6. 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.

MuntashirAkon avatar Feb 12 '23 16:02 MuntashirAkon

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.

OxygenCobalt avatar Mar 08 '23 22:03 OxygenCobalt