Permalink
Browse files

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 #13890

Reviewed By: achen1

Differential Revision: D5333464

Pulled By: shergin

fbshipit-source-id: a0597d1b1967d4de1486e728e03160e1bb15afeb
  • Loading branch information...
kevinluvian authored and facebook-github-bot committed Jul 9, 2017
1 parent 1954fd4 commit e6941990ef1ee4fd757d8dacebdd4be00438e3a7
@@ -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;

2 comments on commit e694199

@ZHT131

This comment has been minimized.

Show comment
Hide comment
@ZHT131

ZHT131 Jul 10, 2017

I change the above code, I cannot create newlines

ZHT131 replied Jul 10, 2017

I change the above code, I cannot create newlines

@shergin

This comment has been minimized.

Show comment
Hide comment
@shergin

shergin Jul 22, 2017

Contributor

@ZHT131 Sorry, what did you change? Can you provide snack (https://snack.expo.io/) demonstrating your problem?

Contributor

shergin replied Jul 22, 2017

@ZHT131 Sorry, what did you change? Can you provide snack (https://snack.expo.io/) demonstrating your problem?

Please sign in to comment.