-
Notifications
You must be signed in to change notification settings - Fork 24.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Android] Fix issue#11068 of duplicating characters when replacing letters to lowercase or uppercase in TextInput (Adjusted) #38649
Conversation
e567413
to
7f47644
Compare
Base commit: 0239776 |
Is it possible to put this fix behind a flag? You can use ReactFeatureFlag and create a new flag. I can hook it up to our fb infra to test out and of course every React Native app can override these feature flags. That way, I can roll out the fix and if it regresses, simply turn off the feature flag vs. needing to revert etc. Edit: also thanks @fknives for the re-attempt! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment around flagging this
e728ea2
to
f32f142
Compare
@lunaleaps I think Feature Flagging makes sense, I've added the new Flag by default enabled. I hope I understood correctly and that's what you meant. Thank you! Note: Also had to rebase, because the |
1e3f017
to
8fde589
Compare
^ rebase to resolve conflicts |
8fde589
to
586cf14
Compare
^ rebased to resolve conflicts within ReactFeatureFlags.java Ran rn-tester again, attached video still applies. |
…ing letters to lowercase or uppercase in TextInput
…nSameLength by default
586cf14
to
2114952
Compare
^ rebased to resolve conflicts within ReactFeatureFlags.java |
This PR is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
This PR was closed because it has been stalled for 7 days with no activity. |
Summary:
These changes are intended to resolve #11068.
This pull request is an adjustment to #35929 which had issues with it's implementation and had to be reverted. (commit: c1eec4c)
Changelog:
[Android] [Fixed] - Fix letters duplication when using autoCapitalize
Test Plan:
I have added an example to the
TextInputSharedExamples.js
which can demonstration the fix.Here is a short video showing the following:
short3.mov
Note: I have tested with latest main, 0.72.3, commit before mine: 3c6dbec
Note2: I have tested on Emulator where I can reproduce the original issue. On real device (Samsung A52s 5G) I could reproduce it using Samsung Keyboard, I could not reproduce it on the same device with Gboard.
Here is a longer version which goes through the TextInput examples: typing, clearing, selection, cut, paste etc.
So to ensure this indeed does not cause the same issues as #35929 did.
Uploaded to youtube, because it was too big: https://youtu.be/5IEzXYpfa7w
Possible Future Improvements
As it can be seen the video, the letter duplication is resolved, however since the lowercase modification happens on the Javascript side, it takes a couple milliseconds and the Uppercase can still be shown momentarily while typing.
Technical details, why the solution works
I've debugged a simple AppCompatEditText with calling the same
getText().replace
indoAfterTextChanged
with a bit of delay and noticed a difference to theReactEditText
.The ReactEditText removes the
android.view.inputmethod.ComposingText
Span inmanageSpans
before calling replace (ComposingText isSpanned.SPAN_EXCLUSIVE_EXCLUSIVE
).That
ComposingText
Span is used inandroid.view.inputmethod.BaseInputConnection
private replaceText
to find from what point the text should be replaced from when applying suggestions or typing new letters. Without that Span, it defaults to the selection position, which is usually the end of the text causing duplication of the old "word".In simple terms, while typing with suggestions on the keyboard, each new letter is handled similarly as clicking a suggestion would be, aka replacing the current "word" with the new "word". (let's say "Ar" word with "Are" word)
Another way to describe it:
While typing with suggestions, with the ComposingText Span the TextView keeps track of what word completions are suggested for on the keyboard UI. When receiving a new letter input, it replaces the current "word" with a new "word", and without the Span, it replaces nothing at the end (selection point) with the new word which results in character duplication.
It also seems to make sense then why without suggestions (like password-visible and secureTextEntry) the issue hasn't occurred.
Examples
How the issue happened:
How it works with the changes applied:
Note: the Editable.replace also removes the ComposingText, if it doesn't cover the whole text, that's why we need to re-setSpan them even if we wouldn't remove them in
manageSpans
.