JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
15.9k stars 1.16k forks source link

JS TextInput is not changing by hardware keyboard if there is LocalTextInputService #3940

Open hondogo opened 10 months ago

hondogo commented 10 months ago

Describe the bug When there is custom local TextInputService then no changes happening while inputting chars by hardware keyboard (only backspace affecting - removing last char before cursor per press). While the same code for JVM platform works correctly.

Affected platforms

Versions

To Reproduce

@OptIn(ExperimentalComposeUiApi::class)
@Composable
fun testKeyboard() {
    val testTextInputService = remember { TestTextInputService() }
    val inputService = remember(testTextInputService) { TextInputService(testTextInputService) }
    CompositionLocalProvider(
        LocalTextInputService provides inputService,
        LocalSoftwareKeyboardController provides testTextInputService
    ) {
        var v by remember { mutableStateOf("initial text") }
        TextField(
            value = v,
            onValueChange = { v = it }
        )
    }
}

@OptIn(ExperimentalComposeUiApi::class)
@Stable
class TestTextInputService(
) : PlatformTextInputService, SoftwareKeyboardController {

    var visible by mutableStateOf(false)

    override fun hide() {
        visible = false
    }

    override fun show() {
        visible = true
    }

    @Deprecated(message = "", replaceWith = ReplaceWith("hide()"))
    override fun hideSoftwareKeyboard() {
        hide()
    }

    @Deprecated(message = "", replaceWith = ReplaceWith("hide()"))
    override fun showSoftwareKeyboard() {
        show()
    }

    override fun startInput(value: TextFieldValue, imeOptions: ImeOptions, onEditCommand: (List<EditCommand>) -> Unit, onImeActionPerformed: (ImeAction) -> Unit) {
    }

    override fun stopInput() {
    }

    override fun updateState(oldValue: TextFieldValue?, newValue: TextFieldValue) {
    }
}

Expected behavior Text also changing while inputting it through hardware keyboard

okushnikov commented 2 weeks ago

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.