Skip to content

Commit ab0ce82

Browse files
lunaleapsbillnbell3
authored andcommitted
Back out "Fix issue#11068 of duplicating characters when replacing letters to lowercase or uppercase in TextInput"
Summary: Changelog: [Internal] - Back out facebook#35929 due to facebook#35929 (comment) Original Phabricator Diff: D47243817 Reviewed By: sunzhaoyuan Differential Revision: D47785787 fbshipit-source-id: 81598be3f0b4e0e753dfbee4cee781673f900827
1 parent 040bc03 commit ab0ce82

File tree

1 file changed

+7
-48
lines changed
  • packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput

1 file changed

+7
-48
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java

Lines changed: 7 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -632,13 +632,10 @@ public void maybeSetText(ReactTextUpdate reactTextUpdate) {
632632
if (reactTextUpdate.getText().length() == 0) {
633633
setText(null);
634634
} else {
635-
boolean shouldRestoreComposingSpans = length() == spannableStringBuilder.length();
636-
635+
// When we update text, we trigger onChangeText code that will
636+
// try to update state if the wrapper is available. Temporarily disable
637+
// to prevent an infinite loop.
637638
getText().replace(0, length(), spannableStringBuilder);
638-
639-
if (shouldRestoreComposingSpans) {
640-
restoreComposingSpansToTextFrom(spannableStringBuilder);
641-
}
642639
}
643640
mDisableTextDiffing = false;
644641

@@ -653,13 +650,10 @@ public void maybeSetText(ReactTextUpdate reactTextUpdate) {
653650
}
654651

655652
/**
656-
* Remove and/or add {@link Spanned#SPAN_EXCLUSIVE_EXCLUSIVE} spans, since they should only exist
657-
* as long as the text they cover is the same unless they are {@link Spanned#SPAN_COMPOSING}. All
658-
* other spans will remain the same, since they will adapt to the new text, hence why {@link
659-
* SpannableStringBuilder#replace} never removes them. Keep copy of {@link Spanned#SPAN_COMPOSING}
660-
* Spans in {@param spannableStringBuilder}, because they are important for keyboard suggestions.
661-
* Without keeping these Spans, suggestions default to be put after the current selection
662-
* position, possibly resulting in letter duplication.
653+
* Remove and/or add {@link Spanned.SPAN_EXCLUSIVE_EXCLUSIVE} spans, since they should only exist
654+
* as long as the text they cover is the same. All other spans will remain the same, since they
655+
* will adapt to the new text, hence why {@link SpannableStringBuilder#replace} never removes
656+
* them.
663657
*/
664658
private void manageSpans(SpannableStringBuilder spannableStringBuilder) {
665659
Object[] spans = getText().getSpans(0, length(), Object.class);
@@ -668,7 +662,6 @@ private void manageSpans(SpannableStringBuilder spannableStringBuilder) {
668662
int spanFlags = getText().getSpanFlags(span);
669663
boolean isExclusiveExclusive =
670664
(spanFlags & Spanned.SPAN_EXCLUSIVE_EXCLUSIVE) == Spanned.SPAN_EXCLUSIVE_EXCLUSIVE;
671-
boolean isComposing = (spanFlags & Spanned.SPAN_COMPOSING) == Spanned.SPAN_COMPOSING;
672665

673666
// Remove all styling spans we might have previously set
674667
if (span instanceof ReactSpan) {
@@ -683,12 +676,6 @@ private void manageSpans(SpannableStringBuilder spannableStringBuilder) {
683676
final int spanStart = getText().getSpanStart(span);
684677
final int spanEnd = getText().getSpanEnd(span);
685678

686-
// We keep a copy of Composing spans
687-
if (isComposing) {
688-
spannableStringBuilder.setSpan(span, spanStart, spanEnd, spanFlags);
689-
continue;
690-
}
691-
692679
// Make sure the span is removed from existing text, otherwise the spans we set will be
693680
// ignored or it will cover text that has changed.
694681
getText().removeSpan(span);
@@ -816,34 +803,6 @@ private void addSpansFromStyleAttributes(SpannableStringBuilder workingText) {
816803
}
817804
}
818805

819-
/**
820-
* Attaches the {@link Spanned#SPAN_COMPOSING} from {@param spannableStringBuilder} to {@link
821-
* ReactEditText#getText}
822-
*
823-
* <p>See {@link ReactEditText#manageSpans} for more details. Also
824-
* https://github.com/facebook/react-native/issues/11068
825-
*/
826-
private void restoreComposingSpansToTextFrom(SpannableStringBuilder spannableStringBuilder) {
827-
Editable text = getText();
828-
if (text == null) {
829-
return;
830-
}
831-
Object[] spans = spannableStringBuilder.getSpans(0, length(), Object.class);
832-
for (Object span : spans) {
833-
int spanFlags = spannableStringBuilder.getSpanFlags(span);
834-
boolean isComposing = (spanFlags & Spanned.SPAN_COMPOSING) == Spanned.SPAN_COMPOSING;
835-
836-
if (!isComposing) {
837-
continue;
838-
}
839-
840-
final int spanStart = spannableStringBuilder.getSpanStart(span);
841-
final int spanEnd = spannableStringBuilder.getSpanEnd(span);
842-
843-
text.setSpan(span, spanStart, spanEnd, spanFlags);
844-
}
845-
}
846-
847806
private static boolean sameTextForSpan(
848807
final Editable oldText,
849808
final SpannableStringBuilder newText,

0 commit comments

Comments
 (0)