Skip to content

Commit c5c0a55

Browse files
committed
iOS: Fixed the bug where a Backspace event was emitted after clearing a text in TextInput by an empty string
1 parent 9c80506 commit c5c0a55

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Libraries/Text/TextInput/RCTBaseTextInputView.m

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,12 @@ - (BOOL)textInputShouldChangeTextInRange:(NSRange)range replacementText:(NSStrin
278278

279279
NSString *previousText = [_predictedText substringWithRange:range] ?: @"";
280280

281-
if (_predictedText) {
281+
// After clearing the text by replacing it with an empty string, `_predictedText`
282+
// still preserves the deleted text.
283+
// As the first character in the TextInput always comes with the range value (0, 0),
284+
// we should check the range value in order to avoid appending a character to the deleted string
285+
// (which caused the issue #18374)
286+
if (!NSEqualRanges(range, NSMakeRange(0, 0)) && _predictedText) {
282287
_predictedText = [_predictedText stringByReplacingCharactersInRange:range withString:text];
283288
} else {
284289
_predictedText = text;

0 commit comments

Comments
 (0)