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
This commit is contained in:
Kevin Luvian 2017-07-09 15:18:59 -07:00 committed by Facebook Github Bot
parent 1954fd4cef
commit e6941990ef
1 changed files with 22 additions and 9 deletions

View File

@ -728,16 +728,29 @@ public class ReactTextInputManager extends BaseViewManager<ReactEditText, Layout
// 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);
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;