Hello! I want to set focus on input and show a key...
# compose
s
Hello! I want to set focus on input and show a keyboard when the screen is showed. I want to implement this behavior on a number of screens and I want to reduce code duplication with FocusRequester and LaunchedEffect. Is it correct to create requestFocus modifier like this?
Copy code
fun Modifier.requestFocus(requester: FocusRequester = FocusRequester()): Modifier = composed {
    LaunchedEffect(requester) {
        requester.requestFocus()
    }

    focusRequester(requester)
}
z
That looks correct, yes. Whether it’s a pattern that will get you into trouble as you scale, idk. But I’d probably give it a more descriptive name at the very least (eg
requestFocusImmediately
)
s
@Zach Klippenstein (he/him) [MOD] thanks for your feedback!