From a804c0f22b4b11b3d9632dc59a6da14f6c4325e3 Mon Sep 17 00:00:00 2001 From: Dmitry Rykun Date: Tue, 18 Apr 2023 05:39:48 -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: 62fa281308b9d2e0a807d024f08d8a214bd99b5e --- .../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]; }