[BottomSheet] Padding for status bar not applied when starting expanded
See original GitHub issueDescription: Top padding for status bar not applied when starting expanded with edge-to-edge. The content view is then drawn below our transparent status bar. If you start sliding the bottom sheet the padding get set properly.
Expected behavior: Top padding should be applied even when starting expanded.
Source code: Assuming edge to edge attribute is set to true and transparent status bar:
val bottomSheetDialog = BottomSheetDialog(this)
// We need to set private data member edgeToEdgeEnabled to true to get full screen effect
// That has been already fixed since alpha 02 release, this is not our issue here but was left for completeness
val field = BottomSheetDialog::class.java.getDeclaredField("edgeToEdgeEnabled")
field.isAccessible = true
field.setBoolean(bottomSheetDialog,true)
//
bottomSheetDialog.setContentView(myView)
bottomSheetDialog.show()
bottomSheetDialog.behavior.skipCollapsed = true
bottomSheetDialog.behavior.state = BottomSheetBehavior.STATE_EXPANDED
To workaround that issue I had to:
mainHandler.postDelayed( {
bottomSheetDialog.behavior.state = BottomSheetBehavior.STATE_EXPANDED
},100)
Analysis
̀EdgeToEdgeCallback.setPaddingForPosition
is not getting called when setting the state to expanded just after the call to show.
For some reason ̀EdgeToEdgeCallback.onStateChanged
is not called then.
Moreover if the content of the sheet changes causing it to change its size the padding can get out of sync. Like showing top padding when none needed because sheets got smaller or not showing the padding when needed because sheet got bigger. ̀EdgeToEdgeCallback.setPaddingForPosition
should also be called whenever the sheet size is changed.
Android API version: 28
Material Library version: 1.4.0-alpha02
Device: F(x)Tec Pro¹
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:8 (1 by maintainers)
Here is what I did to workaround those issues. Just calling that function whenever the bottom sheet size changes does the trick:
I have a fix just merged internally. Should be copied over here very soon if everything looks fine.