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,9 +320,17 @@ public class ReactTextInputManager extends
|
||||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||||
// Rearranging the text (i.e. changing between singleline and multiline attributes) can
|
// 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
|
// also trigger onTextChanged, call the event in JS only when the text actually changed
|
||||||
if (count > 0 || before > 0) {
|
if (count == 0 && before == 0) {
|
||||||
Assertions.assertNotNull(mPreviousText);
|
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 contentWidth = mEditText.getWidth();
|
||||||
int contentHeight = mEditText.getHeight();
|
int contentHeight = mEditText.getHeight();
|
||||||
|
|
||||||
|
@ -349,12 +357,11 @@ public class ReactTextInputManager extends
|
||||||
new ReactTextInputEvent(
|
new ReactTextInputEvent(
|
||||||
mEditText.getId(),
|
mEditText.getId(),
|
||||||
SystemClock.uptimeMillis(),
|
SystemClock.uptimeMillis(),
|
||||||
count > 0 ? s.toString().substring(start, start + count) : "",
|
newText,
|
||||||
before > 0 ? mPreviousText.substring(start, start + before) : "",
|
oldText,
|
||||||
start,
|
start,
|
||||||
count > 0 ? start + count - 1 : start + before));
|
count > 0 ? start + count - 1 : start + before));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterTextChanged(Editable s) {
|
public void afterTextChanged(Editable s) {
|
||||||
|
|
Loading…
Reference in New Issue