mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Fix Xiaomi TextInput crash in native
Summary: Long term fix in native for Error: android_crash:java.lang.NullPointerException:android.widget.Editor$SelectionModifierCursorController.access$300 For more detail please see T68183343 D23301714 Changelog: [Android][Changed] - Fix Xiaomi TextInput crash in native Reviewed By: mdvacca Differential Revision: D23331828 fbshipit-source-id: 914f2d431772f49711b940d47a2b3ef57ab82cdc
This commit is contained in:
committed by
Facebook GitHub Bot
parent
871e14fd80
commit
07a597ad18
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user