Skip to content

Commit

Permalink
Fix Xiaomi TextInput crash in native
Browse files Browse the repository at this point in the history
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
  • Loading branch information
luluwu2032 authored and facebook-github-bot committed Aug 28, 2020
1 parent 871e14f commit 07a597a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Libraries/Components/TextInput/TextInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,11 +389,25 @@ public String getReturnKeyType() {
@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
Expand All @@ -407,7 +421,7 @@ public void setInputType(int type) {
// 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);
}

Expand Down

0 comments on commit 07a597a

Please sign in to comment.