fix #625: handle Samsung Keyboard dot-minus key in TextField validation

Samsung Keyboard numerical keypad features a combined '.-' key that outputs a dot (.) on first press and replaces it with a minus (-) on second press. there is no option to output each symbol separately (short or long press, etc).

updated validation logic to handle dot symbol at the start of the input string.
This commit is contained in:
andrekir
2023-04-26 18:21:27 -03:00
parent ab46bf6ab9
commit c821eb3681

View File

@@ -101,6 +101,7 @@ fun EditTextPreference(
modifier: Modifier = Modifier,
) {
var valueState by remember(value) { mutableStateOf(value.toString()) }
val decimalSeparators = setOf('.', ',', '٫', '、', '·') // set of possible decimal separators
EditTextPreference(
title = title,
@@ -112,7 +113,7 @@ fun EditTextPreference(
),
keyboardActions = keyboardActions,
onValueChanged = {
if (it.isEmpty()) valueState = it
if (it.length <= 1 || it.first() in decimalSeparators) valueState = it
else it.toDoubleOrNull()?.let { double ->
valueState = it
onValueChanged(double)