0

When i set keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number) or even KeyboardOptions.Default.copy(keyboardType = KeyboardType.Number), the onValueChange callback is not triggerd.

Versions:

software version
Compose compiler 1.4.6
Compose UI 1.4.3
Kotlin 1.8.2

Kotlin code:

import android.util.Log
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material3.OutlinedTextField
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.text.input.KeyboardType

@Composable
fun TestNumberInput() {
    var numbers by remember {
        mutableStateOf("")
    }

    OutlinedTextField(
        value = numbers, 
        onValueChange = { 
            Log.i("TEST", "numbers: $numbers")
            numbers = it
        }, 
        keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number)
    )
}

There is already a question on stackoverflow about this problem but the cause seems to come from somewhere else then the problem i have.

Damian
  • 13
  • 4
  • It seems there is no problem in the code. I just tested the code with versions you provided, onValueChange is correctly invoked. – ObscureCookie Jul 19 '23 at 13:58
  • Thank you. I noticed that when keyboardType is number, Activity.dispatchKeyEvent is triggerd which i have overriden. I couldn't found this in the documentation , but maybe this is some sort of standard. Anyway I have adjusted dispatchKeyevent to handle the numeric keyboard and now the value is send to the TextField. – Damian Jul 19 '23 at 14:53

0 Answers0