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 a413abe
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 22 deletions.
13 changes: 5 additions & 8 deletions core/src/commonMain/kotlin/Dialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,13 @@ public fun Dialog(
}

if (scope.visibleState.currentState || scope.visibleState.targetState || scope.visibleState.isIdle.not()) {
val onKeyEvent: ((KeyEvent) -> Boolean) = if (properties.dismissOnBackPress) {
val onKeyEvent = if (properties.dismissOnBackPress) {
{ event: KeyEvent ->
when (event.key) {
Key.Back, Key.Escape -> {
scope.dialogState.visible = false
true
}

else -> false
if (event.key == Key.Back || event.key == Key.Escape) {
scope.dialogState.visible = false
true
}
else false
}
} else {
{ false }
Expand Down
20 changes: 6 additions & 14 deletions core/src/commonMain/kotlin/ModalBottomSheet.kt
Original file line number Diff line number Diff line change
Expand Up @@ -144,20 +144,12 @@ public fun ModalBottomSheet(
scope.visibleState.targetState = state.currentDetent != SheetDetent.Hidden

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
{ event ->
when (event.key) {
Key.Back, Key.Escape -> {
scope.sheetState.currentDetent = SheetDetent.Hidden
true
}

else -> false
}
val onKeyEvent = if (properties.dismissOnBackPress) {
{ event: KeyEvent ->
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 a413abe

Please sign in to comment.