material-components / material-components/material-components-android

[BottomSheet] Going from STATE_HIDDEN to STATE_COLLAPSED makes strange animation

Open
#3,017 9 comments 0 reactions 1 assignee View on GitHub

@hunterstich is already working on this.

Since Feb 10, 2025.

bug Widget: BottomSheet
Dominant language
Java
Stars
17.4k
Forks
3.2k
PR merge metrics
No merged PRs in 30d

Description

Description:

In simple apps, calling bottomSheetBehavior.state = BottomSheetBehavior.STATE_COLLAPSED when it is STATE_HIDDEN starts the animation from the bottom of the screen, and eases up into the peek height.

For some reason, in my fork of UAMP, when showing the bottom sheet for the first time by setting the state to collapsed from hidden, the animation starts at about 25% of the way down from the top of the screen (more than half expanded) and within several milliseconds rests at STATE_SETTLED, creating a jarring visual experience.

To reproduce the error, in the sample app, click a card to start the audio player and show the bottom sheet. This only happens the first time a card is clicked after a cold startup.

Expected behavior: Bottom sheet appears in an easing animation animating upwards from the bottom of the screen until it reaches its peek height. What actually happens: bottom sheet appears more than half expanded and animates downwards until it reaches its peek height.

Source code:

private fun showBottomSheetIfNotVisible() {
        if (!bottomSheetIsVisible) {
            bottomSheetIsVisible = true
            behavior.state = BottomSheetBehavior.STATE_COLLAPSED
            val params = fragmentContainer.layoutParams as ConstraintLayout.LayoutParams
            params.bottomMargin = resources.getDimension(R.dimen.bottomsheet_header_height).toInt()
            fragmentContainer.layoutParams = params
        }
    }

Minimal sample app repro: https://github.com/shmueldabomb441/BottomSheetErrorReportingReproduction (Note: there are a few classes related to the media player and unrelated to the bottom sheet error - I tried to cut away as much as I could while retaining the bug; as far as I can tell, all of the relevant code is in MainActivity.)

Android API version: 32

Material Library version: 1.8.0-alpha01

Device: OnePlus 8T

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.