Set caretHidden to true to fix the Xiaomi crash

Summary:
After monitoring scuba for a few days,  previous fixes(D23301714 D23331828 (https://github.com/facebook/react-native/commit/07a597ad185c8c31ac38bdd4d022b0b880d02859)) don't work as expected.

I managed to test this issue on a Xiaomi device, the crash didn't happen but the there was a popup "Frequetly used email" on top of email edit text:

{F317216473}

Getting rid of the popup probably be the right fix.

For more context see https://github.com/facebook/react-native/issues/27204

Changelog: [Android] - Set caretHidden to true to fix the Xiaomi crash

Reviewed By: mdvacca

Differential Revision: D23451929

fbshipit-source-id: 521931422f3a46a056a9faa4b10fe93cf4732db0
This commit is contained in:
Lulu Wu
2020-09-02 05:26:50 -07:00
committed by Facebook GitHub Bot
parent 59ddd7cd4b
commit b5b4a70410
8 changed files with 36 additions and 19 deletions
@@ -41,12 +41,14 @@ public abstract class NativePlatformConstantsAndroidSpec extends ReactContextBas
Map<String, Object> constants = getTypedExportedConstants();
if (ReactBuildConfig.DEBUG || ReactBuildConfig.IS_INTERNAL_BUILD) {
Set<String> obligatoryFlowConstants = new HashSet<>(Arrays.asList(
"Brand",
"Serial",
"Fingerprint",
"uiMode",
"Version",
"reactNativeVersion",
"Model",
"Manufacturer",
"isTesting",
"Release"
));
@@ -70,6 +70,8 @@ public class AndroidInfoModule extends NativePlatformConstantsAndroidSpec implem
constants.put("Serial", Build.SERIAL);
constants.put("Fingerprint", Build.FINGERPRINT);
constants.put("Model", Build.MODEL);
constants.put("Manufacturer", Build.MANUFACTURER);
constants.put("Brand", Build.BRAND);
if (ReactBuildConfig.DEBUG) {
constants.put(
"ServerHost",
@@ -392,21 +392,8 @@ public class ReactEditText extends AppCompatEditText
// Input type password defaults to monospace font, so we need to re-apply the font
super.setTypeface(tf);
int inputType = type;
// Set InputType to TYPE_CLASS_TEXT (the default one for Android) to fix a crash on Xiaomi
// devices with Android Q. This crash happens when focusing on a email EditText within a
// ScrollView, a prompt will be triggered but the system fail to locate it properly.
// Here is an example post discussing about this issue:
// https://github.com/facebook/react-native/issues/27204
if (inputType == InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS
&& Build.VERSION.SDK_INT == Build.VERSION_CODES.Q
&& Build.MANUFACTURER.startsWith("Xiaomi")) {
inputType = InputType.TYPE_CLASS_TEXT;
}
super.setInputType(inputType);
mStagedInputType = inputType;
super.setInputType(type);
mStagedInputType = type;
/**
* If set forces multiline on input, because of a restriction on Android source that enables
@@ -421,7 +408,7 @@ public class ReactEditText extends AppCompatEditText
// We override the KeyListener so that all keys on the soft input keyboard as well as hardware
// keyboards work. Some KeyListeners like DigitsKeyListener will display the keyboard but not
// accept all input from it
mKeyListener.setInputType(inputType);
mKeyListener.setInputType(type);
setKeyListener(mKeyListener);
}
@@ -479,6 +479,19 @@ public class ReactTextInputManager extends BaseViewManager<ReactEditText, Layout
@ReactProp(name = "caretHidden", defaultBoolean = false)
public void setCaretHidden(ReactEditText view, boolean caretHidden) {
// Set cursor's visibility to False to fix a crash on some Xiaomi devices with Android Q. This
// crash happens when focusing on a email EditText, during which a prompt will be triggered but
// the system fail to locate it properly. Here is an example post discussing about this
// issue: https://github.com/facebook/react-native/issues/27204
String manufacturer = Build.MANUFACTURER.toLowerCase();
if ((view.getInputType() == InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS
|| view.getInputType() == InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS)
&& Build.VERSION.SDK_INT == Build.VERSION_CODES.Q
&& manufacturer.contains("xiaomi")) {
view.setCursorVisible(false);
return;
}
view.setCursorVisible(!caretHidden);
}