From b5b4a7041027fd767850a564b5d80fa4a98ba2a2 Mon Sep 17 00:00:00 2001 From: Lulu Wu Date: Wed, 2 Sep 2020 05:26:50 -0700 Subject: [PATCH] Set caretHidden to true to fix the Xiaomi crash Summary: After monitoring scuba for a few days, previous fixes(D23301714 D23331828 (https://github.com/facebook/react-native/commit/07a597ad185c8c31ac38bdd4d022b0b880d02859)) don't work as expected. I managed to test this issue on a Xiaomi device, the crash didn't happen but the there was a popup "Frequetly used email" on top of email edit text: {F317216473} Getting rid of the popup probably be the right fix. For more context see https://github.com/facebook/react-native/issues/27204 Changelog: [Android] - Set caretHidden to true to fix the Xiaomi crash Reviewed By: mdvacca Differential Revision: D23451929 fbshipit-source-id: 521931422f3a46a056a9faa4b10fe93cf4732db0 --- Libraries/Components/TextInput/TextInput.js | 9 ++++++--- .../FBReactNativeSpec/FBReactNativeSpec.h | 6 ++++++ .../NativePlatformConstantsAndroid.js | 2 ++ Libraries/Utilities/Platform.android.js | 2 ++ .../NativePlatformConstantsAndroidSpec.java | 2 ++ .../modules/systeminfo/AndroidInfoModule.java | 2 ++ .../react/views/textinput/ReactEditText.java | 19 +++---------------- .../textinput/ReactTextInputManager.java | 13 +++++++++++++ 8 files changed, 36 insertions(+), 19 deletions(-) diff --git a/Libraries/Components/TextInput/TextInput.js b/Libraries/Components/TextInput/TextInput.js index b510773d822..8bf08fdd17a 100644 --- a/Libraries/Components/TextInput/TextInput.js +++ b/Libraries/Components/TextInput/TextInput.js @@ -487,8 +487,6 @@ export type Props = $ReadOnly<{| * * - `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, @@ -685,7 +683,12 @@ export type Props = $ReadOnly<{| /** * If `true`, caret is hidden. The default value is `false`. - * This property is supported only for single-line TextInput component on iOS. + * + * On Android devices manufactured by Xiaomi with Android Q, + * when keyboardType equals 'email-address'this will be set + * in native to 'true' to prevent a system related crash. This + * will cause cursor to be diabled as a side-effect. + * */ caretHidden?: ?boolean, diff --git a/Libraries/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec.h b/Libraries/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec.h index ea6aaa0bcb7..93f4a411773 100644 --- a/Libraries/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec.h +++ b/Libraries/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec.h @@ -1915,6 +1915,8 @@ namespace JS { RCTRequired Model; NSString *ServerHost; RCTRequired uiMode; + RCTRequired Brand; + RCTRequired Manufacturer; }; /** Initialize with a set of values */ @@ -3391,6 +3393,10 @@ inline JS::NativePlatformConstantsAndroid::Constants::Builder::Builder(const Inp d[@"ServerHost"] = ServerHost; auto uiMode = i.uiMode.get(); d[@"uiMode"] = uiMode; + auto Brand = i.Brand.get(); + d[@"Brand"] = Brand; + auto Manufacturer = i.Manufacturer.get(); + d[@"Manufacturer"] = Manufacturer; return d; }) {} inline JS::NativePlatformConstantsAndroid::Constants::Builder::Builder(Constants i) : _factory(^{ diff --git a/Libraries/Utilities/NativePlatformConstantsAndroid.js b/Libraries/Utilities/NativePlatformConstantsAndroid.js index c12339267e5..993b8091ddb 100644 --- a/Libraries/Utilities/NativePlatformConstantsAndroid.js +++ b/Libraries/Utilities/NativePlatformConstantsAndroid.js @@ -29,6 +29,8 @@ export interface Spec extends TurboModule { Model: string, ServerHost?: string, uiMode: string, + Brand: string, + Manufacturer: string, |}; +getAndroidID: () => string; } diff --git a/Libraries/Utilities/Platform.android.js b/Libraries/Utilities/Platform.android.js index ece5fe511ad..ab3bc9b345c 100644 --- a/Libraries/Utilities/Platform.android.js +++ b/Libraries/Utilities/Platform.android.js @@ -42,6 +42,8 @@ const Platform = { Model: string, ServerHost?: string, uiMode: string, + Brand: string, + Manufacturer: string, |} { if (this.__constants == null) { this.__constants = NativePlatformConstantsAndroid.getConstants(); diff --git a/ReactAndroid/src/main/java/com/facebook/fbreact/specs/NativePlatformConstantsAndroidSpec.java b/ReactAndroid/src/main/java/com/facebook/fbreact/specs/NativePlatformConstantsAndroidSpec.java index c8340538348..00d2039ade6 100644 --- a/ReactAndroid/src/main/java/com/facebook/fbreact/specs/NativePlatformConstantsAndroidSpec.java +++ b/ReactAndroid/src/main/java/com/facebook/fbreact/specs/NativePlatformConstantsAndroidSpec.java @@ -41,12 +41,14 @@ public abstract class NativePlatformConstantsAndroidSpec extends ReactContextBas Map constants = getTypedExportedConstants(); if (ReactBuildConfig.DEBUG || ReactBuildConfig.IS_INTERNAL_BUILD) { Set obligatoryFlowConstants = new HashSet<>(Arrays.asList( + "Brand", "Serial", "Fingerprint", "uiMode", "Version", "reactNativeVersion", "Model", + "Manufacturer", "isTesting", "Release" )); diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/AndroidInfoModule.java b/ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/AndroidInfoModule.java index 3c4be024f51..b2355c7ecbf 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/AndroidInfoModule.java +++ b/ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/AndroidInfoModule.java @@ -70,6 +70,8 @@ public class AndroidInfoModule extends NativePlatformConstantsAndroidSpec implem constants.put("Serial", Build.SERIAL); constants.put("Fingerprint", Build.FINGERPRINT); constants.put("Model", Build.MODEL); + constants.put("Manufacturer", Build.MANUFACTURER); + constants.put("Brand", Build.BRAND); if (ReactBuildConfig.DEBUG) { constants.put( "ServerHost", 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 c0cb0df07b8..8995949bb76 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 @@ -392,21 +392,8 @@ public class ReactEditText extends AppCompatEditText // 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; + super.setInputType(type); + mStagedInputType = type; /** * If set forces multiline on input, because of a restriction on Android source that enables @@ -421,7 +408,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(inputType); + mKeyListener.setInputType(type); setKeyListener(mKeyListener); } diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java index 5e044b283cf..774ceb25e46 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java @@ -479,6 +479,19 @@ public class ReactTextInputManager extends BaseViewManager