diff --git a/navi-uitron/src/main/java/com/navi/uitron/render/MultiSectionTextFieldRenderer.kt b/navi-uitron/src/main/java/com/navi/uitron/render/MultiSectionTextFieldRenderer.kt index 84b3021..c1a5a42 100644 --- a/navi-uitron/src/main/java/com/navi/uitron/render/MultiSectionTextFieldRenderer.kt +++ b/navi-uitron/src/main/java/com/navi/uitron/render/MultiSectionTextFieldRenderer.kt @@ -73,7 +73,6 @@ class MultiSectionTextFieldRenderer() : Renderer multiSectionTextFieldData = multiSectionTextFieldData?.copyNonNull(dataState.value) ?: dataState.value } - var inputText by remember { mutableStateOf(multiSectionTextFieldData?.inputText.orEmpty()) } @@ -113,9 +112,6 @@ class MultiSectionTextFieldRenderer() : Renderer (0 until property.textFieldPropertyList.size).map { FocusRequester() } } - var lastInput by remember { - mutableStateOf("") - } if (property.visible.orTrue()) { Column( modifier = (modifier ?: Modifier) @@ -170,12 +166,25 @@ class MultiSectionTextFieldRenderer() : Renderer onValueChange = { value -> cursorPosition = value.selection.start if (value.text.isDigitsOnly()) { - if (maxCharList[index] >= value.text.length) { + if (maxCharList[index] > value.text.length) { + inputValues[index].value = value + } else if (maxCharList[index] == value.text.length) { + if (value.text.compareTo(inputValues[index].value.text) != 0 && focusRequesters.getOrNull(index)?.freeFocus() == true) { + focusRequesters.getOrNull(index+1)?.requestFocus() + } inputValues[index].value = value - lastInput = "" } else { if (cursorPosition == maxCharList[index] + 1) { - lastInput = value.text[maxCharList[index]].toString() + val lastInput = value.text[maxCharList[index]].toString() + if (index < property.textFieldPropertyList.size - 1 && maxCharList[index + 1] > inputValues[index + 1].value.text.length && inputValues[index + 1].value.text.isEmpty()) { + inputValues[index + 1].value = TextFieldValue( + text = lastInput + inputValues[index + 1].value.text, + selection = TextRange(maxCharList[index + 1]) + ) + } + } + if (focusRequesters.getOrNull(index)?.freeFocus() == true) { + focusRequesters.getOrNull(index+1)?.requestFocus() } } doOnValueChange( @@ -203,23 +212,10 @@ class MultiSectionTextFieldRenderer() : Renderer .onKeyEvent { event -> val cellValue = inputValues[index].value if (event.type == KeyEventType.KeyUp) { - val maxChar = - property.textFieldPropertyList.getOrNull(index)?.maxChar - ?: defaultMaxCharList[index] if (event.key == Key.Backspace && cellValue.text.isEmpty()) { focusRequesters .getOrNull(index - 1) ?.requestFocus() - } else if (event.key != Key.Backspace && cellValue.text.length.compareTo(maxChar) == 0) { - focusRequesters - .getOrNull(index + 1) - ?.requestFocus() - if (index < property.textFieldPropertyList.size - 1 && maxCharList[index + 1] > inputValues[index + 1].value.text.length && inputValues[index + 1].value.text.isEmpty()) { - inputValues[index + 1].value = TextFieldValue( - text = lastInput + inputValues[index + 1].value.text, - selection = TextRange(maxCharList[index + 1]) - ) - } } } false