From 54b8d96245f1f92636542744ba91d11b1ef5f6a3 Mon Sep 17 00:00:00 2001 From: dankito Date: Fri, 6 Sep 2024 18:21:57 +0200 Subject: [PATCH] Fixed that both called onEnterPressed(), KeyboardActions.onDone and Modifier.onKeyEvent, resulting in that e.g. an account got added twice --- .../banking/ui/forms/OutlinedTextField.kt | 22 +------------------ 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/forms/OutlinedTextField.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/forms/OutlinedTextField.kt index 23d70be..8d50c89 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/forms/OutlinedTextField.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/forms/OutlinedTextField.kt @@ -8,15 +8,10 @@ import androidx.compose.runtime.* import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Shape -import androidx.compose.ui.input.key.* import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.input.ImeAction import androidx.compose.ui.text.input.VisualTransformation -import kotlinx.coroutines.Job import net.codinux.banking.ui.config.Colors -import net.codinux.banking.ui.config.DI - -private val uiService = DI.uiService @OptIn(ExperimentalComposeUiApi::class) @Composable @@ -50,25 +45,10 @@ fun OutlinedTextField( focusedLabelColor = Colors.CodinuxSecondaryColor // does not work ) - var debounceJob by remember { mutableStateOf(null) } - - val coroutineScope = rememberCoroutineScope() - androidx.compose.material.OutlinedTextField( value = value, onValueChange = onValueChange, - modifier = modifier.onKeyEvent { event -> // onKeyEvent only handle input on hardware keyboards - if (onEnterPressed != null && event.type == KeyEventType.KeyUp && (event.key == Key.Enter || event.key == Key.NumPadEnter)) { - debounceJob?.cancel() - debounceJob = uiService.debounce(coroutineScope) { - onEnterPressed() - } - - true - } else { - false - } - }, + modifier = modifier, enabled = enabled, readOnly = readOnly, textStyle = textStyle,