diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java index 7a9f34e2a6a0dd..fb4a4d9cfc174e 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java @@ -81,6 +81,7 @@ public class ReactEditText extends EditText { private @Nullable ScrollWatcher mScrollWatcher; private final InternalKeyListener mKeyListener; private boolean mDetectScrollMovement = false; + private boolean mOnKeyPress = false; private float mLetterSpacingPt = 0; private ReactViewBackgroundManager mReactBackgroundManager; @@ -175,7 +176,7 @@ protected void onScrollChanged(int horiz, int vert, int oldHoriz, int oldVert) { public InputConnection onCreateInputConnection(EditorInfo outAttrs) { ReactContext reactContext = (ReactContext) getContext(); InputConnection inputConnection = super.onCreateInputConnection(outAttrs); - if (inputConnection != null) { + if (inputConnection != null && mOnKeyPress) { inputConnection = new ReactEditTextInputConnectionWrapper(inputConnection, reactContext, this); } @@ -274,6 +275,10 @@ public void setBlurOnSubmit(@Nullable Boolean blurOnSubmit) { mBlurOnSubmit = blurOnSubmit; } + public void setOnKeyPress(boolean onKeyPress) { + mOnKeyPress = onKeyPress; + } + public boolean getBlurOnSubmit() { if (mBlurOnSubmit == null) { // Default blurOnSubmit 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 637027140ec010..9d847e3629ebe7 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 @@ -306,6 +306,11 @@ public void setOnScroll(final ReactEditText view, boolean onScroll) { } } + @ReactProp(name = "onKeyPress", defaultBoolean = false) + public void setOnKeyPress(final ReactEditText view, boolean onKeyPress) { + view.setOnKeyPress(onKeyPress); + } + // Sets the letter spacing as an absolute point size. // This extra handling, on top of what ReactBaseTextShadowNode already does, is required for the // correct display of spacing in placeholder (hint) text.