Fixed that both called onEnterPressed(), KeyboardActions.onDone and Modifier.onKeyEvent, resulting in that e.g. an account got added twice

This commit is contained in:
dankito 2024-09-06 18:21:57 +02:00
parent 0f1acdc519
commit 54b8d96245
1 changed files with 1 additions and 21 deletions

View File

@ -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<Job?>(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,