Syex
03/05/2021, 9:31 AMTextField
and a Button
. Upon a click on the button I want to clear the focus from the TextField
so the keyboard disappears. I'm currently trying
Button(
onClick = {
FocusRequester.Default.freeFocus()
}
)
This crashes the app with
java.lang.IllegalStateException: FocusRequester is not initialized. One reason for this is that you requesting focus changes during composition. Focus requesters should not be made during composition, but should be made in response to some event.Is there any other way to achieve this?
Modifier
modifier = Modifier
.focusRequester(FocusRequester.Default)
.focusable()
And then requestFocus()
in onClick()
Cyril Find
03/05/2021, 10:07 AMval focusManager = LocalFocusManager.current
//...
onClick = { focusManager.clearFocus() })
Syex
03/05/2021, 10:08 AMonClick = { LocalFocusManager.current.clearFocus() }
which just gives you an error without message, but declaring the variable outside works I just saw 🙈Landerl Young
03/05/2021, 10:14 AMSyex
03/05/2021, 10:16 AMLanderl Young
03/05/2021, 10:18 AMSyex
03/05/2021, 10:19 AMCompositionLocal
though, TIL