I want to capture InputConnection of TextField on focus change, the method was onCreateInputConnection in EditText. Is there such method? How to achieve it without using AndroidView?
Tried this but doesn't work either.
@Composable
fun KeyboardScreen() {
val rootView = LocalView.current
...
Button(onClick = {
val inputConnection = BaseInputConnection(rootView, true)
inputConnection.commitText("hello", 5)
}) {
Text(text = "test")
}
That's nearly impossible at this point. I'm afraid you have to wrap the edit text. This is because LocalTextInputService is staticCompositionLocalOf and will cause all other composable to recompose and have the input service changed.
That would require you to write your own implementations of PlatformTextInputService and TextInputService class.
Then you need to provide the instance to the LocalTextInputService composition provider like:
class MyTextInputService : PlatformTextInputService {
}
class MyInputService : TextInputService(MyTextInputService()) {
}
@Composable
fun CustomInputServiceTextField(...){
val inputService = remember { MyInputService() }
CompositionLocalProvider(LocalTextInputService provides inputService) {
TextField(value = ..., onValueChange = ...)
}
}
This is just an idea.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With