From 94a2ff93db9dce207924314219fa3acca0baa3e6 Mon Sep 17 00:00:00 2001 From: Rene Weber Date: Mon, 28 Aug 2017 12:13:34 -0700 Subject: [PATCH] =?UTF-8?q?Force=20original=20ime=20option=20when=20using?= =?UTF-8?q?=20multiline=20with=20blurOnSubmit=20in=20a=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: …ndroid Android overrides the original set ime option when the EditText is a multiline one. This change makes sure to set it back to the original one when blurOnSubmit is true, which causes the button icon to be conforming to the set returnKeyType as well as changing the behaviour of the button, such that it will blurOnSubmit correctly. The reason not do it with blurOnSubmit being false is because it then would not create new lines when pressing the submit button, which would be inconsistent with IOS behaviour. **Note** this change relies on this one #11006 because the app would crash if we don't expllicitly remove the focus (`editText.clearFocus();`) Fixes #8778 **Test plan (required)** 1. Create view with TextInput with multiline and blurOnSubmit set to true ```javascript console.log('submit search')}> ``` 2. Input some text and click submit button in soft keyboard 3. See submit event fired and focus cleared / keyboard removed Closes https://github.com/facebook/react-native/pull/11125 Differential Revision: D5718755 Pulled By: hramos fbshipit-source-id: c403d61a8a879c04c3defb40ad0b6689a2329ce1 --- .../react/views/textinput/ReactEditText.java | 11 +++++++++++ .../textinput/ReactTextInputPropertyTest.java | 15 +++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java index bf318a0dc3100c..a8e43b2bb36969 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java @@ -35,6 +35,7 @@ import android.view.MotionEvent; import android.view.View; import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputConnection; import android.view.inputmethod.InputMethodManager; import android.widget.EditText; @@ -182,6 +183,16 @@ protected void onScrollChanged(int horiz, int vert, int oldHoriz, int oldVert) { } } + @Override + public InputConnection onCreateInputConnection(EditorInfo outAttrs) { + InputConnection connection = super.onCreateInputConnection(outAttrs); + if (isMultiline() && getBlurOnSubmit()) { + // Remove IME_FLAG_NO_ENTER_ACTION to keep the original IME_OPTION + outAttrs.imeOptions &= ~EditorInfo.IME_FLAG_NO_ENTER_ACTION; + } + return connection; + } + @Override public void clearFocus() { setFocusableInTouchMode(false); diff --git a/ReactAndroid/src/test/java/com/facebook/react/views/textinput/ReactTextInputPropertyTest.java b/ReactAndroid/src/test/java/com/facebook/react/views/textinput/ReactTextInputPropertyTest.java index 4f89f035ec31f0..2dd209a71550cb 100644 --- a/ReactAndroid/src/test/java/com/facebook/react/views/textinput/ReactTextInputPropertyTest.java +++ b/ReactAndroid/src/test/java/com/facebook/react/views/textinput/ReactTextInputPropertyTest.java @@ -15,6 +15,7 @@ import android.text.InputFilter; import android.util.DisplayMetrics; import android.view.Gravity; +import android.view.inputmethod.EditorInfo; import android.widget.EditText; import com.facebook.react.bridge.CatalystInstance; @@ -201,6 +202,20 @@ public void testMultiline() { assertThat(view.getInputType() & InputType.TYPE_TEXT_FLAG_MULTI_LINE).isZero(); } + @Test + public void testBlurMultiline() { + ReactEditText view = mManager.createViewInstance(mThemedContext); + + mManager.updateProperties(view, buildStyles("multiline", true)); + mManager.updateProperties(view, buildStyles("blurOnSubmit", true)); + + EditorInfo editorInfo = new EditorInfo(); + editorInfo.imeOptions = EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_ENTER_ACTION; + view.onCreateInputConnection(editorInfo); + + assertThat(editorInfo.imeOptions).isEqualTo(EditorInfo.IME_ACTION_DONE); + } + @Test public void testNumLines() { ReactEditText view = mManager.createViewInstance(mThemedContext);