Skip to content

Commit e694199

Browse files
kevinluvianfacebook-github-bot
authored andcommitted
Fixed new line and prioritise blurOnSubmit in multiline text input
Summary: What existing problem does the pull request solve? this fixes facebook#13506 and facebook#12717 where: - there are some issues when pressing enter with some keyboard - blurOnSubmit is not working with multiline I think this should be in stable branch as this is pretty critical, isn't it? - just create a TextInput with multiline and press enter with samsung keyboard before, it won't create a new line, now it will. - just create a TextInput with multiline and blurOnSubmit true and press enter before, it won't blur, and wont create a new line (on some keyboard, it will create a new line), now it will blur only Closes facebook#13890 Reviewed By: achen1 Differential Revision: D5333464 Pulled By: shergin fbshipit-source-id: a0597d1b1967d4de1486e728e03160e1bb15afeb
1 parent 1954fd4 commit e694199

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -728,16 +728,29 @@ public boolean onEditorAction(TextView v, int actionId, KeyEvent keyEvent) {
728728
// Any 'Enter' action will do
729729
if ((actionId & EditorInfo.IME_MASK_ACTION) > 0 ||
730730
actionId == EditorInfo.IME_NULL) {
731-
EventDispatcher eventDispatcher =
732-
reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
733-
eventDispatcher.dispatchEvent(
734-
new ReactTextInputSubmitEditingEvent(
735-
editText.getId(),
736-
editText.getText().toString()));
737-
}
731+
boolean blurOnSubmit = editText.getBlurOnSubmit();
732+
boolean isMultiline = ((editText.getInputType() &
733+
InputType.TYPE_TEXT_FLAG_MULTI_LINE) != 0);
734+
735+
// Motivation:
736+
// * blurOnSubmit && isMultiline => Generate `submit` event; clear focus; prevent default behaviour (return true);
737+
// * blurOnSubmit && !isMultiline => Generate `submit` event; clear focus; prevent default behaviour (return true);
738+
// * !blurOnSubmit && isMultiline => Perform default behaviour (return false);
739+
// * !blurOnSubmit && !isMultiline => Prevent default behaviour (return true).
740+
741+
if (blurOnSubmit) {
742+
EventDispatcher eventDispatcher =
743+
reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
744+
745+
eventDispatcher.dispatchEvent(
746+
new ReactTextInputSubmitEditingEvent(
747+
editText.getId(),
748+
editText.getText().toString()));
749+
750+
editText.clearFocus();
751+
}
738752

739-
if (editText.getBlurOnSubmit()) {
740-
editText.clearFocus();
753+
return blurOnSubmit || !isMultiline;
741754
}
742755

743756
return true;

0 commit comments

Comments
 (0)