I've been trying to figure out how to capitalize letters in my custom IME keyboard. I created capitalize key but I don't know what I have to put into
clickable(interactionSource = interactionSource, indication = null)
Maybe someone knows more how works with keyboard in Compose. Do you guys know how to achieve this in Jetpack Compose?
@Composable
fun KeyboardKeyCaps(
keyboardKey: String, viewKeyboard: KeyboardViewModel
) {
val interactionSource = remember { MutableInteractionSource() }
val pressed = interactionSource.collectIsPressedAsState()
val context = LocalContext.current
val viewmodel = viewKeyboard
val color by viewmodel.colorKeys.collectAsState()
Box(contentAlignment = Alignment.Center) {
Text(keyboardKey,
Modifier
.background(Color(android.graphics.Color.parseColor("#" + color)))
.border(3.dp, Color.Black)
.clickable(interactionSource = interactionSource, indication = null) {
(context as IMEService).currentInputConnection.let {
}
}
.padding(
start = 12.dp, end = 12.dp, top = 16.dp, bottom = 16.dp
)
)
if (pressed.value) {
Text(
keyboardKey,
Modifier
.border(1.dp, Color.Black)
.background(Color.Gray)
.padding(
start = 13.dp, end = 13.dp, top = 17.dp, bottom = 17.dp
)
)
}
}
}
Usual Key
@Composable
fun KeyboardKey(
keyboardKey: String, viewKeyboard: KeyboardViewModel
) {
val interactionSource = remember { MutableInteractionSource() }
val pressed = interactionSource.collectIsPressedAsState()
val context = LocalContext.current
val viewmodel = viewKeyboard
val color by viewmodel.colorKeys.collectAsState()
Box(contentAlignment = Alignment.Center) {
Text(keyboardKey,
Modifier
.background(Color(android.graphics.Color.parseColor("#" + color)))
.border(3.dp, Color.Black)
.clickable(interactionSource = interactionSource, indication = null) {
(context as IMEService).currentInputConnection.commitText(
keyboardKey, 0
)
}
.padding(
start = 12.dp, end = 12.dp, top = 16.dp, bottom = 16.dp
)
)
if (pressed.value) {
Text(
keyboardKey,
Modifier.graphicsLayer(clip = false)
.border(1.dp, Color.Black)
.background(Color.Gray)
.padding(
start = 16.dp, end = 16.dp, top = 36.dp, bottom = 16.dp
)
)
}
}
}
Screenshots
https://github.com/IBRUTALI/KeyboardApp There is the best example How to capitalize key in compose.