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] Define predictive back behavior for non-modal persistent bottom sheets #3838

Closed OxygenCobalt closed 1 month ago

OxygenCobalt commented 9 months ago

Is your feature request related to a problem? Please describe. My app has a bottom sheet that is persistent, i.e isHideable = false, the the back button makes it go from expanded to collapsed. However, it seems like the predictive back behavior for BottomSheetBehavior is hard-coded to hide the bottom sheet, and in general it seems like the animation will only work if the bottom sheet hides when the back button is pressed. If I try it in my own app with my non-hideable bottom sheet, the sheet stays in it's detached/zoomed out state, even when the back operation was complete.

Describe the solution you'd like I want some kind of predictive back behavior defined for when a bottom sheet will go from an expanded to collapsed state, rather than simply to a hidden state. This can still fit the current "detatch from the edges" behavior defined in the specification, but the bottom sheet simply reattaches itself to the edges of it's screen as it collapses.

Describe alternatives you've considered Designing my bottom sheets to be modal, which would take a lot of effort and not be very user-friendly.

OxygenCobalt commented 9 months ago

Okay, I actually looked closer and it does seem that non-hideable bottom sheets do have a predictive back behavior. Still, the issue where the bottom sheet doesn't seem to correctly scale back remains.

dsn5ft commented 9 months ago

@OxygenCobalt can you provide a video of the issue and code snippets for your setup?

Our Catalog app has a non-hideable bottom sheet which works well with predictive back, so we will have to figure out how your setup is different:

https://github.com/material-components/material-components-android/blob/54d2c8b87f364ca9cb04cbd9b751efd490bbb56e/catalog/java/io/material/catalog/bottomsheet/BottomSheetMainDemoFragment.java#L48-L70

non-hideable bottom sheet predictive back.webm

OxygenCobalt commented 1 month ago

Sorry for the late response @dsn5ft, I lost track of this. It was just a configuration error on my end. Thanks anyway.