Skip to content

Commit

Permalink
Fixed new line and prioritise blurOnSubmit in multiline text input
Browse files Browse the repository at this point in the history
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 e694199
Showing 1 changed file with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

2 comments on commit e694199

@ZHT131
Copy link

@ZHT131 ZHT131 commented on e694199 Jul 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I change the above code, I cannot create newlines

@shergin
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Please sign in to comment.