feat:Input add beforeTextChange API
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user