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:
Родитель
871e14fd80
Коммит
07a597ad18
|
@ -486,6 +486,9 @@ export type Props = $ReadOnly<{|
|
||||||
* The following values work on Android only:
|
* The following values work on Android only:
|
||||||
*
|
*
|
||||||
* - `visible-password`
|
* - `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,
|
keyboardType?: ?KeyboardType,
|
||||||
|
|
||||||
|
|
|
@ -389,11 +389,25 @@ public class ReactEditText extends AppCompatEditText
|
||||||
@Override
|
@Override
|
||||||
public void setInputType(int type) {
|
public void setInputType(int type) {
|
||||||
Typeface tf = super.getTypeface();
|
Typeface tf = super.getTypeface();
|
||||||
super.setInputType(type);
|
|
||||||
mStagedInputType = type;
|
|
||||||
// Input type password defaults to monospace font, so we need to re-apply the font
|
// Input type password defaults to monospace font, so we need to re-apply the font
|
||||||
super.setTypeface(tf);
|
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
|
* 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
|
* 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
|
// 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
|
// keyboards work. Some KeyListeners like DigitsKeyListener will display the keyboard but not
|
||||||
// accept all input from it
|
// accept all input from it
|
||||||
mKeyListener.setInputType(type);
|
mKeyListener.setInputType(inputType);
|
||||||
setKeyListener(mKeyListener);
|
setKeyListener(mKeyListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче