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 11 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 @Nullable Integer mMaximumTextLength = null;

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,10 @@ 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();
setText(spannableStringBuilder);
mMaximumTextLength = spannableStringBuilder.length();
setSelection(startPosition);
}
mDisableTextDiffing = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,16 @@ class RewriteExample extends React.Component<$FlowFixMeProps, any> {
this.state = {text: ''};
}
render() {
const limit = 20;
const limit = 100;
const remainder = limit - this.state.text.length;
const remainderColor = remainder > 5 ? 'blue' : 'red';
return (
<View style={styles.rewriteContainer}>
<TextInput
testID="rewrite_sp_underscore_input"
autoCorrect={false}
multiline={false}
maxLength={limit}
onChangeText={text => {
text = text.replace(/ /g, '_');
text = text.replace(/ /g, '_').toUpperCase();
this.setState({text});
}}
style={styles.default}
Expand All @@ -122,18 +120,40 @@ class RewriteExampleInvalidCharacters extends React.Component<
> {
constructor(props) {
super(props);
this.state = {text: ''};
this.state = {text: '', selection: {start: -1, end: -1}};
}

onSelectionChangeHandler = ({nativeEvent: {selection}}) => {
const {start, end} = selection;
const {text} = this.state;
const maxEnd = text.length;
const validEnd = end > maxEnd ? maxEnd : end;
const validStart = start > maxEnd ? maxEnd : start;
const newSelection = {start: validStart, end: validEnd};
this.setState({selection: newSelection});
};
fabOnReact marked this conversation as resolved.
Show resolved Hide resolved

render() {
const {
fabOnReact marked this conversation as resolved.
Show resolved Hide resolved
text,
selection: {start, end},
} = this.state;
return (
<View style={styles.rewriteContainer}>
<TextInput
testID="rewrite_no_sp_input"
autoCorrect={false}
multiline={false}
multiline={true}
onChangeText={text => {
this.setState({text: text.replace(/\s/g, '')});
const newText = text.replace(/\s/g, '');
fabOnReact marked this conversation as resolved.
Show resolved Hide resolved
const newEnd = end - 1;
this.setState({
text: newText,
selection: {start: newEnd, end: newEnd},
});
}}
onSelectionChange={this.onSelectionChangeHandler}
selection={{start: start, end: end}}
style={styles.default}
value={this.state.text}
/>
Expand Down Expand Up @@ -457,8 +477,7 @@ module.exports = ([
},
},
{
name: 'maxLength',
title: "Live Re-Write (<sp> -> '_') + maxLength",
title: "Live Re-Write (<sp> -> '_' -> toUpperCase) + maxLength",
render: function(): React.Node {
return <RewriteExample />;
},
Expand Down