Skip to content

Commit 55cca5c

Browse files
s77rtOlimpiaZurek
authored andcommitted
Switch order of onSelectionChange and onChange events on iOS (facebook#35603)
Summary: Switched order of onSelectionChange and onChange events on iOS This was already fixed but for fabric only https://github.com/facebook/react-native/blob/main/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm#L36-L46 This PR is a complementary of facebook@7b48899 Fixes facebook#28865 ## Changelog [IOS] [FIXED] - onSelectionChange() is fired before onChange() on multiline TextInput Pull Request resolved: facebook#35603 Test Plan: Reproduce the minimal example provided here facebook#28865 Verify that the events order is onChange then onSelectionChange with no duplicates Reviewed By: cipolleschi Differential Revision: D41947673 Pulled By: dmytrorykun fbshipit-source-id: cf452a6101400b1b54295c83fa7735449d91e781
1 parent 1ea6e3a commit 55cca5c

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Libraries/Text/TextInput/RCTBackedTextInputDelegateAdapter.m

+11
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ @interface RCTBackedTextViewDelegateAdapter () <UITextViewDelegate>
168168

169169
@implementation RCTBackedTextViewDelegateAdapter {
170170
__weak UITextView<RCTBackedTextInputViewProtocol> *_backedTextInputView;
171+
NSAttributedString *_lastStringStateWasUpdatedWith;
172+
BOOL _ignoreNextTextInputCall;
171173
BOOL _textDidChangeIsComing;
172174
UITextRange *_previousSelectedTextRange;
173175
}
@@ -254,12 +256,21 @@ - (BOOL)textView:(__unused UITextView *)textView shouldChangeTextInRange:(NSRang
254256

255257
- (void)textViewDidChange:(__unused UITextView *)textView
256258
{
259+
if (_ignoreNextTextInputCall && [_lastStringStateWasUpdatedWith isEqual:_backedTextInputView.attributedText]) {
260+
_ignoreNextTextInputCall = NO;
261+
return;
262+
}
263+
_lastStringStateWasUpdatedWith = _backedTextInputView.attributedText;
257264
_textDidChangeIsComing = NO;
258265
[_backedTextInputView.textInputDelegate textInputDidChange];
259266
}
260267

261268
- (void)textViewDidChangeSelection:(__unused UITextView *)textView
262269
{
270+
if (![_lastStringStateWasUpdatedWith isEqual:_backedTextInputView.attributedText]) {
271+
[self textViewDidChange:_backedTextInputView];
272+
_ignoreNextTextInputCall = YES;
273+
}
263274
[self textViewProbablyDidChangeSelection];
264275
}
265276

0 commit comments

Comments
 (0)