Skip to content

TextInput crashes an app if Samsung Keyboard uses Predictive Text & Suggest text corrections #33139

Closed

Description

@BohdanSol

Description

Main issue: Generated release .apk TextInput crash the app on Samsung when Predictive Text & Suggest text corrections is activated.
React-native versions checked: 0.63.3, 0.67.2
Phones produced the issue: Samsung S20 Ultra, Samsung Galaxy S21 Plus
Another possible issue: For all the crashes captured some parts of the text were underlined green or red, maybe the issue is with that suggestions...
It was first produced by the production project based on 0.63.3v, then I created bare 0.67.2v project and added simple TextInput, and the issue still exists. Attaching a video so everybody can replicate.

Screenshot_20220216-094239_Samsung_Keyboard

record-20220217-094302.mp4

Version

0.63.3, 0.67.2

Output of npx react-native info

System:
OS: macOS 12.2.1
CPU: (8) arm64 Apple M1
Memory: 439.56 MB / 16.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 17.2.0 - /opt/homebrew/bin/node
Yarn: 1.22.17 - /opt/homebrew/bin/yarn
npm: 8.1.2 - /usr/local/bin/npm
Watchman: 2021.12.13.00 - /opt/homebrew/bin/watchman
Managers:
CocoaPods: 1.11.2 - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 21.2, iOS 15.2, macOS 12.1, tvOS 15.2, watchOS 8.3
Android SDK:
API Levels: 29, 30, 32
Build Tools: 28.0.3, 29.0.2, 30.0.0, 30.0.2, 32.0.0
System Images: android-29 | Google APIs Intel x86 Atom, android-29 | Google Play ARM 64 v8a, android-31 | Google APIs ARM 64 v8a, android-32 | Google APIs ARM 64 v8a, android-32 | Google APIs Intel x86 Atom_64
Android NDK: Not Found
IDEs:
Android Studio: 2020.3 AI-203.7717.56.2031.7935034
Xcode: 13.2.1/13C100 - /usr/bin/xcodebuild
Languages:
Java: 1.8.0_292 - /usr/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: 17.0.2 => 17.0.2
react-native: 0.67.2 => 0.67.2
react-native-macos: Not Found
npmGlobalPackages:
react-native: Not Found

Steps to reproduce

  1. Get my repo: https://github.com/BohdanSol/projectTwo
  2. yarn install
  3. Generate keystore, put it inside android>app. Change values regarding keystore inside gradlew.properties
  4. From root cd android && ./gradlew assembleRelease
  5. Test generated apk in real device

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

https://github.com/BohdanSol/projectTwo

Activity

  1. BohdanSol commented on Feb 18, 2022

    @BohdanSol
    Author

    UPD: Seems like it's related with Samsung devices upgraded to Android 12

  2. kcsuyog commented on Feb 21, 2022

    @kcsuyog

    I have the same issue.
    For us, it's mostly happening with SM-G998B and SM-G991B on Android 12

  3. tarouboy commented on Feb 21, 2022

    @tarouboy

    Not sure is it related but received app crash when typing.
    here's the log from Sentry

    java.lang.IllegalStateException: Drag shadow dimensions must be positive
        at android.view.View.startDragAndDrop(View.java:26740)
        at android.widget.Editor.startDragAndDrop(Editor.java:1393)
        at android.widget.Editor.performLongClick(Editor.java:1432)
        at android.widget.TextView.performLongClick(TextView.java:12405)
    
  4. BohdanSol commented on Feb 21, 2022

    @BohdanSol
    Author

    @tarouboy For me it's:

    android.text.SpannableStringInternal in getSpanFlags at line 331
    android.text.SpannableString in getSpanFlags at line 24
    android.text.SpannableStringInternal in getSpans at line 389
    android.text.SpannableString in getSpans at line 24
    android.text.SpannableStringBuilder in change at line 431
    android.text.SpannableStringBuilder in replace at line 560
    android.text.SpannableStringBuilder in replace at line 518
    android.text.SpannableStringBuilder in replace at line 39
    android.view.inputmethod.BaseInputConnection in replaceText at line 945
    android.view.inputmethod.BaseInputConnection in commitText at line 219
    com.android.internal.widget.EditableInputConnection in commitText at line 204
    com.android.internal.view.IInputConnectionWrapper in executeMessage at line 561
    com.android.internal.view.IInputConnectionWrapper$MyHandler in handleMessage at line 118
    android.os.Handler in dispatchMessage at line 106
    android.os.Looper in loopOnce at line 226
    android.os.Looper in loop at line 313
    android.app.ActivityThread in main at line 8582
    java.lang.reflect.Method in invoke
    com.android.internal.os.RuntimeInit$MethodAndArgsCaller in run at line 563
    com.android.internal.os.ZygoteInit in main at line 1133
    
  5. BohdanSol commented on Feb 21, 2022

    @BohdanSol
    Author

    @JoshuaGross , @RSNara , @mdvacca , sorry for mentioning you all straight, but It seems very important issue for me. Maybe somebody can take at least a quick look at the repo I attached and give this higher priority status.

  6. rakefetWorkiz commented on Feb 23, 2022

    @rakefetWorkiz

    we having the exact same issue.
    this is real show stopper 🤦‍♀️

  7. efstathiosntonas commented on Mar 10, 2022

    @efstathiosntonas

    Any updates regarding this issue? It’s happening on both Android 11 & 12 (rn 0.67.3), we get lot’s of crashes every day. It also lags a lot if a user enters a big block of text and it leads to ANR.

  8. JuanAlejandro commented on Mar 16, 2022

    @JuanAlejandro

    We were able to reproduce this bug and we found that setting autoCorrect to false in the TextInput solves the issue. We are planning to roll out this soon and expect ANR numbers to go down. I'll keep you posted.

    Try this and let me know if it works for you.

    P.S.: Since this is happening only for Samsung devices with Android 12 I made this util to only set autoCorrect to false when the device meets these props:

    import { toLower } from 'lodash';
    import { getSystemVersion, useManufacturer } from 'react-native-device-info';
    
    export const useIsSamsungWithAndroid12 = (): boolean => {
      const { loading, result } = useManufacturer();
      const systemVersion = getSystemVersion();
    
      return !loading && toLower(result) === 'samsung' && systemVersion.startsWith('12');
    };
    
  9. BohdanSol commented on Mar 17, 2022

    @BohdanSol
    Author

    @JuanAlejandro working as expected as workaround for this kind of issue. Thank you very much!

  10. systemride commented on Mar 31, 2022

    @systemride

    @JuanAlejandro Any update on whether your fix continues to solve the issue?

  11. smali-kazmi commented on Apr 5, 2022

    @smali-kazmi

    any fix for this issue? because lot of our users facing the same issue if they have Samsung Device

  12. smali-kazmi commented on Apr 6, 2022

    @smali-kazmi

    We were able to reproduce this bug and we found that setting autoCorrect to false in the TextInput solves the issue. We are planning to roll out this soon and expect ANR numbers to go down. I'll keep you posted.

    Try this and let me know if it works for you.

    P.S.: Since this is happening only for Samsung devices with Android 12 I made this util to only set autoCorrect to false when the device meets these props:

    import { toLower } from 'lodash';
    import { getSystemVersion, useManufacturer } from 'react-native-device-info';
    
    export const useIsSamsungWithAndroid12 = (): boolean => {
      const { loading, result } = useManufacturer();
      const systemVersion = getSystemVersion();
    
      return !loading && toLower(result) === 'samsung' && systemVersion.startsWith('12');
    };
    

    doesn't fix the issue

  13. 41 remaining items

  14. smali-kazmi commented on Dec 30, 2022

    @smali-kazmi

    Hello everyone here are my findings to avoid keyboard crash issue

    1. I changed value={inputValue || ''} to defaultValue={originalInputValue || ''} as suggested by @Houguiram
    2. switch to Microsoft SwiftKey Keyboard or for default Samsung s22 keyboard I turn off following two settings
    3. Suggest Text Corrections or in Manage app disable it for your application
    4. More Typing options > Enhanced accuracy

    Screenshot_20221230_152810_Samsung Keyboard
    Screenshot_20221230_152823_Samsung Keyboard

  15. rodrigobertolottizinsp commented on Jan 3, 2023

    @rodrigobertolottizinsp

    Please we need a solution for this.

  16. Steve-Rynjah commented on Jan 4, 2023

    @Steve-Rynjah

    @here any solution on this yet please reply. Thank you.

  17. gkasireddy202 commented on Jan 5, 2023

    @gkasireddy202

    Any solution.

  18. mglobel commented on Jan 5, 2023

    @mglobel

    We've finally solved this issue for our app, the root cause was re-renders locking up the UI.

    Echoing @Houguiram on this comment #33139 (comment), making the component fully uncontrolled makes a huge difference.

    For us we had a class component using Formik, so memoizing wasn't possible. Formik was causing double re-renders every time the user typed. We refactored our component to remove Formik and make sure that zero re-renders happened while typing. This might be complex for some if you're doing something like updating state on the component onDataChanged. We're using mobx as our data store and are simply updating the value in data store with onDataChanged, to be accessed when the form is submitted. Since there's no state update..no re-render.

    Obviously it'd still be great to figure out the actual root cause of why this is only happening on Samsung devices. But for those looking for immediate relief, look into how often your components are re-rendering on text changes and try to eliminate/reduce that.

  19. Saad-Bashar commented on Jan 6, 2023

    @Saad-Bashar

    @mglobel did you push the fix to prod? I also had seen a good result which I mentioned here, #33139 (comment)

    But I have not yet pushed it to production.

  20. mglobel commented on Jan 6, 2023

    @mglobel

    @Saad-Bashar Our fix is currently rolling out. We were also able to see an improvement on our own Samsung Android 13 device. By Monday I should have more confirmation from our users whether the fix is a widespread improvement.

  21. mglobel commented on Jan 9, 2023

    @mglobel

    @Saad-Bashar We've rolled out the fix and have confirmation from several users that it resolved the issue for them.

  22. Saad-Bashar commented on Jan 9, 2023

    @Saad-Bashar

    @Saad-Bashar We've rolled out the fix and have confirmation from several users that it resolved the issue for them.

    Thanks for the feedback! I just wanted to confirm again, uncontrolled input and removing re-renders solve the issue for you?

  23. tomwotton commented on Jan 10, 2023

    @tomwotton

    I have the same issue and tried some of the solutions but not working fine. Now simply I have fixed this by changing the keyboard type to email-address.

  24. YuriiLunovSendient commented on Jan 10, 2023

    @YuriiLunovSendient

    I have the same issue and tried some of the solutions but not working fine. Now simply I have fixed this by changing the keyboard type to email-address.

    Thanks this helps, but still not a perfect solution, because of adding "@" and ".com" buttons to the keyboard layout, but works better with multiline inputs than "visible-password" type

  25. tomwotton commented on Jan 11, 2023

    @tomwotton

    @LunyovYuriy yes right its not a perfect solution but its not crashing the app and autocorrect is not working when we use email-address keyboard.

  26. lunaleaps commented on Jan 12, 2023

    @lunaleaps
    Contributor

    Closing issue as we're addressing in #35590 (comment)

  27. locked and limited conversation to collaborators on Jan 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions