From e6941990ef1ee4fd757d8dacebdd4be00438e3a7 Mon Sep 17 00:00:00 2001 From: Kevin Luvian Date: Sun, 9 Jul 2017 15:18:59 -0700 Subject: [PATCH] Fixed new line and prioritise blurOnSubmit in multiline text input Summary: What existing problem does the pull request solve? this fixes #13506 and #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 https://github.com/facebook/react-native/pull/13890 Reviewed By: achen1 Differential Revision: D5333464 Pulled By: shergin fbshipit-source-id: a0597d1b1967d4de1486e728e03160e1bb15afeb --- .../textinput/ReactTextInputManager.java | 31 +++++++++++++------ 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java index 28f53a8dd..f8d1862e0 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java @@ -728,16 +728,29 @@ public class ReactTextInputManager extends BaseViewManager 0 || actionId == EditorInfo.IME_NULL) { - EventDispatcher eventDispatcher = - reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher(); - eventDispatcher.dispatchEvent( - new ReactTextInputSubmitEditingEvent( - editText.getId(), - editText.getText().toString())); - } + boolean blurOnSubmit = editText.getBlurOnSubmit(); + boolean isMultiline = ((editText.getInputType() & + InputType.TYPE_TEXT_FLAG_MULTI_LINE) != 0); - if (editText.getBlurOnSubmit()) { - editText.clearFocus(); + // Motivation: + // * blurOnSubmit && isMultiline => Generate `submit` event; clear focus; prevent default behaviour (return true); + // * blurOnSubmit && !isMultiline => Generate `submit` event; clear focus; prevent default behaviour (return true); + // * !blurOnSubmit && isMultiline => Perform default behaviour (return false); + // * !blurOnSubmit && !isMultiline => Prevent default behaviour (return true). + + if (blurOnSubmit) { + EventDispatcher eventDispatcher = + reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher(); + + eventDispatcher.dispatchEvent( + new ReactTextInputSubmitEditingEvent( + editText.getId(), + editText.getText().toString())); + + editText.clearFocus(); + } + + return blurOnSubmit || !isMultiline; } return true;