fix: Input limited the number of words when entering Chinese bug.

This commit is contained in:
吴尚昆 2022-07-07 12:12:06 +08:00 committed by osborn
parent 35c6d03d14
commit d412d456bb
2 changed files with 15 additions and 4 deletions

View File

@ -38,6 +38,10 @@ function getInput(c: Partial<Input>) {
inputView.onSubmitEditing = (text) => {
inputed.text = `Submited: ${text}`
};
inputView.beforeTextChange = (change) => {
log(`beforeTextChange ${JSON.stringify(change)}`);
return true;
};

View File

@ -569,14 +569,16 @@ - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range r
}
- (void)textViewDidChange:(UITextView *)textView {
if (textView.markedTextRange || textView.text.length > 0) {
UITextRange *textRange = textView.markedTextRange;
if (textRange || textView.text.length > 0) {
self.view.multiLineInput.placeholderLabel.hidden = YES;
} else {
self.view.multiLineInput.placeholderLabel.hidden = NO;
}
if (textView.markedTextRange) return;
if (textRange) {
NSString *text = [textView textInRange:textRange];
if (text.length) return;
}
if (self.maxLength) {
UITextRange *range = textView.selectedTextRange;
textView.text = [self limitToHansMaxLength:self.maxLength.unsignedIntValue text:textView.text];
@ -612,6 +614,11 @@ - (NSString *)limitToHansMaxLength:(NSUInteger)maxLen text:(NSString *)text {
- (void)textFieldDidChange:(UITextField *)textField {
UITextRange *textRange = textField.markedTextRange;
if (textRange) {
NSString *text = [textField textInRange:textRange];
if (text.length) return;
}
if (self.maxLength) {
UITextRange *range = textField.selectedTextRange;
textField.text = [self limitToHansMaxLength:self.maxLength.unsignedIntValue text:textField.text];