iOS:Input support maxLength

This commit is contained in:
pengfei.zhou 2020-04-30 18:31:26 +08:00 committed by osborn
parent 0c6fa027b1
commit fd762bac86

View File

@ -31,7 +31,7 @@ @interface DoricInputNode()<UITextViewDelegate>
@property(nonatomic, copy) onTextChangeBlock onTextChange;
@property(nonatomic, copy) onFocusChangeBlock onFocusShange;
@property(nonatomic, strong) UILabel *placeholderLabel;
@property(nonatomic, strong) NSNumber *maxLength;
@end
@implementation DoricInputNode
@ -85,6 +85,8 @@ - (void)blendView:(UITextView *)view forPropName:(NSString *)name propValue:(id)
self.onFocusShange = nil;
}
} else if ([name isEqualToString:@"maxLength"]) {
self.maxLength = prop;
} else {
[super blendView:view forPropName:name propValue:prop];
}
@ -136,6 +138,11 @@ - (BOOL)textViewShouldEndEditing:(UITextView *)textView {
}
- (void)textViewDidChange:(UITextView *)textView {
if (self.maxLength) {
if (textView.text.length > self.maxLength.unsignedIntValue) {
textView.text = [textView.text substringToIndex:self.maxLength.unsignedIntValue];
}
}
if (self.onTextChange) {
self.onTextChange(textView.text, self);
}