Skip to content

Commit f08c94b

Browse files
jsfufacebook-github-bot
authored andcommitted
fix the TextInput can't control input length when value's length > maxLength (#23545)
Summary: I found the TextInput can't control input length when default value's length > maxLength. for example: 1.Set the value in special cases ``` <TextInput value={'12345678'} maxLength={6}/> ``` 2.Quickly press the keyboard with multiple fingers ``` // RCTBaseTextInputView.m …… if (_maxLength) { NSUInteger allowedLength = _maxLength.integerValue - backedTextInputView.attributedText.string.length + range.length; if (text.length > allowedLength) { …… ``` when value's length > maxLength,the allowedLength not a negative number.it was transformed into a big number,because it is type NSUInteger.so the `text.length > allowedLength` always false. [iOS][Fixed] - fix the TextInput can't control input length when value's length > maxLength Pull Request resolved: #23545 Differential Revision: D14146581 Pulled By: cpojer fbshipit-source-id: f53b1312ae55fad9fc10430ab94784c1a9ad4723
1 parent 9375a12 commit f08c94b

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

Libraries/Text/TextInput/RCTBaseTextInputView.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,9 +305,9 @@ - (BOOL)textInputShouldChangeTextInRange:(NSRange)range replacementText:(NSStrin
305305
}
306306

307307
if (_maxLength) {
308-
NSUInteger allowedLength = _maxLength.integerValue - backedTextInputView.attributedText.string.length + range.length;
308+
NSInteger allowedLength = _maxLength.integerValue - backedTextInputView.attributedText.string.length + range.length;
309309

310-
if (text.length > allowedLength) {
310+
if (allowedLength < 0 || text.length > allowedLength) {
311311
// If we typed/pasted more than one character, limit the text inputted.
312312
if (text.length > 1) {
313313
// Truncate the input string so the result is exactly maxLength

0 commit comments

Comments
 (0)