Don't send same text changes from text input
Differential Revision: D2663576 fb-gh-sync-id: 259040eda54982c10374f9f1ee89f67a459937d0
This commit is contained in:
parent
5b796cec34
commit
fc511f0730
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue