Skip to content

Commit

Permalink
Switch order of onSelectionChange and onChange events on iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
s77rt committed Dec 9, 2022
1 parent 43e7f50 commit 07b2207
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Libraries/Text/TextInput/RCTBackedTextInputDelegateAdapter.m
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ @interface RCTBackedTextViewDelegateAdapter () <UITextViewDelegate>

@implementation RCTBackedTextViewDelegateAdapter {
__weak UITextView<RCTBackedTextInputViewProtocol> *_backedTextInputView;
NSAttributedString *_lastStringStateWasUpdatedWith;
BOOL _ignoreNextTextInputCall;
BOOL _textDidChangeIsComing;
UITextRange *_previousSelectedTextRange;
}
Expand Down Expand Up @@ -254,12 +256,21 @@ - (BOOL)textView:(__unused UITextView *)textView shouldChangeTextInRange:(NSRang

- (void)textViewDidChange:(__unused UITextView *)textView
{
if (_ignoreNextTextInputCall && [_lastStringStateWasUpdatedWith isEqual:_backedTextInputView.attributedText]) {
_ignoreNextTextInputCall = NO;
return;
}
_lastStringStateWasUpdatedWith = _backedTextInputView.attributedText;
_textDidChangeIsComing = NO;
[_backedTextInputView.textInputDelegate textInputDidChange];
}

- (void)textViewDidChangeSelection:(__unused UITextView *)textView
{
if (![_lastStringStateWasUpdatedWith isEqual:_backedTextInputView.attributedText]) {
[self textViewDidChange:_backedTextInputView];
_ignoreNextTextInputCall = YES;
}
[self textViewProbablyDidChangeSelection];
}

Expand Down

0 comments on commit 07b2207

Please sign in to comment.