```@Composable private fun MyInputField( modif...
# compose
m
Copy code
@Composable
private fun MyInputField(
    modifier: Modifier = Modifier,
    text: String,
    onTextChanged: (String) -> Unit,
) {
    val focusRequester = remember { FocusRequester() }
    LaunchedEffect(Unit) {
        focusRequester.requestFocus()
    }

    OutlinedTextField(
        modifier = modifier.focusRequester(focusRequester),
        label = { Text(text = "some text") },
        value = text,
        onValueChange = onTextChanged,
    )
}
sometimes keyboard is show and sometimes it is not what that depends on?
d
why do you remember
focusRequester
?
d
Why shouldn't he?
m
I think that you should, error you get about
FocusRequester
tells you to remember it
d
Copy code
val focusRequester = FocusRequester()
    
    TextField(
    ...
    modifier = modifier
        .focusRequester(focusRequester)
    )

    if (requestFocus) {
        DisposableEffect(Unit) {
            focusRequester.requestFocus()
            onDispose { }
        }
    }
that works for me