KeyboardForTV is a Jetpack Compose library designed specifically for Android TV applications. It provides a customizable on-screen keyboard with support for D-pad navigation, optimized for TV interfaces.
- TV-Optimized: Built with
androidx.tvlibraries, ensuring smooth D-pad navigation and focus handling. - Multi-language Support: Includes built-in support for English and Persian layouts, with easy switching.
- Jetpack Compose: Fully composable and easy to integrate into modern Android apps.
- Isolated Dependency Injection: Uses Koin with an isolated context to ensure no conflicts with the host application's DI graph.
- Customizable Actions: callbacks for search query changes and voice search triggers.
- Android minSdk 21
- Jetpack Compose (compatible with BOM 2024.12.01 or later)
- Koin (internally used)
Integrate the Keyboard composable into your screen. The Keyboard component handles its own state (view
model) internally using an isolated Koin context.
import ir.myket.keyboard.Keyboard
...
@Composable
fun SearchScreen() {
var searchQuery by remember { mutableStateOf("") }
Column {
// ... Your UI content
Keyboard(
columnCount = 10, // Number of keys in a row
onSearchQueryChange = { query ->
// Handle the updated search query (e.g., filter a list)
searchQuery = query
},
)
}
}| Parameter | Type | Description |
|---|---|---|
modifier |
Modifier |
Modifier to be applied to the layout. |
columnCount |
Int |
Defines the number of columns in the keyboard grid. |
onSearchQueryChange |
(String) -> Unit |
Callback triggered whenever the input text changes (character added or removed). |
The project is built using modern Android development practices:
- Language: Kotlin
- UI Framework: Jetpack Compose (with
androidx.tvcomponents). - Dependency Injection: Koin (using
KoinIsolatedContextto encapsulate the library's dependencies). - Architecture: MVVM (Model-View-ViewModel) pattern.
KeyboardViewModel: Manages the state of the search query and keyboard actions.ActionableViewModel: Base class for handling ViewModel actions via flows.
components: Contains individual UI components like keys (CharacterItem,ImageItem) and theSearchBox.di: Koin configuration (KeyboardIsolatedKoinContext).models: data classes representing keyboard keys and layouts (KeyboardItems).utils: Extension functions and helper utilities.viewmodels: State management logic.