Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SDL_StartTextInputWithProperties not updating input type on android #11448

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Susko3
Copy link
Contributor

@Susko3 Susko3 commented Nov 11, 2024

Description

RFC, not final PR. MVP that fixes this on Android.

Fixes SDL_StartTextInputWithProperties so that the requested SDL_PROP_TEXTINPUT_TYPE_NUMBER is always applied. Tested on Android. Previously, if a screen keyboard was already shown (eg. text input already active), the properties would be ignored.

This change allows the following application code to work:

// user clicks a regular textbox so the app starts normal text input
SDL_StartTextInputWithProperties(window, /* SDL_TEXTINPUT_TYPE_TEXT */);
// Android: the screen keyboard is shown and has text type

// some time later

// user clicks a number textbox so the app wants to change the text input type
// importantly, SDL_StopTextInput() was not called
SDL_StartTextInputWithProperties(window, /* SDL_TEXTINPUT_TYPE_NUMBER */);
// Android: the screen keyboard is updated to have number type [fixed by this PR]

Does this series of calls make sense from an API standpoint? Do you think the application should call SDL_StartTextInputWithProperties()SDL_StopTextInput()SDL_StartTextInputWithProperties()? (Seems less ideal, as it might flick the keyboard unnecessarily.)

I've not checked that calling ShowScreenKeyboard() when the keyboard is already shown works as expected on other platforms (only Android is tested and updated).

Existing Issue(s)

Calls to SDL_StartTextInputWithProperties when text input is already active will be ignored by android (the keyboard type presented to the user will not change).

if (AutoShowingScreenKeyboard() && !SDL_ScreenKeyboardShown(window)) {
if (AutoShowingScreenKeyboard()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was the SDL_ScreenKeyboardShown() check originally here? It was correct for SDL_StartTextInput(), but now that SDL_StartTextInputWithProperties() is a thing, this check no longer makes sense.

If the props have changed, ShowScreenKeyboard (or a new update method) should be called to communicate the updated keyboard type to the platform layer.

@@ -1422,6 +1422,7 @@ public void run() {
mTextEdit.requestFocus();

InputMethodManager imm = (InputMethodManager) SDL.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.restartInput(mTextEdit);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works, but it shouldn't be called every time. Restarting text input might cause UX problems. Maybe only call it if mTextEdit input type is changed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant