From 84d0ec24948a2220ed29513b91b845b5afa46d3e Mon Sep 17 00:00:00 2001 From: jpstrikesback Date: Thu, 26 Apr 2018 09:19:14 -0400 Subject: [PATCH] Tracking PR #18627 --- Libraries/Text/TextInput/RCTBaseTextInputView.m | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Libraries/Text/TextInput/RCTBaseTextInputView.m b/Libraries/Text/TextInput/RCTBaseTextInputView.m index d9c47ff16311d4..99b41df6c35611 100644 --- a/Libraries/Text/TextInput/RCTBaseTextInputView.m +++ b/Libraries/Text/TextInput/RCTBaseTextInputView.m @@ -268,7 +268,12 @@ - (BOOL)textInputShouldChangeTextInRange:(NSRange)range replacementText:(NSStrin NSString *previousText = [_predictedText substringWithRange:range] ?: @""; - if (_predictedText) { + // After clearing the text by replacing it with an empty string, `_predictedText` + // still preserves the deleted text. + // As the first character in the TextInput always comes with the range value (0, 0), + // we should check the range value in order to avoid appending a character to the deleted string + // (which caused the issue #18374) + if (!NSEqualRanges(range, NSMakeRange(0, 0)) && _predictedText) { _predictedText = [_predictedText stringByReplacingCharactersInRange:range withString:text]; } else { _predictedText = text;