Compose Multiplatform reactive keyboard-aware layout engine.
Compose Multiplatform has historically lacked consistent software keyboard handling across mobile platforms:
- Android —
Modifier.imePadding()behaves inconsistently on foldables, landscape modes, and edge-to-edge gesture navigation. - iOS — The software keyboard overlays Compose content entirely by default without automatic insets.
cmp-keyboard solves this with one declarative composable that works seamlessly everywhere.
Add the JitPack repository and dependency to your build.gradle.kts:
repositories {
maven { url = uri("https://jitpack.io") }
}
dependencies {
implementation("com.github.govindtank:cmp-keyboard:1.0.0")
}import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material3.*
import androidx.compose.runtime.*
import io.github.govindtank.keyboard.KeyboardAware
import io.github.govindtank.keyboard.rememberKeyboardInfo
@Composable
fun ChatScreen() {
val keyboard by rememberKeyboardInfo()
var text by remember { mutableStateOf("") }
KeyboardAware {
Column {
LazyColumn(modifier = Modifier.weight(1f)) {
// message list
}
TextField(value = text, onValueChange = { text = it })
Button(onClick = { /* send */ }) {
Text("Send")
}
}
}
if (keyboard.isVisible) {
Text("Keyboard Height: ${keyboard.height}")
}
}| Platform | Detection Mechanism | Notes |
|---|---|---|
| Android | ViewTreeObserver.OnGlobalLayoutListener |
Works on foldables, landscape, edge-to-edge |
| iOS | UIResponder.keyboardWillShowNotification / keyboardWillHideNotification |
Uses safe-area insets (iOS 15+) |
If you find this project useful, consider supporting its active maintenance and future development:
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Maintained with ❤️ by Govind Tank.