diff --git a/Libraries/Components/TextInput/TextInput.js b/Libraries/Components/TextInput/TextInput.js index 654765e7c79..b510773d822 100644 --- a/Libraries/Components/TextInput/TextInput.js +++ b/Libraries/Components/TextInput/TextInput.js @@ -486,6 +486,9 @@ export type Props = $ReadOnly<{| * The following values work on Android only: * * - `visible-password` + * + * On Android devices manufactured by Xiaomi with Android Q, 'email-address' + * type will be replaced in native by 'default' to prevent a system related crash. */ keyboardType?: ?KeyboardType, 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 cbda60c185b..c0cb0df07b8 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 @@ -389,11 +389,25 @@ public class ReactEditText extends AppCompatEditText @Override public void setInputType(int type) { Typeface tf = super.getTypeface(); - super.setInputType(type); - mStagedInputType = type; // 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; + /** * If set forces multiline on input, because of a restriction on Android source that enables * multiline only for inputs of type Text and Multiline on method {@link @@ -407,7 +421,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(type); + mKeyListener.setInputType(inputType); setKeyListener(mKeyListener); }