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 704d0956d85559..360b503501f7f3 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 @@ -82,6 +82,7 @@ public class ReactEditText extends EditText { private @Nullable ScrollWatcher mScrollWatcher; private final InternalKeyListener mKeyListener; private boolean mDetectScrollMovement = false; + private boolean mOnKeyPress = false; 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 4879fbcc6614d2..14f5f3cc8261ae 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 @@ -302,6 +302,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); + } + @ReactProp(name = "placeholder") public void setPlaceholder(ReactEditText view, @Nullable String placeholder) { view.setHint(placeholder);