The XML `SearchView` loses focus when you close th...
# compose
f
The XML
SearchView
loses focus when you close the keyboard. How can I achieve the same behavior in Compose with a
TextField
?
c
We do something like this:
Copy code
val keyboardIsVisible = LocalWindowInsets.current.ime.isVisible
    var keyboardWasVisible by remember {
        mutableStateOf(keyboardIsVisible)
    }

    SideEffect {
        if (!keyboardIsVisible && keyboardWasVisible) {
            LocalFocusManager.current.clearFocus()
        }

        keyboardWasVisible = keyboardIsVisible
    }
You have to setup accompanist-insets for this to work.
👍 1
f
great, thank you very much!