#Is there a specific channel for Compose

1 messages · Page 1 of 1 (latest)

native belfry
#

idk just posting it here, is anyone facing similar issue post the latest update : https://stackoverflow.com/q/67687674/6462865 the onValueChange lambda is not getting invoked on my textfield if the keyboard type is set to number, its pretty strange, if anyone here encountered similar issue please suggest a fix or other suggestions.

native belfry
#

The special character in the same keyboard is working as expected just not the numbers.

native sentinel
#

Hi @native belfry , you want the normal keyboard to open in the area where text will be entered. Right?

#

I think we can check this by putting an if-else check in the keyboardOptions of the TextField. Accordingly, we can change it to KeyboardType.Number or KeyboardType.Text.

#
@Composable
fun MyTextField() {
    var isNumericKeyboard by remember { mutableStateOf(true) }
    var myTextValue by remember { mutableStateOf("") }

    Column {
        TextField(
            value = textValue,
            onValueChange = { newValue ->
                myTextValue = newValue
            },
            keyboardOptions = {
                KeyboardOptions(keyboardType = if (isNumericKeyboard) KeyboardType.Number else KeyboardType.Text)
            }
        )
        Button(onClick = {
            isNumericKeyboard = false 
        }) {
            Text("Hello!")
        }
    }
}
#

I don't know if it will work correctly but you can try it.

native sentinel
#

And btw there is no specific Compose channel here. You can write this channel your question about Compose.

native belfry
native belfry
native sentinel
#

the video didn't work for me

native sentinel
native belfry
#

it seems to be an extreme isolated bug have rolled back to the 2023.10 bom and it works as expected.

native sentinel
#

So you solved the problem?

native sentinel
#

In Compose, InputInteractionState can be used to track the interaction state that is triggered when you click or navigate away from a TextField. This status can be used to monitor whether a TextField has focus. If the TextField has focus and the user presses a key, it can track that state.

val interactionSource = remember { MutableInteractionSource() }
val isFocused by interactionSource.collectIsFocusedAsState()

val textValue by remember { mutableStateOf(TextFieldValue("")) }

TextField(
    value = textValue,
    onValueChange = {
        textValue = it
    },
    keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number),
    interactionSource = interactionSource
)

if (isFocused) {
    // If the TextField has focus, you can do something here.
}
#

maybe this could work

native belfry