Skip to content

Commit

Permalink
Fix multiline TextInput crash when inserting/removing lots of text
Browse files Browse the repository at this point in the history
It seems that the returned string that we use to set `previousText` can
be mutated while it is waiting to be processed by RCTBridge.
  • Loading branch information
tido64 committed Jul 8, 2020
1 parent d7e8504 commit 8c6da37
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions Libraries/Text/TextInput/RCTBaseTextInputView.m
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ - (void)textInputDidBeginEditing

[_eventDispatcher sendTextEventWithType:RCTTextEventTypeFocus
reactTag:self.reactTag
text:self.backedTextInputView.attributedText.string
text:[self.backedTextInputView.attributedText.string copy] // [TODO(macOS Candidate ISS#2710739)
key:nil
eventCount:_nativeEventCount];
}
Expand All @@ -389,13 +389,13 @@ - (void)textInputDidEndEditing
{
[_eventDispatcher sendTextEventWithType:RCTTextEventTypeEnd
reactTag:self.reactTag
text:self.backedTextInputView.attributedText.string
text:[self.backedTextInputView.attributedText.string copy] // [TODO(macOS Candidate ISS#2710739)
key:nil
eventCount:_nativeEventCount];

[_eventDispatcher sendTextEventWithType:RCTTextEventTypeBlur
reactTag:self.reactTag
text:self.backedTextInputView.attributedText.string
text:[self.backedTextInputView.attributedText.string copy] // [TODO(macOS Candidate ISS#2710739)
key:nil
eventCount:_nativeEventCount];
}
Expand All @@ -412,7 +412,7 @@ - (BOOL)textInputShouldReturn
#endif // ]TODO(macOS Candidate ISS#2710739)
[_eventDispatcher sendTextEventWithType:RCTTextEventTypeSubmit
reactTag:self.reactTag
text:self.backedTextInputView.attributedText.string
text:[self.backedTextInputView.attributedText.string copy] // [TODO(macOS Candidate ISS#2710739)
key:nil
eventCount:_nativeEventCount];
#if TARGET_OS_OSX // [TODO(macOS Candidate ISS#2710739)
Expand Down Expand Up @@ -475,7 +475,7 @@ - (BOOL)textInputShouldChangeTextInRange:(NSRange)range replacementText:(NSStrin
}
}

NSString *previousText = backedTextInputView.attributedText.string ?: @"";
NSString *previousText = [backedTextInputView.attributedText.string copy] ?: @""; // TODO(OSS Candidate ISS#2710739)

if (range.location + range.length > backedTextInputView.attributedText.string.length) {
_predictedText = backedTextInputView.attributedText.string;
Expand Down Expand Up @@ -522,7 +522,7 @@ - (void)textInputDidChange

if (_onChange) {
_onChange(@{
@"text": self.attributedText.string,
@"text": [self.attributedText.string copy], // [TODO(macOS Candidate ISS#2710739)
@"target": self.reactTag,
@"eventCount": @(_nativeEventCount),
});
Expand Down

0 comments on commit 8c6da37

Please sign in to comment.