golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
124.16k stars 17.69k forks source link

x/mobile: key events not fired for predictive keyboards #38179

Open andydotxyz opened 4 years ago

andydotxyz commented 4 years ago

On a Samsing Galaxy S10, running Android 10 (this was not an issue with the keyboard they shipped in Android 9) key events are no longer fired when the (default) predictive text is turned on. Some other apps, such as Termux (https://github.com/termux/termux-app/issues/686) report that words appear after space/enter etc - however that is not true for gomobile. Each time a word should display a single "unknown key code" event is fired and no characters.

What version of Go are you using (go version)?

1.12, 1.13, 1.14

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

I think the environment on the Android phone is most relevant, but I don't know what to provide. Code works fine on older keyboards, or if you turn off the predictive text

What did you do?

What did you expect to see?

I want to see characters as they are entered. There are various docs about how to disable prediction (such as https://developer.android.com/reference/android/text/InputType#TYPE_NULL) but I cannot figure out how to set those options in a default gomobile app, as the root view does not seem to be configurable in GoNativeActivity.java.

What did you see instead?

(as above)

andydotxyz commented 4 years ago

I have managed to force disabling of prediction by using a hidden EditText and setting the input type: textEdit.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);

However this does not generate any key events when typing.

andydotxyz commented 4 years ago

The only progress I have made is using the EditText workaround, pack one into the view hierarchy, then you can add a change watcher:

mTextEdit.addTextChangedListener(new TextWatcher() {
        @Override
        public void onTextChanged(...) {
// here we can get the current state of the text field...
});

Unfortunately I cannot figure out how to reverse-engineer key events, it is reporting the current state. But it's a start...

andydotxyz commented 4 years ago

I followed that line of thought for a while but then realised that normal keyboard will get double-events because they get keys as well. This feels like a very complex situation. Any experts got thoughts? :)

andybons commented 4 years ago

@hyangah