Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to type text in interactive mode in Jetpack Compose

I am trying to type text into a text field in interactive mode and it's not working. But, doing it on a physical device works.

MainActivity.kt

@Preview(showSystemUi = true)
@Composable
fun HelloContentPreview()
{
    HelloContent()
}


@Composable
fun HelloContent()
{
    Column(modifier = Modifier.padding(16.dp)) {
        var name by remember { mutableStateOf("") }
        Text(
            text = "Hello! $name",
            modifier = Modifier.padding(bottom = 8.dp),
            style = MaterialTheme.typography.h5
        )
        OutlinedTextField(
            value = name,
            onValueChange = {
                name = it
                Log.i(TAG, "HelloContent: onValueChange: $it")
            },
            label = { Text("Name") }
        )
    }
}

Interactive mode enter image description here

like image 548
Tayyab Mazhar Avatar asked Jan 20 '26 02:01

Tayyab Mazhar


1 Answers

Based on the answer in IssueTracker https://issuetracker.google.com/u/1/issues/236149640#comment8

This problem is fixed for now. At least for me, it works.

PS If it doesn't work for you, ensure you've changed the text value in the onValueChange callback in your @Preview composite! Like this:

@Preview(showBackground = true)
@Composable
private fun InputPrev() {
    var textValue by remember { mutableStateOf("Text") }
    MainTextInputField(
        text = textValue,
        onValueChange = {
            textValue = it
        }
    )
}
like image 191
Oleh Kuchura Avatar answered Jan 21 '26 16:01

Oleh Kuchura



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!