Reputation: 790
I have a TextField
and a ModalDrawer
in a compose screen. I would like to close the soft keyboard when the user opens the drawer, but I haven't been able to figure out how. There is no onOpened
lifecycle event that gets triggered in ModalDrawer
afaik.
Upvotes: 3
Views: 1594
Reputation: 282
You can use the confirmStateChange parameter in rememberDrawerState() and call keyboardController.hide() when the drawerValue becomes DrawerValue.open like this:
val keyboardController = LocalSoftwareKeyboardController.current
val state = rememberDrawerState(
initialValue = DrawerValue.Closed,
confirmStateChange = {
if (it == DrawerValue.Open) {
keyboardController?.hide()
}
true
}
)
ModalDrawer(
drawerState = state,
...
) {
...
}
Upvotes: 4