Fixed bug 4004 - iOS: don't hide keyboard on RETURN
authorSam Lantinga <slouken@libsdl.org>
Tue, 19 Dec 2017 10:57:21 -0800
changeset 1178298ea6e4c0d68
parent 11781 c2f3e4187c9d
child 11783 c7577c45151a
Fixed bug 4004 - iOS: don't hide keyboard on RETURN

Dominik Reichardt

As discussed in 2012 the iOS onscreen keyboard hides when you hit RETURN (see https://discourse.libsdl.org/t/on-screen-keyboard-change/19216).
IMO this is a bad idea to not be able to influence this behavior and just recently this was fixed for Android by adding the hint SDL_HINT_ANDROID_RETURN_HIDES_IME in changeset 11768 0f2fb9ec6ad6.
android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
include/SDL_hints.h
src/video/uikit/SDL_uikitviewcontroller.m
     1.1 --- a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java	Tue Dec 19 10:48:29 2017 -0800
     1.2 +++ b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java	Tue Dec 19 10:57:21 2017 -0800
     1.3 @@ -1508,7 +1508,7 @@
     1.4           */
     1.5  
     1.6          if (event.getKeyCode() == 66) {
     1.7 -            String imeHide = SDLActivity.nativeGetHint("SDL_ANDROID_RETURN_HIDES_IME");
     1.8 +            String imeHide = SDLActivity.nativeGetHint("SDL_RETURN_KEY_HIDES_IME");
     1.9              if ((imeHide != null) && imeHide.equals("1")) {
    1.10                  Context c = SDL.getContext();
    1.11                  if (c instanceof SDLActivity) {
     2.1 --- a/include/SDL_hints.h	Tue Dec 19 10:48:29 2017 -0800
     2.2 +++ b/include/SDL_hints.h	Tue Dec 19 10:57:21 2017 -0800
     2.3 @@ -721,17 +721,16 @@
     2.4  #define SDL_HINT_ANDROID_SEPARATE_MOUSE_AND_TOUCH "SDL_ANDROID_SEPARATE_MOUSE_AND_TOUCH"
     2.5  
     2.6   /**
     2.7 - * \brief A variable to control whether the return key on the soft keyboard should hide the 
     2.8 - * soft keyboard on Android.
     2.9 + * \brief A variable to control whether the return key on the soft keyboard
    2.10 + *        should hide the soft keyboard on Android and iOS.
    2.11   *
    2.12   * The variable can be set to the following values:
    2.13 - *   "0"       - The return key will be handled as a key event. This is the behaviour of 
    2.14 - *               SDL <= 2.0.3. (default)
    2.15 + *   "0"       - The return key will be handled as a key event. This is the behaviour of SDL <= 2.0.3. (default)
    2.16   *   "1"       - The return key will hide the keyboard.
    2.17   *
    2.18   * The value of this hint is used at runtime, so it can be changed at any time.
    2.19   */
    2.20 -#define SDL_HINT_ANDROID_RETURN_HIDES_IME "SDL_ANDROID_RETURN_HIDES_IME"
    2.21 +#define SDL_HINT_RETURN_KEY_HIDES_IME "SDL_RETURN_KEY_HIDES_IME"
    2.22  
    2.23  /**
    2.24   *  \brief override the binding element for keyboard inputs for Emscripten builds
     3.1 --- a/src/video/uikit/SDL_uikitviewcontroller.m	Tue Dec 19 10:48:29 2017 -0800
     3.2 +++ b/src/video/uikit/SDL_uikitviewcontroller.m	Tue Dec 19 10:57:21 2017 -0800
     3.3 @@ -387,7 +387,9 @@
     3.4  {
     3.5      SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_RETURN);
     3.6      SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_RETURN);
     3.7 -    SDL_StopTextInput();
     3.8 +    if (SDL_GetHintBoolean(SDL_HINT_RETURN_KEY_HIDES_IME, SDL_FALSE)) {
     3.9 +         SDL_StopTextInput();
    3.10 +    }
    3.11      return YES;
    3.12  }
    3.13