From 73ffe1394f22650a63bae2d5672e72712b027bfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateo=20Guzm=C3=A1n?= Date: Tue, 10 Dec 2024 11:57:48 -0800 Subject: [PATCH] Paper: TextInput `maxLength` is not working in old arch (#48126) Summary: Fixes https://github.com/facebook/react-native/issues/47563 It seems like a regression from https://github.com/facebook/react-native/issues/45401, where it was aimed to fix `onChangeText` being called multiple times when changing the text programmatically in an input with the `multiline` prop set as true. This PR reverts that partially, as the `maxLength` check is not being evaluated correctly before setting the text. Not reverting it completely as when removing the second part of the fix, the `onChangeText` gets called multiple times again. ## Changelog: [IOS] [FIXED] - Fixing TextInput `maxLength` not working in old arch Pull Request resolved: https://github.com/facebook/react-native/pull/48126 Test Plan: The issue could be reproduced in the rn-tester. See my videos with the before and after the fix.
Before: https://github.com/user-attachments/assets/86fd67eb-fc14-469a-a5f8-8e83b49f857c
After: https://github.com/user-attachments/assets/368383b1-c1bd-4e0b-ac44-c78022462fa0
Reviewed By: cortinico Differential Revision: D67025182 Pulled By: cipolleschi fbshipit-source-id: 720c400eef362618106ae434aef421c7529214fe --- .../Libraries/Text/TextInput/RCTBaseTextInputView.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputView.mm b/packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputView.mm index 3869e58589b..127d93f8cb8 100644 --- a/packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputView.mm +++ b/packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputView.mm @@ -457,7 +457,7 @@ RCT_NOT_IMPLEMENTED(-(instancetype)initWithFrame : (CGRect)frame) _maxLength.integerValue - (NSInteger)backedTextInputView.attributedText.string.length + (NSInteger)range.length, 0); - if (text.length > _maxLength.integerValue) { + if (text.length > allowedLength) { // If we typed/pasted more than one character, limit the text inputted. if (text.length > 1) { if (allowedLength > 0) {