|
@@ -193,16 +193,22 @@ fun ColumnScope.OTPFields() {
|
|
|
TextField(
|
|
|
value = otpValues[index],
|
|
|
onValueChange = { newValue ->
|
|
|
- if (newValue.length <= 1) {
|
|
|
- otpValues[index] = newValue
|
|
|
- if (newValue.isNotEmpty() && index < otpLength - 1) {
|
|
|
- Log.d("test_otp_event", "newValue = ${otpValues[index]}")
|
|
|
- focusManager.moveFocus(FocusDirection.Next)
|
|
|
+ if (newValue.length <= otpLength) {
|
|
|
+ if (newValue.length == 1) {
|
|
|
+ otpValues[index] = newValue
|
|
|
+ if (index != otpLength -1) {
|
|
|
+ focusManager.moveFocus(FocusDirection.Next)
|
|
|
+ } else {
|
|
|
+ focusManager.clearFocus()
|
|
|
+ keyboardController?.hide()
|
|
|
+ }
|
|
|
+ } else if (newValue.length == otpLength) {
|
|
|
+ newValue.forEachIndexed { i, c ->
|
|
|
+ if (i < otpLength) otpValues[i] = c.toString()
|
|
|
+ }
|
|
|
+ focusManager.clearFocus()
|
|
|
+ keyboardController?.hide()
|
|
|
}
|
|
|
-// else if (index == otpLength -1) {
|
|
|
-// focusManager.clearFocus()
|
|
|
-// keyboardController?.hide()
|
|
|
-// }
|
|
|
}
|
|
|
},
|
|
|
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number),
|
|
@@ -228,16 +234,17 @@ fun ColumnScope.OTPFields() {
|
|
|
if (event.key == Key.Backspace) {
|
|
|
if (index > 0) {
|
|
|
Log.d("test_otp_event", "Inside otp event")
|
|
|
- if (index < otpLength) {
|
|
|
- focusManager.moveFocus(FocusDirection.Previous)
|
|
|
- otpValues[index - 1] = ""
|
|
|
- }
|
|
|
-// else if (otpValues[index].isNotEmpty()) {
|
|
|
-// otpValues[index] = ""
|
|
|
-// } else {
|
|
|
-// focusManager.moveFocus(FocusDirection.Previous)
|
|
|
-// otpValues[index - 1] = ""
|
|
|
-// }
|
|
|
+ if (index == otpLength -1) {
|
|
|
+ if (otpValues[index].isNotEmpty()) {
|
|
|
+ otpValues[index] = ""
|
|
|
+ } else {
|
|
|
+ focusManager.moveFocus(FocusDirection.Previous)
|
|
|
+ otpValues[index - 1] = ""
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ focusManager.moveFocus(FocusDirection.Previous)
|
|
|
+ otpValues[index - 1] = ""
|
|
|
+ }
|
|
|
}
|
|
|
true
|
|
|
}
|