Skip to content
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 letters duplication when using autoCapitalize #29070

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
677a789
fix capitalize characters and position cursor
fabOnReact Jun 5, 2020
80ebff4
rename variable in java
fabOnReact Jun 5, 2020
7e8eb41
adding test example to RNTester
fabOnReact Jul 1, 2020
a667188
changing text with setText
fabOnReact Jul 1, 2020
04ce594
check for reactTextUpdate.length
fabOnReact Aug 30, 2020
bab02b5
Fix RNTester example
fabOnReact Aug 30, 2020
784a210
remove console.log
fabOnReact Aug 30, 2020
206fef9
Merge remote-tracking branch 'upstream/master' into fix-cursor-position
fabOnReact Sep 12, 2020
85897b4
Merge remote-tracking branch 'upstream/master' into fix-cursor-position
fabOnReact Sep 12, 2020
0d337da
fix eslint errors
fabOnReact Sep 12, 2020
bbe195a
Merge branch 'master' into fix-cursor-position
fabOnReact Feb 1, 2021
d28ac7b
update selection with maybeSetText
fabOnReact Feb 2, 2021
f8aea21
rn-tester - remove changes to examples
fabOnReact Feb 2, 2021
76cd475
avoid increasing count when changing cursor Position
fabOnReact Feb 2, 2021
1ec343b
update TextInput Example Title
fabOnReact Feb 2, 2021
5957e59
Merge branch 'master' into fix-cursor-position
fabOnReact Feb 2, 2021
3354c31
set mMaximumLength initial value to 0
fabOnReact Feb 2, 2021
6490443
Merge branch 'master' into fix-cursor-position
fabOnReact Feb 3, 2021
53c4868
Merge branch 'master' into fix-cursor-position
fabOnReact Feb 4, 2021
532d772
Merge branch 'master' into fix-cursor-position
fabOnReact Feb 12, 2021
ae74063
Merge branch 'master' into fix-cursor-position
fabOnReact Feb 16, 2021
8e7bd2e
Merge branch 'master' into fix-cursor-position
fabOnReact Mar 3, 2021
8ac631e
Merge branch 'main' into fix-cursor-position
fabOnReact Jan 18, 2022
7ecdea7
revert changes to maybeSetSelection
fabOnReact Jan 18, 2022
b86f498
use int insted of Integer
fabOnReact Mar 18, 2022
ec52724
Merge branch 'main' into fix-cursor-position
fabOnReact Mar 18, 2022
6e6ab1b
Merge branch 'main' into fix-cursor-position
fabOnReact Mar 18, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public class ReactEditText extends AppCompatEditText
private int mFontStyle = ReactTypefaceUtils.UNSET;
private boolean mAutoFocus = false;
private boolean mDidAttachToWindow = false;
private Integer mMaximumTextLength = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be Integer? The wrapped object Integer type has more overhead because the actual operations (less-than, etc) will first convert this to an int. Let's just use int here instead and below as well if possible?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot. I'm reading changes from de44184 and re-evaluating this solution.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @JoshuaGross I added all the changes requested with b86f498 and I updated the PR summary with all the relevant information 🙏 Thanks a lot


private ReactViewBackgroundManager mReactBackgroundManager;

Expand Down Expand Up @@ -331,7 +332,9 @@ public void maybeSetSelection(int eventCounter, int start, int end) {
}

if (start != UNSET && end != UNSET) {
setSelection(start, end);
int validStart = (start > mMaximumTextLength) ? mMaximumTextLength : start;
int validEnd = (end > mMaximumTextLength) ? mMaximumTextLength : end;
setSelection(validStart, validEnd);
}
}

Expand Down Expand Up @@ -510,6 +513,7 @@ public boolean canUpdateWithEventCount(int eventCounter) {

// VisibleForTesting from {@link TextInputEventsTestCase}.
public void maybeSetText(ReactTextUpdate reactTextUpdate) {
mMaximumTextLength = reactTextUpdate.getText().length();
if (isSecureText() && TextUtils.equals(getText(), reactTextUpdate.getText())) {
return;
}
Expand Down Expand Up @@ -553,7 +557,11 @@ public void maybeSetText(ReactTextUpdate reactTextUpdate) {
// When we update text, we trigger onChangeText code that will
// try to update state if the wrapper is available. Temporarily disable
// to prevent an infinite loop.
getText().replace(0, length(), spannableStringBuilder);
Integer startPosition = getSelectionStart();
Integer endPosition = getSelectionEnd();
setText(spannableStringBuilder);
mMaximumTextLength = spannableStringBuilder.length();
maybeSetSelection(mNativeEventCount, startPosition, endPosition);
}
mDisableTextDiffing = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class RewriteExample extends React.Component<$FlowFixMeProps, any> {
multiline={false}
maxLength={limit}
onChangeText={text => {
text = text.replace(/ /g, '_');
text = text.replace(/ /g, '_').toUpperCase();
this.setState({text});
}}
style={styles.default}
Expand Down