Status Update
Comments
cl...@google.com <cl...@google.com> #2
If a bottom sheet is in a half expanded state and recreated into a screen where half expanded isn't possible (because it isn't tall enough) it crashes with the same error.
This is also an issue in pre 1.4.0-alpha04, but the error message is "The initial value must have an associated anchor".
This is easily reproducible by having a bottom sheet with a height that in landscape has half expanded, but doesn't in portrait. When rotating with the sheet open it always crashes. This can be mitigated by disallowing the bottom sheet to be half expanded by creating the bottom sheet state with rememberModalBottomSheetState(initialValue = ModalBottomSheetValue.Hidden, skipHalfExpanded = true)
po...@google.com <po...@google.com> #3
Thanks for the report. Do you have an isolated repro?
ma...@google.com <ma...@google.com> #4
You do - apologies, I missed that. We'll check it out! :)
po...@google.com <po...@google.com>
ap...@google.com <ap...@google.com> #5
Looked into this - I believe it is due to how we require the previous target's offset in the anchor change
handler. When animating to a target, we will always update the currentValue
, regardless of whether it exists in the anchors. This is useful for specifically your use case where you call animateTo
(through show
) before the sheet content is recomposed and re-measured. The anchor change handler can move to the appropriate target when the anchors change after the layout size changes.
Instead of requiring the previous target's offset - since it might not be in the anchors - we will change this to a nullable getter in the change handler.
As a workaround, you can place the call in an effect - this should make sure things are executed at the right time. This code from your repro:
ModalBottomSheetLayout(
sheetState = bottomSheetState,
sheetBackgroundColor = if (showSheetContent) Color.Red else Color.Transparent,
scrimColor = if (showSheetContent) ModalBottomSheetDefaults.scrimColor else Color.Transparent,
sheetContent = {
if (showSheetContent) {
SheetContent()
}
}
) {
Column {
Button(
onClick = {
showSheetContent = true
coroutineScope.launch {
bottomSheetState.show()
}
}
) { ... }
}
}
Would become:
if (showSheetContent) {
LaunchedEffect(Unit) {
bottomSheetState.show()
}
}
ModalBottomSheetLayout(
sheetState = bottomSheetState,
sheetBackgroundColor = if (showSheetContent) Color.Red else Color.Transparent,
scrimColor = if (showSheetContent) ModalBottomSheetDefaults.scrimColor else Color.Transparent,
sheetContent = {
if (showSheetContent) {
SheetContent()
}
}
) {
Column {
Button(
onClick = {
showSheetContent = true
}
) { ... }
}
We'll update this issue once we merge the fix.
Description
all required information.
Android Studio Build: 4.1 canary 8
Version of Gradle Plugin:4.1.0-alpha08
Version of Gradle: 6.3
Version of Java: 8
OS: Android 10
Steps to Reproduce:
1. Create a simple Composable function with a DropDownMenu and a DropDownItem from ui-material
2. Pass a listener through the 'onClick' parameter of DropDownItem
3. The passed listener will never be invoked
Reading the source code of DropDownItem, I found that the cause of the problem is a ripple modifier, applied after the clickable one.