From 8c6da37268e2ccb29c76e389d15b7908098d96e4 Mon Sep 17 00:00:00 2001 From: Tommy Nguyen Date: Wed, 8 Jul 2020 11:12:35 +0200 Subject: [PATCH] Fix multiline TextInput crash when inserting/removing lots of text It seems that the returned string that we use to set `previousText` can be mutated while it is waiting to be processed by RCTBridge. --- Libraries/Text/TextInput/RCTBaseTextInputView.m | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Libraries/Text/TextInput/RCTBaseTextInputView.m b/Libraries/Text/TextInput/RCTBaseTextInputView.m index 37890b074f03e4..8b7ef9dc644096 100644 --- a/Libraries/Text/TextInput/RCTBaseTextInputView.m +++ b/Libraries/Text/TextInput/RCTBaseTextInputView.m @@ -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]; } @@ -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]; } @@ -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) @@ -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; @@ -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), });