Skip to content

Commit

Permalink
Add explicit KeyDown check for dismissOnBackPress
Browse files Browse the repository at this point in the history
  • Loading branch information
alexstyl committed Oct 16, 2024
1 parent a78780d commit dc51bd3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
9 changes: 3 additions & 6 deletions core/src/commonMain/kotlin/Dialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.key.Key
import androidx.compose.ui.input.key.KeyEvent
import androidx.compose.ui.input.key.key
import androidx.compose.ui.input.key.*
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.semantics.dialog
import androidx.compose.ui.semantics.semantics
Expand Down Expand Up @@ -85,11 +83,10 @@ public fun Dialog(
if (scope.visibleState.currentState || scope.visibleState.targetState || scope.visibleState.isIdle.not()) {
val onKeyEvent = if (properties.dismissOnBackPress) {
{ event: KeyEvent ->
if (event.key == Key.Back || event.key == Key.Escape) {
if (event.type == KeyEventType.KeyDown && (event.key == Key.Back || event.key == Key.Escape)) {
scope.dialogState.visible = false
true
}
else false
} else false
}
} else {
{ false }
Expand Down
6 changes: 2 additions & 4 deletions core/src/commonMain/kotlin/ModalBottomSheet.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ import androidx.compose.runtime.saveable.mapSaver
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.key.Key
import androidx.compose.ui.input.key.KeyEvent
import androidx.compose.ui.input.key.key
import androidx.compose.ui.input.key.*
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
Expand Down Expand Up @@ -146,7 +144,7 @@ public fun ModalBottomSheet(
if (scope.visibleState.currentState || scope.visibleState.targetState || scope.visibleState.isIdle.not()) {
val onKeyEvent = if (properties.dismissOnBackPress) {
{ event: KeyEvent ->
if (event.key == Key.Back || event.key == Key.Escape) {
if (event.type == KeyEventType.KeyDown && (event.key == Key.Back || event.key == Key.Escape)) {
scope.sheetState.currentDetent = SheetDetent.Hidden
true
} else false
Expand Down

0 comments on commit dc51bd3

Please sign in to comment.