Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[iOS] Fixed onChange prop of textinput not be called in some cases #23687

Closed
wants to merge 4 commits into from
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions Libraries/Text/TextInput/RCTBaseTextInputView.m
Original file line number Diff line number Diff line change
Expand Up @@ -423,12 +423,18 @@ - (BOOL)textInputShouldChangeTextInRange:(NSRange)range replacementText:(NSStrin
@"eventCount": @(_nativeEventCount),
});
}

// Sometimes, even we return YES, UIKit may not call textInputDidChange delegate, like click keyboard predictive text. So we have trick here, perform textInputDidChange by ourself.
[self performSelector:@selector(textInputDidChange) withObject:nil afterDelay:0.1];

return YES;
}

- (void)textInputDidChange
{
// If textInputDidChange be called by UIKit delegate, we cancel our own perform operation
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(textInputDidChange) object:nil];

[self updateLocalData];

id<RCTBackedTextInputViewProtocol> backedTextInputView = self.backedTextInputView;
Expand All @@ -446,15 +452,15 @@ - (void)textInputDidChange
[self textInputDidChangeSelection];
_predictedText = backedTextInputView.attributedText.string;
}

_nativeEventCount++;

if (_onChange) {
_onChange(@{
@"text": self.attributedText.string,
@"target": self.reactTag,
@"eventCount": @(_nativeEventCount),
});
@"text": self.attributedText.string,
@"target": self.reactTag,
@"eventCount": @(_nativeEventCount),
});
}
}

Expand Down