Browse files

Force original ime option when using multiline with blurOnSubmit in a…


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
                onSubmitEditing={event => console.log('submit search')}></TextInput>

2. Input some text and click submit button in soft keyboard
3. See submit event fired and focus cleared / keyboard removed
Closes #11125

Differential Revision: D5718755

Pulled By: hramos

fbshipit-source-id: c403d61a8a879c04c3defb40ad0b6689a2329ce1
  • Loading branch information...
reneweb authored and facebook-github-bot committed Aug 28, 2017
1 parent 2ceed95 commit 94a2ff93db9dce207924314219fa3acca0baa3e6
@@ -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) {
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;
public void clearFocus() {
@@ -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();
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;
public void testNumLines() {
ReactEditText view = mManager.createViewInstance(mThemedContext);

0 comments on commit 94a2ff9

Please sign in to comment.