Status Update
Comments
ha...@gmail.com <ha...@gmail.com> #2
Branch: androidx-master-dev
commit 23a7d960caf43390a554700d3c56ada189a9d10e
Author: Louis Pullen-Freilich <lpf@google.com>
Date: Mon Aug 10 15:11:36 2020
IconButton / IconToggleButton API scrub
Test: ./gradlew updateApi
Bug:
Bug:
Relnote: "Adds enabled parameter to IconButton, and reorders parameters in IconToggleButton"
Change-Id: I0a9419b1a631cadad451395302ad87b7f9214f96
M ui/ui-material/api/current.txt
M ui/ui-material/api/public_plus_experimental_current.txt
M ui/ui-material/api/restricted_current.txt
M ui/ui-material/src/commonMain/kotlin/androidx/compose/material/IconButton.kt
jo...@google.com <jo...@google.com> #3
Thanks for the report. Do you have an isolated repro?
jo...@google.com <jo...@google.com> #4
You do - apologies, I missed that. We'll check it out! :)
jo...@google.com <jo...@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.
jo...@google.com <jo...@google.com> #6
I'll add that the bottom sheet "floats" above the bottom of the screen
Would you mind filing a separate issue for this? I wasn't able to reproduce it yet.
ha...@gmail.com <ha...@gmail.com> #7
Thanks for the quick reply!
Would you mind filing a separate issue for this?
Sure, I'll see if I can figure out in which specific conditions it happens and open a new issue
jo...@google.com <jo...@google.com> #8
Thanks! I found a repro (and the cause) for this so just an issue without a repro is totally fine :)
ha...@gmail.com <ha...@gmail.com> #9
Here's the new issue
For some completeness I added a video and a link to the same repo as in this issue
ap...@google.com <ap...@google.com> #10
Branch: androidx-main
commit 43ba01d4fc84edb9495a2089090bcd2f786be743
Author: Jossi Wolf <jossiwolf@google.com>
Date: Mon Jan 16 12:11:00 2023
Handle absence of previous target in ModalBottomSheetAnchorChangeHandler
When we animate or snap, we update the currentValue regardless of whether it exists in the anchors. If ModalBottomSheetState was moved to a visible value (HalfExpanded or Expanded) while only having a hidden anchor (when the sheet content is empty), we would crash in the AnchorChangeHandler because we required the previous target to be present in the previous set of anchors.
Test: modalBottomSheet_shortSheet_anchorChangeHandler_previousTargetNotInAnchors_reconciles, modalBottomSheet_tallSheet_anchorChangeHandler_previousTargetNotInAnchors_reconciles
Relnote: Fixed a bug in ModalBottomSheetLayout where the sheet would crash when going from the hidden to a visible state in some circumstances.
Bug: 265444789
Change-Id: Ia926514a65dc4d2c44781e132f8faae7e442cf68
M compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/ModalBottomSheetTest.kt
M compose/material/material/src/commonMain/kotlin/androidx/compose/material/ModalBottomSheet.kt
jo...@google.com <jo...@google.com>
ha...@gmail.com <ha...@gmail.com> #11
Does this also fix the crash I described in
jo...@google.com <jo...@google.com> #12
Yep, it also fixes that :)
ha...@gmail.com <ha...@gmail.com> #13
Awesome :)
pr...@google.com <pr...@google.com> #14
The following release(s) address this bug.It is possible this bug has only been partially addressed:
androidx.compose.material:material:1.4.0-alpha05
Description
Jetpack Compose version: 1.4.0-alpha04
Jetpack Compose component used: ModalBottomSheetLayout
Android Studio Build: Electric Eel 2022.1.1 #AI-221.6008.13.2211.9477386
Kotlin version: 1.7.21
Repo:https://github.com/hakonschia/bottomsheetcrash
The updated ModalBottomSheetLayout in 1.4.0-alpha04 seems to have some issues. I have observed two cases where it crashes with
Key HalfExpanded is missing in the map
. The linked repo contains both scenarios.First scenario:
I'll add that the bottom sheet "floats" above the bottom of the screen, which seems like a new bug introduced in alpha04. In the example repo this only happens when the sheet is opened in landscape. If I open it in portrait and then rotate, it doesn't happen. It also doesn't crash in this case, so it seems this might be related. This is visible in the video attached.
Second scenario:
The updated ModalBottomSheetLayout is supposed to support empty sheet content, but when going from empty content to some content it crashes.
Steps to reproduce:
I'll add here that I have had to do this hack with empty content to avoid the bottom sheet sometimes being visible when it shouldn't, for example when resizing the window in Picture-in-Picture mode (which might be related to https://issuetracker.google.com/issues/260517771 ). I've added a button to enter PiP where this issue can be seen by removing the logic to not render the content when not visible.
Adding
Spacer(Modifier.height(1.dp))
fixes this crash, which is what I had to do previously anyways since empty content wasn't supported, but I'd like to remove this hack.Stack trace (if applicable):