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 f20132ba0b0332..2927ab9c705404 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 @@ -963,16 +963,22 @@ public void onSelectionChanged(int start, int end) { // Android will call us back for both the SELECTION_START span and SELECTION_END span in text // To prevent double calling back into js we cache the result of the previous call and only // forward it on if we have new values - if (mPreviousSelectionStart != start || mPreviousSelectionEnd != end) { + + // Apparently Android might call this with an end value that is less than the start value + // Lets normalize them. See https://github.com/facebook/react-native/issues/18579 + int realStart = Math.min(start, end); + int realEnd = Math.max(start, end); + + if (mPreviousSelectionStart != realStart || mPreviousSelectionEnd != realEnd) { mEventDispatcher.dispatchEvent( new ReactTextInputSelectionEvent( mReactEditText.getId(), - start, - end + realStart, + realEnd )); - mPreviousSelectionStart = start; - mPreviousSelectionEnd = end; + mPreviousSelectionStart = realStart; + mPreviousSelectionEnd = realEnd; } } }