question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BottomSheetBehavior] Broken hidden->collapsed animation, setPeekHeight animation

See original GitHub issue

Description: Changing BottomSheet state when one is laid out should lead to state change animation. However changing state from hidden to collapsed breaks animation totally in certain cases (makes it appear as expanded -> collapsed). setPeekHeight is affected as well due to the same reason (leads to no visible animation, peek height is changed due to layout)

Source code:

// Issue for hidden -> collapsed
behavior.isHideable = true
behavior.state = BottomSheetBehavior.STATE_HIDDEN
// await layout

behavior.isHideable = false // animates only if no onLayoutChild happens between setHideable and settleToState
// The same issue for setPeekHeight
behavior.isHideable = true
behavior.state = BottomSheetBehavior.STATE_HIDDEN
// await layout

setPeekHeight(123, true) // animates only if no onLayoutChild happens between setPeekHeight and settleToState

Possible workaround for both is ugly as hell:

if (view.parent.isLayoutRequested) {
    view.post(animateCollapse)
    return
}
behavior.isHideable = false
behavior.state = BottomSheetBehavior.STATE_COLLAPSED

Thoughts:

This seem to work correctly prior to 46366ad4356b57180eac048cec9994c796a5ca66 (onLayoutChild change with hideable check) There are several culprits to me:

  • hideable is set prior to layout (whereas state - once view is actually laid out)
  • peekHeight is set prior to layout as well
  • settleToStatePendingLayout awaits parent being laid out, however onLayoutChild could pass several times affecting child’s mTop
  • onLayoutChild affect child’s mTop and startSettlingAnimation either won’t animate or animate incorrectly

Android API version: any

Material Library version: 1.2.1

Device: any

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:12
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
prathameshmm02commented, Oct 14, 2021

I can confirm, it’s still an issue as stated by the author. When BottomSheet is first hidden then if tried to unhide it by setting isHideable to false, it jumps to the expanded state then to the collapsed state but according to the setHideable method and normally, it should be in collapsed state.

public void setHideable(boolean hideable) {
    if (this.hideable != hideable) {
      this.hideable = hideable;
      if (!hideable && state == STATE_HIDDEN) {
        // Lift up to collapsed state
        setState(STATE_COLLAPSED);
      }
      updateAccessibilityActions();
    }
  }
0reactions
paulfthomascommented, Feb 8, 2022

Closing the issue due to no further info available, please feel free to reopen it with more details.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Show/Hide View With Animation When Bottom Sheet ...
Android Bottom Sheet Behavior explained and extended to create a Tapping a menu ... [BottomSheetBehavior] Broken hidden>collapsed animation setPeekHeight ...
Read more >
Android BottomSheetBehavior setPeekHeight(int peekHeight ...
I faced a similar problem, and I am not sure of a direct solution using: setPeekHeight(int peekHeight, boolean animate).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found