[BottomSheetBehavior] Broken hidden->collapsed animation, setPeekHeight animation
See original GitHub issueDescription: 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 (whereasstate
- once view is actually laid out)peekHeight
is set prior to layout as wellsettleToStatePendingLayout
awaits parent being laid out, howeveronLayoutChild
could pass several times affectingchild
’smTop
onLayoutChild
affectchild
’smTop
and startSettlingAnimation either won’t animate or animate incorrectly
Android API version: any
Material Library version: 1.2.1
Device: any
Issue Analytics
- State:
- Created 3 years ago
- Reactions:12
- Comments:6 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
Closing the issue due to no further info available, please feel free to reopen it with more details.