androidandroid-jetpack-composeandroid-compose-textfield

How to know when a Composable like TextField gains focus?


I want to trigger a function upon my TextField's focus-gain, but I am unable to find something like a listener.


Solution

  • You can use the onFocusChanged modifier

    TextField(
        value = text,
        onValueChange = { text = it},
        modifier = Modifier.onFocusChanged {
            if (it.isFocused){
                //...
            }
        }
    )