Tiny Compose Multiplatform utility for reading the current environment's factual interaction capabilities.
Use it when a design system needs to adapt component sizing, spacing, or interaction affordances based on whether touch, pointer, or keyboard input is available.
This is a small helper library until Compose media query APIs are stable and available across Compose Multiplatform targets.
dependencies {
implementation("com.composables:compose-interaction-capabilities:1.0.0")
}import androidx.compose.runtime.Composable
import com.composables.interactioncapabilities.currentInteractionCapabilities
@Composable
fun Component() {
val capabilities = currentInteractionCapabilities()
val useTouchSizes = capabilities.hasTouch
// Map capabilities to your own design-system sizing rules.
}- Web and Wasm use browser media queries:
hasTouch = matchMedia("(any-pointer: coarse)").matcheshasPointer = matchMedia("(any-pointer: fine)").matcheshasKeyboard = true- Compose state updates when the media query result changes.
- JVM Desktop uses AWT to detect headless environments and pointer availability.
hasTouchremainsfalsebecause standard JVM/AWT does not expose a reliable touch capability query.hasKeyboardreports whether desktop keyboard input is available through AWT, not a low-level hardware inventory. - Android checks
PackageManagerfor touch support andInputDevice/configuration for pointer and keyboard devices. The conservative baseline is touch-first. - iOS returns
hasTouch = true,hasPointer = false, and usesGCKeyboardto report whether a hardware keyboard is currently connected. Pointer remains conservative because iOS/iPadOS exposes pointer interactions and events, not a reliable public connected-pointer query for this tiny Compose-only API.
- Android
- JVM Desktop
- JS browser
- WasmJS browser
- iOS Arm64
- iOS Simulator Arm64
The :demo project renders the current InteractionCapabilities result using the published API from this repository.
./gradlew :demo:run
./gradlew :demo:jsBrowserDevelopmentRun
./gradlew :demo:wasmJsBrowserDevelopmentRun
./gradlew :demo:installDebugFor iOS, the demo module builds an InteractionCapabilitiesDemo framework with a MainViewController() entry point.