material-components / material-components-android

Modular and customizable Material Design UI components for Android
Apache License 2.0
16.2k stars 3.05k forks source link

[BottomSheetBehavior] Allow avoiding STATE_HALF_EXPANDED #1807

Open Mugurell opened 3 years ago

Mugurell commented 3 years ago

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:

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.

bknmjolner commented 3 years ago

I would also like this feature very much.

mortenholmgaard commented 3 years ago

I do also have this problem!

DanteAndroid commented 2 years ago

eager to have this too

VITYQ commented 2 years ago

Please add this

OxygenCobalt commented 2 years ago

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
}
manabu-nakamura commented 1 year ago

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

MuntashirAkon commented 1 year ago

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.

OxygenCobalt commented 1 year ago

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.