This PR fixes the predictive text (Grammarly) issue present in default Samsung keyboard on devices with Android 13 (api 33).
Problem:
When Grammarly kick-in and marks issues in the text, content of the editor is replaced with malformed content, where some of the existing spans are removed from editor, and cursor sometimes moves to the end of the text.
In addition, we can't debug the Android source code, since it is different on Samsung.
Solution:
I tried multiple approaches using InputFilters and TextWatchers to detect when the issue is happening, and remedy it. While they do work to some extent, they are not very reliable, and there is one problem I was not able to adress - cursor moving to the end of the text (and scrolling the editor as well).
My last resort was trying to implement a custom InputConnection, but I realized that I don't necessarily need to do it - I can make a wrapper around Samsung version, and direct/intercept all the calls to it to see what is up. This worked well, and If found out that Samsung is using Extracted Text (one you usually see in EditText when it expands in landscape mode) for Grammarly, and returning null from it (default behavior of BaseInputConnection) disables the Grammarly, but still keeps regular suggestions and spellchecker.
Unfortunately, I was not able to make Grammarly work without messing up content of the editor, but in my opinion that's fine.
The fix is disabled by default in a library, but enable in Demo App.
Test device targeting
Launch the app on Samsung device on Android 13
Tap in the editor to bring up the keyboard.
In Logcat confirm that you see this line Overriding predictive text behavior on Samsung device with API 33
Try same on other device (not Samsung or different Android version) and confirm that that line is missing from logcat.
Test the fix
Launch the app on Samsung device on Android 13 with default Samsung keyboard (and predictive text enabled, which is default).
On a new line, anywhere in demo content type "Hello my name is . "
Notice that nothing happens - images are still present, and you are not scrolled to the bottom of the screen.
Try typing other things, and confirm that nothing adverse is happening.
[x] If there are new strings that have to be translated, I have added them to the client's strings.xml as a part of the integration PR.
Fixes #1023
This PR fixes the predictive text (Grammarly) issue present in default Samsung keyboard on devices with Android 13 (api 33).
Problem: When Grammarly kick-in and marks issues in the text, content of the editor is replaced with malformed content, where some of the existing spans are removed from editor, and cursor sometimes moves to the end of the text.
Video from the issue to illustrate it: https://user-images.githubusercontent.com/728822/211878346-1d296b47-8031-4f18-841a-23fb2a190172.mp4
In addition, we can't debug the Android source code, since it is different on Samsung.
Solution: I tried multiple approaches using
InputFilters
andTextWatchers
to detect when the issue is happening, and remedy it. While they do work to some extent, they are not very reliable, and there is one problem I was not able to adress - cursor moving to the end of the text (and scrolling the editor as well).My last resort was trying to implement a custom
InputConnection
, but I realized that I don't necessarily need to do it - I can make a wrapper around Samsung version, and direct/intercept all the calls to it to see what is up. This worked well, and If found out that Samsung is using Extracted Text (one you usually see in EditText when it expands in landscape mode) for Grammarly, and returning null from it (default behavior of BaseInputConnection) disables the Grammarly, but still keeps regular suggestions and spellchecker.Unfortunately, I was not able to make Grammarly work without messing up content of the editor, but in my opinion that's fine.
The fix is disabled by default in a library, but enable in Demo App.
Test device targeting
Overriding predictive text behavior on Samsung device with API 33
Test the fix
strings.xml
as a part of the integration PR.