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 0dde905faed0ee..e15dd5a7969cda 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 @@ -172,14 +172,16 @@ protected void onScrollChanged(int horiz, int vert, int oldHoriz, int oldVert) { @Override public InputConnection onCreateInputConnection(EditorInfo outAttrs) { ReactContext reactContext = (ReactContext) getContext(); - ReactEditTextInputConnectionWrapper inputConnectionWrapper = - new ReactEditTextInputConnectionWrapper(super.onCreateInputConnection(outAttrs), reactContext, this); + InputConnection inputConnection = super.onCreateInputConnection(outAttrs); + if (inputConnection != null) { + inputConnection = new ReactEditTextInputConnectionWrapper(inputConnection, reactContext, this); + } if (isMultiline() && getBlurOnSubmit()) { // Remove IME_FLAG_NO_ENTER_ACTION to keep the original IME_OPTION outAttrs.imeOptions &= ~EditorInfo.IME_FLAG_NO_ENTER_ACTION; } - return inputConnectionWrapper; + return inputConnection; } @Override diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditTextInputConnectionWrapper.java b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditTextInputConnectionWrapper.java index f0e12e61f340e5..cc2976efdf8679 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditTextInputConnectionWrapper.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditTextInputConnectionWrapper.java @@ -92,14 +92,15 @@ public boolean setComposingText(CharSequence text, int newCursorPosition) { int previousSelectionEnd = mEditText.getSelectionEnd(); String key; boolean consumed = super.setComposingText(text, newCursorPosition); + int currentSelectionStart = mEditText.getSelectionStart(); boolean noPreviousSelection = previousSelectionStart == previousSelectionEnd; - boolean cursorDidNotMove = mEditText.getSelectionStart() == previousSelectionStart; - boolean cursorMovedBackwards = mEditText.getSelectionStart() < previousSelectionStart; - if ((noPreviousSelection && cursorMovedBackwards) - || !noPreviousSelection && cursorDidNotMove) { + boolean cursorDidNotMove = currentSelectionStart == previousSelectionStart; + boolean cursorMovedBackwardsOrAtBeginningOfInput = + (currentSelectionStart < previousSelectionStart) || currentSelectionStart <= 0; + if (cursorMovedBackwardsOrAtBeginningOfInput || (!noPreviousSelection && cursorDidNotMove)) { key = BACKSPACE_KEY_VALUE; } else { - key = String.valueOf(mEditText.getText().charAt(mEditText.getSelectionStart() - 1)); + key = String.valueOf(mEditText.getText().charAt(currentSelectionStart - 1)); } dispatchKeyEventOrEnqueue(key); return consumed;