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 020814755..6e4a3f449 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 @@ -320,40 +320,47 @@ public class ReactTextInputManager extends public void onTextChanged(CharSequence s, int start, int before, int count) { // Rearranging the text (i.e. changing between singleline and multiline attributes) can // also trigger onTextChanged, call the event in JS only when the text actually changed - if (count > 0 || before > 0) { - Assertions.assertNotNull(mPreviousText); - - int contentWidth = mEditText.getWidth(); - int contentHeight = mEditText.getHeight(); - - // Use instead size of text content within EditText when available - if (mEditText.getLayout() != null) { - contentWidth = mEditText.getCompoundPaddingLeft() + mEditText.getLayout().getWidth() + - mEditText.getCompoundPaddingRight(); - contentHeight = mEditText.getCompoundPaddingTop() + mEditText.getLayout().getHeight() + - mEditText.getCompoundPaddingTop(); - } - - // The event that contains the event counter and updates it must be sent first. - // TODO: t7936714 merge these events - mEventDispatcher.dispatchEvent( - new ReactTextChangedEvent( - mEditText.getId(), - SystemClock.uptimeMillis(), - s.toString(), - (int) PixelUtil.toDIPFromPixel(contentWidth), - (int) PixelUtil.toDIPFromPixel(contentHeight), - mEditText.incrementAndGetEventCounter())); - - mEventDispatcher.dispatchEvent( - new ReactTextInputEvent( - mEditText.getId(), - SystemClock.uptimeMillis(), - count > 0 ? s.toString().substring(start, start + count) : "", - before > 0 ? mPreviousText.substring(start, start + before) : "", - start, - count > 0 ? start + count - 1 : start + before)); + if (count == 0 && before == 0) { + return; } + + Assertions.assertNotNull(mPreviousText); + String newText = s.toString().substring(start, start + count); + String oldText = mPreviousText.substring(start, start + before); + // Don't send same text changes + if (count == before && newText.equals(oldText)) { + return; + } + int contentWidth = mEditText.getWidth(); + int contentHeight = mEditText.getHeight(); + + // Use instead size of text content within EditText when available + if (mEditText.getLayout() != null) { + contentWidth = mEditText.getCompoundPaddingLeft() + mEditText.getLayout().getWidth() + + mEditText.getCompoundPaddingRight(); + contentHeight = mEditText.getCompoundPaddingTop() + mEditText.getLayout().getHeight() + + mEditText.getCompoundPaddingTop(); + } + + // The event that contains the event counter and updates it must be sent first. + // TODO: t7936714 merge these events + mEventDispatcher.dispatchEvent( + new ReactTextChangedEvent( + mEditText.getId(), + SystemClock.uptimeMillis(), + s.toString(), + (int) PixelUtil.toDIPFromPixel(contentWidth), + (int) PixelUtil.toDIPFromPixel(contentHeight), + mEditText.incrementAndGetEventCounter())); + + mEventDispatcher.dispatchEvent( + new ReactTextInputEvent( + mEditText.getId(), + SystemClock.uptimeMillis(), + newText, + oldText, + start, + count > 0 ? start + count - 1 : start + before)); } @Override