Skip to content

Commit

Permalink
Force original ime option when using multiline with blurOnSubmit in a…
Browse files Browse the repository at this point in the history
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
<View>
           <TextInput
                returnKeyType='search'
                blurOnSubmit={true}
                multiline={true}
                onSubmitEditing={event => console.log('submit search')}></TextInput>
</View>
```

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 94a2ff9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 94a2ff9

Please sign in to comment.