react-native icon indicating copy to clipboard operation
react-native copied to clipboard

TextInput is causing app to hang in Samsung devices with Android 13

Open JuanAlejandro opened this issue 2 years ago • 4 comments

Description

Our app is throwing ANRs when users with Samsung devices with Android 13 are typing in input fields. We had a similar issue for Samsung users with Android 12 and we ended up disabling auto-correct for those users to fix this issue. Now it looks like is the suggestions setting that is causing ANRs in Android 13 so we are setting the keyboardType as visible-password to avoid suggestions.

Version

0.69.3

Output of npx react-native info

System:
    OS: macOS 12.5.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 1.36 GB / 32.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 18.5.0 - /opt/homebrew/bin/node
    Yarn: 1.22.19 - /opt/homebrew/bin/yarn
    npm: 8.12.1 - /opt/homebrew/bin/npm
    Watchman: Not Found
  Managers:
    CocoaPods: 1.11.2 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 21.4, iOS 15.5, macOS 12.3, tvOS 15.4, watchOS 8.5
    Android SDK: Not Found
  IDEs:
    Android Studio: 2021.2 AI-212.5712.43.2112.8609683
    Xcode: 13.4.1/13F100 - /usr/bin/xcodebuild
  Languages:
    Java: 11.0.12 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: Not Found
    react-native: Not Found
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Steps to reproduce

1 - Clone the repo https://github.com/JuanAlejandro/keyboard-issue-samsung 2 - Run yarn install 3 - Test release variant in a Samsung S22 4 - Start typing until you reach 3-4 lines of text.

Expected result:

  • The app works properly when the user types

Actual result:

  • The app hangs

Snack, code example, screenshot, or link to a repository

GitHub repo: https://github.com/JuanAlejandro/keyboard-issue-samsung

Video: https://user-images.githubusercontent.com/11820379/199054761-5bd9d015-488f-4528-bf5e-4992f02e41c0.mp4

JuanAlejandro avatar Oct 31 '22 16:10 JuanAlejandro

I'm having a similar ANR but with Pixel phones. And it's only happening in Android 13.

lucasuracosta avatar Nov 01 '22 12:11 lucasuracosta

I have the same issue with samsung Android 13

Dlpan avatar Nov 03 '22 04:11 Dlpan

Our users are experiencing the same thing. Can you confirm that suggestions are causing the hanging? How did you guys workaround it?

justindi15 avatar Nov 03 '22 21:11 justindi15

Our users are experiencing the same thing. Can you confirm that suggestions are causing the hanging? How did you guys workaround it?

We set the keyboardType to visible-password. This will not bring up the text suggestions menu up so it will not cause the hang.

JuanAlejandro avatar Nov 04 '22 18:11 JuanAlejandro

Subscribing

rikur avatar Nov 11 '22 20:11 rikur

Currently we are setting autoCorrect to false for android version 12 and 13 and for samsung devices, do we need to set keyboardType to visible-password as well? @JuanAlejandro

Saad-Bashar avatar Nov 14 '22 04:11 Saad-Bashar

Looks like it might not just be related to react-native, https://support.google.com/pixelphone/thread/181332682/keyboard-freezing-after-android-13-update?hl=en

Saad-Bashar avatar Nov 14 '22 08:11 Saad-Bashar

Currently we are setting autoCorrect to false for android version 12 and 13 and for samsung devices, do we need to set keyboardType to visible-password as well? @JuanAlejandro

Yes @Saad-Bashar. This is an ugly hack but better to have that than the app freezing every time they are typing.

JuanAlejandro avatar Nov 14 '22 14:11 JuanAlejandro

Looks like it might not just be related to react-native, https://support.google.com/pixelphone/thread/181332682/keyboard-freezing-after-android-13-update?hl=en

I wouldn't say this is related to this issue since there are not enough data to say this is happening to all devices with Android 13 (I have a Google Pixel 4 XL and I have not experienced any issue with the keyboard).

JuanAlejandro avatar Nov 14 '22 14:11 JuanAlejandro

@JuanAlejandro hi! i downloaded your repo today. but, i cannot reproduce the problem. there are only expected results - "The app works properly when the user types". i followed your step - "Steps to reproduce". and did not to change for code. and i builded on 'galaxy 22, plus, ultra'. all results are same. in your local or emulator not applied to your solution, is the problem still occured?

rudenick0309 avatar Nov 15 '22 02:11 rudenick0309

Hi @rudenick0309! Does your Samsung device has Android 13?

I just updated the steps to include "Samsung S22 with Android 13" in the 3rd step.

You can see how this issue is repro in the video below

https://user-images.githubusercontent.com/11820379/201818480-9ff2baf7-989a-414c-9d2e-bc8253897275.mp4

JuanAlejandro avatar Nov 15 '22 03:11 JuanAlejandro

@JuanAlejandro thank your answer! but, i have device like you. exactly samsung 22, 22+, 22ultra with android 13. i dont know why i cannot reproduce this problem. am i lucky? :)

By the way, did you solve it by putting " keyboardType={'visible-password'} " in the TextInput tag? i have made a simple realtime chat app using 'TextInput'. so i want to prevent textInput this problem.

rudenick0309 avatar Nov 15 '22 06:11 rudenick0309

@rudenick0309 just one last thing... are you using the default keyboard of Samsung? There are a handful of users that prefer to have the Gboard. I don't know if the issue still persists with a different keyboard, but it might be a possibility.

And yes, I solved it by putting the keyboardType='visible-password' to the TextInput. But I wouldn't do it in your app if you haven't received complaints or your ANRs are increasing.

JuanAlejandro avatar Nov 15 '22 14:11 JuanAlejandro

@JuanAlejandro thank you for your advice. you are right. i have not received any complaints or ANRs. i will do more consider. thanks to your support, if i meet these case, i will solve more quickly! thank you

rudenick0309 avatar Nov 15 '22 22:11 rudenick0309

@JuanAlejandro @rudenick0309 Our customers have the same issue with Android 13 on Samsung and Pixel devices (both Samsung Keyboard and Gboard). Just typing a sentence, the application will throw the ANR pop-up and must be forced close. We can't turn off the predictive or spell check due to production requirements. Do you have any suggestions, we have received many complaints about that day by day.

Phong-TH avatar Nov 22 '22 06:11 Phong-TH

Unfortunately, our case is the same. One of the key functionality of our apps is writing text in the TextInput. The majority of our android users are using Samsung. We are getting so many crashes every day :(

Saad-Bashar avatar Nov 22 '22 07:11 Saad-Bashar

Same here! The solution keyboardType='visible-password' works for normal inputs, but won't work for multiline inputs as it will always be 1 line without the return key as a new line ( while you can still scroll if the text it long enough )

Nasseratic avatar Nov 22 '22 08:11 Nasseratic

Same here! The solution keyboardType='visible-password' works for normal inputs, but won't work for multiline inputs

Do you mean you still get the crashes for multiline inputs? Because we have multiline inputs. Thanks.

Saad-Bashar avatar Nov 22 '22 08:11 Saad-Bashar

@Saad-Bashar No I mean the input will be narrowed to one line, so you can't have TextArea-like inputs So it will always be 1 line without the return key as a new line ( while you can still scroll if the text is long enough ) image

Nasseratic avatar Nov 22 '22 09:11 Nasseratic

So, in our use case, I was able to identify the issue and it's actually a bug in the android framework (issue only happens on android version 13 for us)

You can find more details here: https://github.com/facebook/react-native/issues/35350#issuecomment-1323399593

hannojg avatar Nov 22 '22 09:11 hannojg

@Saad-Bashar No I mean the input will be narrowed to one line, so you can't have TextArea-like inputs So it will always be 1 line without the return key as a new line ( while you can still scroll if the text is long enough ) image

We used returnKeyType=none, then it works fine for multiline.

Saad-Bashar avatar Nov 22 '22 10:11 Saad-Bashar

@hannojg can we change any lines on the native or android framework to fix this problem?

Phong-TH avatar Nov 22 '22 10:11 Phong-TH

@Phong-TH If you don't use rotation anywhere in your react-native code, you can try commenting the rotation lines:

Screenshot 2022-11-22 at 11 27 33 AM

hannojg avatar Nov 22 '22 10:11 hannojg

If the issue is with the usage of an inverted FlatList I recommend manually inverting the FlatList. If you guys are interested I can post an example

hannojg avatar Nov 22 '22 10:11 hannojg

@hannojg by rotation you mean orientation change, right?

efstathiosntonas avatar Nov 22 '22 10:11 efstathiosntonas

@hannojg Thanks for your implementation but I do not use FlatList, just a screen have a TextInput with multiline={true} and predictive causes the ANR, so I don't think the inverted prop causes the error 😕

Phong-TH avatar Nov 22 '22 10:11 Phong-TH

Same here, we are not using any FlatList. Just TextInput. It hangs on Android 13.

Saad-Bashar avatar Nov 22 '22 10:11 Saad-Bashar

So, in our use case, I was able to identify the issue and it's actually a bug in the android framework (issue only happens on android version 13 for us)

You can find more details here: #35350 (comment)

@hannojg there are two issues:

  • One related to FlatList and the inverted prop that causes ANRs in all Android devices with system version 13.
  • The other one is related to the TextInput that affects only Samsung devices with Android 13.

JuanAlejandro avatar Nov 22 '22 14:11 JuanAlejandro

Oh yeah I see, good separation! Sorry for any caused confusion 😄

hannojg avatar Nov 22 '22 14:11 hannojg

If you got multiple TextInput in your app, the fastest way to temporally fix the issue is to put this in your index.js file:

import { Platform, TextInput } from "react-native";

TextInput.defaultProps = {
  ...TextInput.defaultProps,
  autoCorrect: Platform.OS === "ios",
  keyboardType: Platform.OS === "android" ? "visible-password" : "default",
  returnKeyType: Platform.OS === "android" ? "none" : "default",
  spellCheck: Platform.OS === "ios",
};

~ps. Be careful though if you got different keyboard types eg. numeric, number or email-address, it will override them.~

While applying visible-password the TextInput is treated as a single line, it won't autoresize when long text is entered

efstathiosntonas avatar Nov 23 '22 08:11 efstathiosntonas