Jetpack Compose TextField in ModalBottomSheetLayout, keyboard won't hide automatically

1.1k Views Asked by At

If hide the bottom sheet by drag gesture then keyboard won't hide automatically

enter image description here

enter image description here

How can I fix it?

1

There are 1 best solutions below

2
On BEST ANSWER

Since you haven't shared any code here, this is how I would have handle this issue:

Use the Disposable Effect and onDispose handle the keyboard hiding

Sample Code:

...
val keyboardController = LocalSoftwareKeyboardController.current

  DisposableEffect(key1 = modalBottomSheetState.isVisible, effect = {
        onDispose {
            keyboardController?.hide()
        }
    })
...

The LocalSoftwareKeyboardController is marked as Experimental so you can also do the following:

...
 val focusManager = LocalFocusManager.current

  DisposableEffect(key1 = modalBottomSheetState.isVisible, effect = {
        onDispose {
             focusManager.clearFocus()
        }
    })
...