Skip to content

Commit b5b4a70

Browse files
luluwu2032facebook-github-bot
authored andcommitted
Set caretHidden to true to fix the Xiaomi crash
Summary: After monitoring scuba for a few days, previous fixes(D23301714 D23331828 (07a597a)) 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 #27204 Changelog: [Android] - Set caretHidden to true to fix the Xiaomi crash Reviewed By: mdvacca Differential Revision: D23451929 fbshipit-source-id: 521931422f3a46a056a9faa4b10fe93cf4732db0
1 parent 59ddd7c commit b5b4a70

File tree

8 files changed

+36
-19
lines changed

8 files changed

+36
-19
lines changed

Libraries/Components/TextInput/TextInput.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -487,8 +487,6 @@ export type Props = $ReadOnly<{|
487487
*
488488
* - `visible-password`
489489
*
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.
492490
*/
493491
keyboardType?: ?KeyboardType,
494492

@@ -685,7 +683,12 @@ export type Props = $ReadOnly<{|
685683

686684
/**
687685
* If `true`, caret is hidden. The default value is `false`.
688-
* This property is supported only for single-line TextInput component on iOS.
686+
*
687+
* On Android devices manufactured by Xiaomi with Android Q,
688+
* when keyboardType equals 'email-address'this will be set
689+
* in native to 'true' to prevent a system related crash. This
690+
* will cause cursor to be diabled as a side-effect.
691+
*
689692
*/
690693
caretHidden?: ?boolean,
691694

Libraries/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec.h

+6
Original file line numberDiff line numberDiff line change
@@ -1915,6 +1915,8 @@ namespace JS {
19151915
RCTRequired<NSString *> Model;
19161916
NSString *ServerHost;
19171917
RCTRequired<NSString *> uiMode;
1918+
RCTRequired<NSString *> Brand;
1919+
RCTRequired<NSString *> Manufacturer;
19181920
};
19191921

19201922
/** Initialize with a set of values */
@@ -3391,6 +3393,10 @@ inline JS::NativePlatformConstantsAndroid::Constants::Builder::Builder(const Inp
33913393
d[@"ServerHost"] = ServerHost;
33923394
auto uiMode = i.uiMode.get();
33933395
d[@"uiMode"] = uiMode;
3396+
auto Brand = i.Brand.get();
3397+
d[@"Brand"] = Brand;
3398+
auto Manufacturer = i.Manufacturer.get();
3399+
d[@"Manufacturer"] = Manufacturer;
33943400
return d;
33953401
}) {}
33963402
inline JS::NativePlatformConstantsAndroid::Constants::Builder::Builder(Constants i) : _factory(^{

Libraries/Utilities/NativePlatformConstantsAndroid.js

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ export interface Spec extends TurboModule {
2929
Model: string,
3030
ServerHost?: string,
3131
uiMode: string,
32+
Brand: string,
33+
Manufacturer: string,
3234
|};
3335
+getAndroidID: () => string;
3436
}

Libraries/Utilities/Platform.android.js

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ const Platform = {
4242
Model: string,
4343
ServerHost?: string,
4444
uiMode: string,
45+
Brand: string,
46+
Manufacturer: string,
4547
|} {
4648
if (this.__constants == null) {
4749
this.__constants = NativePlatformConstantsAndroid.getConstants();

ReactAndroid/src/main/java/com/facebook/fbreact/specs/NativePlatformConstantsAndroidSpec.java

+2
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,14 @@ public NativePlatformConstantsAndroidSpec(ReactApplicationContext reactContext)
4141
Map<String, Object> constants = getTypedExportedConstants();
4242
if (ReactBuildConfig.DEBUG || ReactBuildConfig.IS_INTERNAL_BUILD) {
4343
Set<String> obligatoryFlowConstants = new HashSet<>(Arrays.asList(
44+
"Brand",
4445
"Serial",
4546
"Fingerprint",
4647
"uiMode",
4748
"Version",
4849
"reactNativeVersion",
4950
"Model",
51+
"Manufacturer",
5052
"isTesting",
5153
"Release"
5254
));

ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/AndroidInfoModule.java

+2
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ public String getName() {
7070
constants.put("Serial", Build.SERIAL);
7171
constants.put("Fingerprint", Build.FINGERPRINT);
7272
constants.put("Model", Build.MODEL);
73+
constants.put("Manufacturer", Build.MANUFACTURER);
74+
constants.put("Brand", Build.BRAND);
7375
if (ReactBuildConfig.DEBUG) {
7476
constants.put(
7577
"ServerHost",

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

+3-16
Original file line numberDiff line numberDiff line change
@@ -392,21 +392,8 @@ public void setInputType(int type) {
392392
// Input type password defaults to monospace font, so we need to re-apply the font
393393
super.setTypeface(tf);
394394

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;
395+
super.setInputType(type);
396+
mStagedInputType = type;
410397

411398
/**
412399
* If set forces multiline on input, because of a restriction on Android source that enables
@@ -421,7 +408,7 @@ public void setInputType(int type) {
421408
// We override the KeyListener so that all keys on the soft input keyboard as well as hardware
422409
// keyboards work. Some KeyListeners like DigitsKeyListener will display the keyboard but not
423410
// accept all input from it
424-
mKeyListener.setInputType(inputType);
411+
mKeyListener.setInputType(type);
425412
setKeyListener(mKeyListener);
426413
}
427414

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

+13
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,19 @@ public void setCursorColor(ReactEditText view, @Nullable Integer color) {
479479

480480
@ReactProp(name = "caretHidden", defaultBoolean = false)
481481
public void setCaretHidden(ReactEditText view, boolean caretHidden) {
482+
// Set cursor's visibility to False to fix a crash on some Xiaomi devices with Android Q. This
483+
// crash happens when focusing on a email EditText, during which a prompt will be triggered but
484+
// the system fail to locate it properly. Here is an example post discussing about this
485+
// issue: https://github.com/facebook/react-native/issues/27204
486+
String manufacturer = Build.MANUFACTURER.toLowerCase();
487+
if ((view.getInputType() == InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS
488+
|| view.getInputType() == InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS)
489+
&& Build.VERSION.SDK_INT == Build.VERSION_CODES.Q
490+
&& manufacturer.contains("xiaomi")) {
491+
view.setCursorVisible(false);
492+
return;
493+
}
494+
482495
view.setCursorVisible(!caretHidden);
483496
}
484497

0 commit comments

Comments
 (0)