mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-05-13 12:26:45 +08:00
Fix issue with composing text not being cleared on some Android devices (#18859)
Summary: Clearing the android TextInput text programmatically (i.e. calling: this.textInputRef.clear()) does not clear the previously composing text, if enabled, causing inconveniences when such behaviour is desired (i.e. chat input box, where you constantly have to clear the input after sending a message). Instead, the currently observed behaviour is that, after a new text is entered (usually as soon as the first letter), the previously composing text reappears making the input unusable. The effect is only observable on some devices, for example, we observed it on Samsung S6 devices using both Android 6 and 7, and several LG devices running Android 6. This issue is only present when clearing the text; setting text to some other value does not produce the same effect. <!-- Required: Write your motivation here. If this PR fixes an issue, type "Fixes #issueNumber" to automatically close the issue when the PR is merged. --> Pull Request resolved: https://github.com/facebook/react-native/pull/18859 Differential Revision: D14067144 Pulled By: hramos fbshipit-source-id: 09f337edc026b83221f8a399749222cd75457ec7
This commit is contained in:
committed by
Facebook Github Bot
parent
c933755c6a
commit
b47191608b
@@ -385,7 +385,13 @@ public class ReactEditText extends EditText {
|
||||
mContainsImages = reactTextUpdate.containsImages();
|
||||
mIsSettingTextFromJS = true;
|
||||
|
||||
getText().replace(0, length(), spannableStringBuilder);
|
||||
// On some devices, when the text is cleared, buggy keyboards will not clear the composing
|
||||
// text so, we have to set text to null, which will clear the currently composing text.
|
||||
if (reactTextUpdate.getText().length() == 0) {
|
||||
setText(null);
|
||||
} else {
|
||||
getText().replace(0, length(), spannableStringBuilder);
|
||||
}
|
||||
|
||||
mIsSettingTextFromJS = false;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
|
||||
Reference in New Issue
Block a user