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 28f53a8ddeab25..f8d1862e0fa84e 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 boolean onEditorAction(TextView v, int actionId, KeyEvent keyEvent) { // Any 'Enter' action will do if ((actionId & EditorInfo.IME_MASK_ACTION) > 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); + + // 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(); + } - if (editText.getBlurOnSubmit()) { - editText.clearFocus(); + return blurOnSubmit || !isMultiline; } return true;