Hide keyboard on app resume

This commit is contained in:
Jon Staab
2026-05-06 12:48:15 -07:00
parent 99fe0e543c
commit 6f731e48d2
+8
View File
@@ -1,3 +1,4 @@
import {App} from "@capacitor/app"
import {Capacitor} from "@capacitor/core"
import {Keyboard} from "@capacitor/keyboard"
import {noop} from "@welshman/lib"
@@ -13,9 +14,16 @@ export const syncKeyboard = () => {
document.body.classList.remove("keyboard-open")
})
// On Android, system-dismissing the IME during pause doesn't fire keyboardWillHide,
// so on resume we force a hide to re-sync native insets and clear our CSS state.
const resumeListener = App.addListener("appStateChange", ({isActive}) => {
if (isActive) Keyboard.hide()
})
return () => {
showListener.then(listener => listener.remove())
hideListener.then(listener => listener.remove())
resumeListener.then(listener => listener.remove())
document.body.classList.remove("keyboard-open")
}
}