feat:Input add beforeTextChange API

This commit is contained in:
pengfei.zhou
2021-06-11 17:47:06 +08:00
committed by osborn
parent e528630f71
commit 9fed9e431c
11 changed files with 95 additions and 2 deletions

View File

@@ -20,6 +20,7 @@
// Created by on 2019/12/11.
//
#import <JavaScriptCore/JavaScriptCore.h>
#import "DoricInputNode.h"
#import "DoricUtil.h"
#import "DoricPromise.h"
@@ -76,6 +77,7 @@ @interface DoricInputNode () <UITextViewDelegate>
@property(nonatomic, copy) onFocusChangeBlock onFocusChange;
@property(nonatomic, copy) onSubmitEditingBlock onSubmitEditing;
@property(nonatomic, strong) NSNumber *maxLength;
@property(nonatomic, copy) NSString *beforeTextChangeFuncId;
@end
@implementation DoricInputNode
@@ -116,6 +118,8 @@ - (void)blendView:(DoricInputView *)view forPropName:(NSString *)name propValue:
} else {
view.textContainer.maximumNumberOfLines = 0;
}
} else if ([name isEqualToString:@"beforeTextChange"]) {
self.beforeTextChangeFuncId = prop;
} else if ([name isEqualToString:@"hintText"]) {
view.placeholderLabel.text = (NSString *) prop;
} else if ([name isEqualToString:@"hintTextColor"]) {
@@ -283,6 +287,22 @@ - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range r
return NO;
}
}
if (self.beforeTextChangeFuncId) {
DoricAsyncResult *asyncResult = [self
pureCallJSResponse:self.beforeTextChangeFuncId,
@{
@"editing": textView.text,
@"start": @(range.location),
@"length": @(range.length),
@"replacement": text,
},
nil];
NSNumber *ret = [asyncResult waitUntilResult:^(JSValue *model) {
return [model toNumber];
}];
return [ret boolValue];
}
return YES;
}