fix: onChangeText should be called only once if changed via js in a multiline textinput#45401
fix: onChangeText should be called only once if changed via js in a multiline textinput#45401deepanshushuklad11 wants to merge 1 commit intofacebook:mainfrom deepanshushuklad11:fix/onchange_called_multipletimes
Conversation
Base commit: d68a177 |
|
@cortinico @cipolleschi Any update on this |
cipolleschi
left a comment
There was a problem hiding this comment.
Hi @deepanshushuklad11, thanks for the fix and sorry for te late reply. I missed the PR on friday.
I see that this is the fix only for the Old Arch. Can you verify whether the problem exists also in the New Arch and fix it there as well?
The component where I'd start looking into is RCTTextInputComponentView.
Thank you so much!
@cipolleschi Its not happening on new arch |
|
@cipolleschi Anything else required from my end? |
|
@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
|
Sorry for the delay! I imported the PR, let's see if the internal CI is happy about it! |
Hey @cipolleschi any update ? |
|
Hi @deepanshushuklad11, sorry for the delay, I have been quite busy the past week. I'll try to get to it this week. |
|
@cipolleschi merged this pull request in d88dd14. |
|
This pull request was successfully merged by @deepanshushuklad11 in d88dd14 When will my fix make it into a release? | How to file a pick request? |
Summary: Fixes #47563 It seems like a regression from #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: #48126 Test Plan: The issue could be reproduced in the rn-tester. See my videos with the before and after the fix. <details> <summary>Before:</summary> https://github.com/user-attachments/assets/86fd67eb-fc14-469a-a5f8-8e83b49f857c </details> <details> <summary>After:</summary> https://github.com/user-attachments/assets/368383b1-c1bd-4e0b-ac44-c78022462fa0 </details> Reviewed By: cortinico Differential Revision: D67025182 Pulled By: cipolleschi fbshipit-source-id: 720c400eef362618106ae434aef421c7529214fe
Summary: Fixes #47563 It seems like a regression from #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: #48126 Test Plan: The issue could be reproduced in the rn-tester. See my videos with the before and after the fix. <details> <summary>Before:</summary> https://github.com/user-attachments/assets/86fd67eb-fc14-469a-a5f8-8e83b49f857c </details> <details> <summary>After:</summary> https://github.com/user-attachments/assets/368383b1-c1bd-4e0b-ac44-c78022462fa0 </details> Reviewed By: cortinico Differential Revision: D67025182 Pulled By: cipolleschi fbshipit-source-id: 720c400eef362618106ae434aef421c7529214fe
Summary: Fixes #47563 It seems like a regression from #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: #48126 Test Plan: The issue could be reproduced in the rn-tester. See my videos with the before and after the fix. <details> <summary>Before:</summary> https://github.com/user-attachments/assets/86fd67eb-fc14-469a-a5f8-8e83b49f857c </details> <details> <summary>After:</summary> https://github.com/user-attachments/assets/368383b1-c1bd-4e0b-ac44-c78022462fa0 </details> Reviewed By: cortinico Differential Revision: D67025182 Pulled By: cipolleschi fbshipit-source-id: 720c400eef362618106ae434aef421c7529214fe
Fixes 44566
Summary:
Issue was onChangeText was called 5-6 times if maxLength was set in a multiline component and TextInput Value was changed via state update.
`if (_maxLength) {
NSInteger allowedLength = MAX(
_maxLength.integerValue - (NSInteger)backedTextInputView.attributedText.string.length + (NSInteger)range.length,
0);
This is the original code snippet.
It was happening because of wrong check of maxLength with text length
if (text.length > allowedLength)this should be(text.length > _maxLength.integerValue)andif (allowedLength <= 0)we should not change the string and firetextInputDidChangeChangelog:
[IOS] [FIXED] : Fixing maxLength check which was firing onChange multiple times
For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->
Test Plan:
Tested in Ios

Ran yarn test