Skip to content

Commit 07a597a

Browse files
luluwu2032facebook-github-bot
authored andcommitted
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
1 parent 871e14f commit 07a597a

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

Libraries/Components/TextInput/TextInput.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,9 @@ export type Props = $ReadOnly<{|
486486
* The following values work on Android only:
487487
*
488488
* - `visible-password`
489+
*
490+
* On Android devices manufactured by Xiaomi with Android Q, 'email-address'
491+
* type will be replaced in native by 'default' to prevent a system related crash.
489492
*/
490493
keyboardType?: ?KeyboardType,
491494

ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,11 +389,25 @@ public String getReturnKeyType() {
389389
@Override
390390
public void setInputType(int type) {
391391
Typeface tf = super.getTypeface();
392-
super.setInputType(type);
393-
mStagedInputType = type;
394392
// Input type password defaults to monospace font, so we need to re-apply the font
395393
super.setTypeface(tf);
396394

395+
int inputType = type;
396+
397+
// Set InputType to TYPE_CLASS_TEXT (the default one for Android) to fix a crash on Xiaomi
398+
// devices with Android Q. This crash happens when focusing on a email EditText within a
399+
// ScrollView, a prompt will be triggered but the system fail to locate it properly.
400+
// Here is an example post discussing about this issue:
401+
// https://github.com/facebook/react-native/issues/27204
402+
if (inputType == InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS
403+
&& Build.VERSION.SDK_INT == Build.VERSION_CODES.Q
404+
&& Build.MANUFACTURER.startsWith("Xiaomi")) {
405+
inputType = InputType.TYPE_CLASS_TEXT;
406+
}
407+
408+
super.setInputType(inputType);
409+
mStagedInputType = inputType;
410+
397411
/**
398412
* If set forces multiline on input, because of a restriction on Android source that enables
399413
* multiline only for inputs of type Text and Multiline on method {@link
@@ -407,7 +421,7 @@ public void setInputType(int type) {
407421
// We override the KeyListener so that all keys on the soft input keyboard as well as hardware
408422
// keyboards work. Some KeyListeners like DigitsKeyListener will display the keyboard but not
409423
// accept all input from it
410-
mKeyListener.setInputType(type);
424+
mKeyListener.setInputType(inputType);
411425
setKeyListener(mKeyListener);
412426
}
413427

0 commit comments

Comments
 (0)