From 23e087fc267cefd9e86ff0634f8ad3f99d6d68bd Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Thu, 14 Jul 2016 07:39:18 -0700 Subject: [PATCH] Fix TextInput stack overflow when pasting text in multiline input with maxlength Summary: When pasting text longer than maxlenght, the textDidChange: call we did would end calling back into textView:shouldChange: because we saw an unexpected multi-character change. Since this is an expected mutation, update predictedText appropriately. Reviewed By: majak Differential Revision: D3561524 fbshipit-source-id: 07bb78d830ccfa3aed6ee274dc30adeadce9e1f8 --- Examples/UIExplorer/js/TextInputExample.ios.js | 6 ++++++ Libraries/Text/RCTTextView.m | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/Examples/UIExplorer/js/TextInputExample.ios.js b/Examples/UIExplorer/js/TextInputExample.ios.js index 6c166b391..a65d55393 100644 --- a/Examples/UIExplorer/js/TextInputExample.ios.js +++ b/Examples/UIExplorer/js/TextInputExample.ios.js @@ -679,6 +679,12 @@ exports.examples = [ keyboardType="url" style={[styles.multiline, styles.multilineWithFontStyles]} /> + allowedLength) { + // If we typed/pasted more than one character, limit the text inputted if (text.length > 1) { // Truncate the input string so the result is exactly maxLength NSString *limitedString = [text substringToIndex:allowedLength]; NSMutableString *newString = textView.text.mutableCopy; [newString replaceCharactersInRange:range withString:limitedString]; textView.text = newString; + _predictedText = newString; + // Collapse selection at end of insert to match normal paste behavior UITextPosition *insertEnd = [textView positionFromPosition:textView.beginningOfDocument offset:(range.location + allowedLength)]; textView.selectedTextRange = [textView textRangeFromPosition:insertEnd toPosition:insertEnd]; + [self textViewDidChange:textView]; } return NO;