mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-05-06 17:52:57 +08:00
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: https://github.com/facebook/react-native/pull/23545
Differential Revision: D14146581
Pulled By: cpojer
fbshipit-source-id: f53b1312ae55fad9fc10430ab94784c1a9ad4723
This commit is contained in:
committed by
Facebook Github Bot
parent
9375a12620
commit
f08c94bd36
@@ -305,9 +305,9 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithFrame:(CGRect)frame)
|
||||
}
|
||||
|
||||
if (_maxLength) {
|
||||
NSUInteger allowedLength = _maxLength.integerValue - backedTextInputView.attributedText.string.length + range.length;
|
||||
NSInteger allowedLength = _maxLength.integerValue - backedTextInputView.attributedText.string.length + range.length;
|
||||
|
||||
if (text.length > allowedLength) {
|
||||
if (allowedLength < 0 || text.length > 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
|
||||
|
||||
Reference in New Issue
Block a user