From b4025529277d5d9fe9246a76c0650f287277b1a9 Mon Sep 17 00:00:00 2001 From: Dmitry Rykun Date: Tue, 18 Apr 2023 02:47:24 -0700 Subject: [PATCH] Do not send extra onChangeText even wnen instantianting multiline TextView (#36930) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/36930 This diff fixes https://github.com/facebook/react-native/issues/36494 Now this code matches its [Fabric counterpart](https://github.com/facebook/react-native/commit/7b4889937ceb0eccdbb62a610b58525c29928be7). There is also one extra check that `_lastStringStateWasUpdatedWith != nil`. With that in place we don't send extra `onChangeText` event when `attributedText` is assigned for the first time on TextView construction. Changelog: [IOS][Fixed] - Do not send extra onChangeText even wnen instantianting multiline TextView Reviewed By: sammy-SC Differential Revision: D45049135 fbshipit-source-id: 3351b9b62fca5e8722c8da08f2c081b857164458 --- .../Text/TextInput/RCTBackedTextInputDelegateAdapter.m | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/react-native/Libraries/Text/TextInput/RCTBackedTextInputDelegateAdapter.m b/packages/react-native/Libraries/Text/TextInput/RCTBackedTextInputDelegateAdapter.m index 0542362dbe0ac6..1c8f8e055e8399 100644 --- a/packages/react-native/Libraries/Text/TextInput/RCTBackedTextInputDelegateAdapter.m +++ b/packages/react-native/Libraries/Text/TextInput/RCTBackedTextInputDelegateAdapter.m @@ -256,21 +256,21 @@ - (BOOL)textView:(__unused UITextView *)textView shouldChangeTextInRange:(NSRang - (void)textViewDidChange:(__unused UITextView *)textView { - if (_ignoreNextTextInputCall && [_lastStringStateWasUpdatedWith isEqual:_backedTextInputView.attributedText]) { + if (_ignoreNextTextInputCall) { _ignoreNextTextInputCall = NO; return; } - _lastStringStateWasUpdatedWith = _backedTextInputView.attributedText; _textDidChangeIsComing = NO; [_backedTextInputView.textInputDelegate textInputDidChange]; } - (void)textViewDidChangeSelection:(__unused UITextView *)textView { - if (![_lastStringStateWasUpdatedWith isEqual:_backedTextInputView.attributedText]) { + if (_lastStringStateWasUpdatedWith && ![_lastStringStateWasUpdatedWith isEqual:_backedTextInputView.attributedText]) { [self textViewDidChange:_backedTextInputView]; _ignoreNextTextInputCall = YES; } + _lastStringStateWasUpdatedWith = _backedTextInputView.attributedText; [self textViewProbablyDidChangeSelection]; }