From 46ca9d2ad9fce4cb87507c5f74247d91146f99c3 Mon Sep 17 00:00:00 2001 From: mannol Date: Sat, 14 Apr 2018 19:33:16 +0200 Subject: [PATCH] Fix issue with composing text not being cleared 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 deeming 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. --- .../com/facebook/react/views/textinput/ReactEditText.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java index 74910dad3231ed..0b59a3c9e94060 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java @@ -385,7 +385,13 @@ public void maybeSetText(ReactTextUpdate reactTextUpdate) { 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) {