Skip to content

Commit

Permalink
Allow ModalBottomSheet to be dismissed by back press even not idle
Browse files Browse the repository at this point in the history
The error behavior described in the issue is no longer reproducable. This is probably due to all past improvements to Bottom Sheet and Modals.
  • Loading branch information
alexstyl committed Oct 16, 2024
1 parent e120c05 commit a46ee68
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions core/src/commonMain/kotlin/ModalBottomSheet.kt
Original file line number Diff line number Diff line change
Expand Up @@ -145,19 +145,13 @@ public fun ModalBottomSheet(

if (scope.visibleState.currentState || scope.visibleState.targetState || scope.visibleState.isIdle.not()) {

val onKeyEvent: (KeyEvent) -> Boolean = if (scope.sheetState.isIdle && properties.dismissOnBackPress) {
// AnchoredDraggableState jumps to 1.0f progress as soon as we change the current value
// while moving. This causes the sheet to disappear instead of animating away nicely.
// Because of this, we only manage back presses when the sheet is idle
val onKeyEvent: (KeyEvent) -> Boolean = if (properties.dismissOnBackPress) {
{ event ->
when (event.key) {
Key.Back, Key.Escape -> {
scope.sheetState.currentDetent = SheetDetent.Hidden
true
}

else -> false
if (event.key == Key.Back || event.key == Key.Escape) {
scope.sheetState.currentDetent = SheetDetent.Hidden
true
}
else false
}
} else {
{ false }
Expand Down

0 comments on commit a46ee68

Please sign in to comment.