Skip to content

Commit

Permalink
iOS: Fixed the bug where a Backspace event was emitted when entering …
Browse files Browse the repository at this point in the history
…characters after clearing a text in TextInput by an empty string (#18627)

Summary:
The bug #18374 was caused by the loose condition to execute `stringByReplacingCharactersInRange` in the method `textInputShouldChangeTextInRange` . As a result, `findMismatch` wrongly returning `true` which ends up the Backspace event being fired in another `textInputShouldChangeTextInRange` call in `textInputDidChange`.

Closes facebook/react-native#18627

Differential Revision: D8436331

Pulled By: hramos

fbshipit-source-id: ec75a6ca926061cbf7cb106db652f2b4a71c9a0c
  • Loading branch information
hamaron authored and aleclarson committed Feb 23, 2019
1 parent be0a536 commit 35f9585
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Libraries/Text/TextInput/RCTBaseTextInputView.m
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,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 copy];
Expand Down

0 comments on commit 35f9585

Please sign in to comment.