Closed Slion closed 2 years ago
Also if you set the state to expanded before showing your dialog you don't get any onStateChanged
call.
This is also somewhat related to #2168
Here is what I did to workaround those issues. Just calling that function whenever the bottom sheet size changes does the trick:
/**
* To fix issues with wrong edge-to-edge bottom sheet top padding and status bar icon color…
* …we need to call [BottomSheetDialog.EdgeToEdgeCallback.setPaddingForPosition] which is a private function from a private class.
* See: https://github.com/material-components/material-components-android/issues/2165
*/
fun adjustBottomSheet(aDialog : BottomSheetDialog) {
// Get our private class
val classEdgeToEdgeCallback = Class.forName("com.google.android.material.bottomsheet.BottomSheetDialog\$EdgeToEdgeCallback")
// Get our private method
val methodSetPaddingForPosition: Method = classEdgeToEdgeCallback.getDeclaredMethod("setPaddingForPosition", View::class.java)
methodSetPaddingForPosition.isAccessible = true
// Get private field containing our EdgeToEdgeCallback instance
val fieldEdgeToEdgeCallback = BottomSheetDialog::class.java.getDeclaredField("edgeToEdgeCallback")
fieldEdgeToEdgeCallback.isAccessible = true
// Get our bottom sheet view field
val fieldBottomField = BottomSheetDialog::class.java.getDeclaredField("bottomSheet")
fieldBottomField.isAccessible = true
// Eventually call setPaddingForPosition from EdgeToEdgeCallback instance passing bottom sheet view as parameter
methodSetPaddingForPosition.invoke(fieldEdgeToEdgeCallback.get(aDialog),fieldBottomField.get(aDialog))
}
Any updates on this? Having the same problem and the original workaround isn't looking pretty and it isn't working in every case.
Any updates on this?
Check the Fulguris source code maybe I'm pretty sure it is still working there somehow.
Could it be that this was fixed somewhat in v1.4.0?
Still having this problem, couldn't get the workaround to even work.
I have a fix just merged internally. Should be copied over here very soon if everything looks fine.
Description: 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:
To workaround that issue I had to:
Analysis
̀EdgeToEdgeCallback.setPaddingForPosition
is not getting called when setting the state to expanded just after the call to show. For some reasoǹ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¹