-
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 onKeyPress so it provides the correct key when TextInput is at max length #30751
Conversation
Hi @osamaqarem! Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks! |
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.
Code analysis results:
google-java-format
found some issues. See https://github.com/google/google-java-format
...id/src/main/java/com/facebook/react/views/textinput/ReactEditTextInputConnectionWrapper.java
Show resolved
Hide resolved
...id/src/main/java/com/facebook/react/views/textinput/ReactEditTextInputConnectionWrapper.java
Outdated
Show resolved
Hide resolved
...id/src/main/java/com/facebook/react/views/textinput/ReactEditTextInputConnectionWrapper.java
Show resolved
Hide resolved
...id/src/main/java/com/facebook/react/views/textinput/ReactEditTextInputConnectionWrapper.java
Show resolved
Hide resolved
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
Base commit: 5d500f4 |
Base commit: 5d500f4 |
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.
Code analysis results:
google-java-format
found some issues. See https://github.com/google/google-java-format
...id/src/main/java/com/facebook/react/views/textinput/ReactEditTextInputConnectionWrapper.java
Show resolved
Hide resolved
...id/src/main/java/com/facebook/react/views/textinput/ReactEditTextInputConnectionWrapper.java
Show resolved
Hide resolved
...id/src/main/java/com/facebook/react/views/textinput/ReactEditTextInputConnectionWrapper.java
Show resolved
Hide resolved
...id/src/main/java/com/facebook/react/views/textinput/ReactEditTextInputConnectionWrapper.java
Show resolved
Hide resolved
b5dcc30
to
626f580
Compare
(currentSelectionStart < previousSelectionStart) || currentSelectionStart <= 0; | ||
if (cursorMovedBackwardsOrAtBeginningOfInput || (!noPreviousSelection && cursorDidNotMove)) { | ||
(currentSelectionStart < previousSelectionStart) || currentSelectionStart <= 0; | ||
int maxLength = mEditText.getLengthFilterValue(); |
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.
Another way of getting the maxLength would be looping through the InputFilter
s on the EditText
until we find the LengthFilter
. Let me know if that approach is preferrable.
Regarding the commit: fix: backspace keypress not inferred when max length is 0: This fixes a specific edge case when When The videos below demonstrate the issue and the result of the fix introduced in this commit. Beforebefore.movAfterafter.mov |
cc @JoshuaGross to check out this PR. Quick turn around for a reported issue here: #30747 |
Summary
Fixes #30747 making Android behave the same as iOS under the same scenario.
When autosuggest is enabled (which is the default), then the keypress is inferred based on cursor position. The issue appears when max length is reached where we can no longer guess the keypress based on cursor location alone.
The problem can be reproduced using the expo snack provided in the original issue:
https://snack.expo.io/PuyXgucEf
Changelog
[Android] [Fixed] - Fix onKeyPress so it provides the correct key when TextInput has keybard suggestions and is at max length.
Test Plan
Tested using RNTester app in Components > TextInput > Event handling example and adding a
maxLength
prop.maxLength
is reached.Before
before.mov
After
after.mov