adjust code style and add default case

This commit is contained in:
pengfei.zhou 2020-06-13 11:53:21 +08:00 committed by osborn
parent 497bd0ac45
commit 4a788eb4bb
3 changed files with 45 additions and 38 deletions

View File

@ -136,6 +136,9 @@ public class InputNode extends ViewNode<EditText> implements TextWatcher, View.O
case 4: case 4:
mView.setInputType(InputType.TYPE_CLASS_PHONE); mView.setInputType(InputType.TYPE_CLASS_PHONE);
break; break;
default:
mView.setInputType(InputType.TYPE_CLASS_TEXT);
break;
} }
} }
break; break;

View File

@ -24,8 +24,9 @@
#import "DoricUtil.h" #import "DoricUtil.h"
#import "DoricPromise.h" #import "DoricPromise.h"
typedef void (^onTextChangeBlock)(NSString *text,DoricInputNode *node); typedef void (^onTextChangeBlock)(NSString *text, DoricInputNode *node);
typedef void (^onFocusChangeBlock)(BOOL focused,DoricInputNode *node);
typedef void (^onFocusChangeBlock)(BOOL focused, DoricInputNode *node);
@implementation DoricInputView @implementation DoricInputView
@ -68,7 +69,7 @@ - (CGSize)sizeThatFits:(CGSize)size {
@end @end
@interface DoricInputNode()<UITextViewDelegate> @interface DoricInputNode () <UITextViewDelegate>
@property(nonatomic, copy) onTextChangeBlock onTextChange; @property(nonatomic, copy) onTextChangeBlock onTextChange;
@property(nonatomic, copy) onFocusChangeBlock onFocusShange; @property(nonatomic, copy) onFocusChangeBlock onFocusShange;
@property(nonatomic, strong) NSNumber *maxLength; @property(nonatomic, strong) NSNumber *maxLength;
@ -106,57 +107,56 @@ - (void)blendView:(DoricInputView *)view forPropName:(NSString *)name propValue:
BOOL mutilin = [(NSNumber *) prop boolValue]; BOOL mutilin = [(NSNumber *) prop boolValue];
if (!mutilin) { if (!mutilin) {
view.textContainer.maximumNumberOfLines = 1; view.textContainer.maximumNumberOfLines = 1;
}else { } else {
view.textContainer.maximumNumberOfLines = 0; view.textContainer.maximumNumberOfLines = 0;
} }
} else if ([name isEqualToString:@"hintText"]) { } else if ([name isEqualToString:@"hintText"]) {
view.placeholderLabel.text = (NSString *)prop; view.placeholderLabel.text = (NSString *) prop;
} else if ([name isEqualToString:@"hintTextColor"]) { } else if ([name isEqualToString:@"hintTextColor"]) {
view.placeholderLabel.textColor = DoricColor(prop); view.placeholderLabel.textColor = DoricColor(prop);
} else if ([name isEqualToString:@"onTextChange"]) { } else if ([name isEqualToString:@"onTextChange"]) {
if ([prop isKindOfClass:[NSString class]]) { if ([prop isKindOfClass:[NSString class]]) {
self.onTextChange = ^(NSString *text, DoricInputNode *node) { self.onTextChange = ^(NSString *text, DoricInputNode *node) {
[node callJSResponse:prop,text,nil]; [node callJSResponse:prop, text, nil];
}; };
}else { } else {
self.onTextChange = nil; self.onTextChange = nil;
} }
} else if ([name isEqualToString:@"onFocusChange"]) { } else if ([name isEqualToString:@"onFocusChange"]) {
if ([prop isKindOfClass:[NSString class]]) { if ([prop isKindOfClass:[NSString class]]) {
self.onFocusShange = ^(BOOL focused, DoricInputNode *node) { self.onFocusShange = ^(BOOL focused, DoricInputNode *node) {
[node callJSResponse:prop,@(focused),nil]; [node callJSResponse:prop, @(focused), nil];
}; };
}else { } else {
self.onFocusShange = nil; self.onFocusShange = nil;
} }
} else if ([name isEqualToString:@"maxLength"]) { } else if ([name isEqualToString:@"maxLength"]) {
self.maxLength = prop; self.maxLength = prop;
} } else if ([name isEqualToString:@"inputType"]) {
else if([name isEqualToString:@"inputType"]){
switch ([prop integerValue]) { switch ([prop integerValue]) {
case 1: { case 1: {
// [self.view setKeyboardType: UIKeyboardTypeNumberPad ]; [self.view setKeyboardType:UIKeyboardTypeNumberPad];
break; break;
} }
case 2: { case 2: {
[self.view setKeyboardType: UIKeyboardTypeDecimalPad]; [self.view setKeyboardType:UIKeyboardTypeDecimalPad];
break; break;
} }
case 3: { case 3: {
[self.view setKeyboardType: UIKeyboardTypeAlphabet]; [self.view setKeyboardType:UIKeyboardTypeAlphabet];
break; break;
} }
case 4: { case 4: {
[self.view setKeyboardType: UIKeyboardTypePhonePad]; [self.view setKeyboardType:UIKeyboardTypePhonePad];
break; break;
} }
default: { default: {
[self.view setKeyboardType:UIKeyboardTypeDefault];
break; break;
} }
} }
} } else {
else {
[super blendView:view forPropName:name propValue:prop]; [super blendView:view forPropName:name propValue:prop];
} }
} }
@ -164,12 +164,13 @@ - (void)blendView:(DoricInputView *)view forPropName:(NSString *)name propValue:
- (void)blend:(NSDictionary *)props { - (void)blend:(NSDictionary *)props {
[super blend:props]; [super blend:props];
} }
- (void)afterBlended:(NSDictionary *)props { - (void)afterBlended:(NSDictionary *)props {
[super afterBlended:props]; [super afterBlended:props];
if (self.view.doricLayout.paddingTop != self.view.textContainerInset.top if (self.view.doricLayout.paddingTop != self.view.textContainerInset.top
|| self.view.doricLayout.paddingLeft != self.view.textContainerInset.left || self.view.doricLayout.paddingLeft != self.view.textContainerInset.left
|| self.view.doricLayout.paddingBottom != self.view.textContainerInset.bottom || self.view.doricLayout.paddingBottom != self.view.textContainerInset.bottom
|| self.view.doricLayout.paddingRight != self.view.textContainerInset.right) { || self.view.doricLayout.paddingRight != self.view.textContainerInset.right) {
self.view.textContainerInset = UIEdgeInsetsMake(self.view.doricLayout.paddingTop, self.view.doricLayout.paddingLeft, self.view.doricLayout.paddingBottom, self.view.doricLayout.paddingRight); self.view.textContainerInset = UIEdgeInsetsMake(self.view.doricLayout.paddingTop, self.view.doricLayout.paddingLeft, self.view.doricLayout.paddingBottom, self.view.doricLayout.paddingRight);
} }
self.view.placeholderLabel.font = self.view.font; self.view.placeholderLabel.font = self.view.font;
@ -182,6 +183,7 @@ - (void)requestLayout {
} }
#pragma mark - Doric-JS api #pragma mark - Doric-JS api
- (NSString *)getText { - (NSString *)getText {
return self.view.text; return self.view.text;
} }
@ -189,12 +191,12 @@ - (NSString *)getText {
- (void)setSelection:(NSDictionary *)params withPromise:(DoricPromise *)promise { - (void)setSelection:(NSDictionary *)params withPromise:(DoricPromise *)promise {
NSString *start = params[@"start"]; NSString *start = params[@"start"];
NSString *end = params[@"end"]; NSString *end = params[@"end"];
if (([start isKindOfClass:[NSString class]] || [start isKindOfClass:[NSNumber class]]) && if (([start isKindOfClass:[NSString class]] || [start isKindOfClass:[NSNumber class]]) &&
([start isKindOfClass:[NSString class]] || [start isKindOfClass:[NSNumber class]])) { ([start isKindOfClass:[NSString class]] || [start isKindOfClass:[NSNumber class]])) {
self.view.selectedRange = NSMakeRange(start.intValue, end.intValue - start.intValue); self.view.selectedRange = NSMakeRange(start.intValue, end.intValue - start.intValue);
} }
[promise resolve:nil]; [promise resolve:nil];
} }
@ -207,12 +209,14 @@ - (void)releaseFocus {
} }
#pragma mark - UITextViewDelegate #pragma mark - UITextViewDelegate
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView { - (BOOL)textViewShouldBeginEditing:(UITextView *)textView {
if (self.onFocusShange) { if (self.onFocusShange) {
self.onFocusShange(YES, self); self.onFocusShange(YES, self);
} }
return YES; return YES;
} }
- (BOOL)textViewShouldEndEditing:(UITextView *)textView { - (BOOL)textViewShouldEndEditing:(UITextView *)textView {
if (self.onFocusShange) { if (self.onFocusShange) {
self.onFocusShange(NO, self); self.onFocusShange(NO, self);
@ -235,24 +239,24 @@ - (void)textViewDidChange:(UITextView *)textView {
} }
- (NSString *)limitToHansMaxLength:(NSUInteger)maxLen text:(NSString *)text{ - (NSString *)limitToHansMaxLength:(NSUInteger)maxLen text:(NSString *)text {
NSUInteger asciiMaxLen = 2 * maxLen; NSUInteger asciiMaxLen = 2 * maxLen;
__block NSUInteger asciiLen = 0; __block NSUInteger asciiLen = 0;
__block NSUInteger subStringRangeLen = 0; __block NSUInteger subStringRangeLen = 0;
[text enumerateSubstringsInRange:NSMakeRange(0, text.length) [text enumerateSubstringsInRange:NSMakeRange(0, text.length)
options:NSStringEnumerationByComposedCharacterSequences options:NSStringEnumerationByComposedCharacterSequences
usingBlock:^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) { usingBlock:^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) {
if ([substring canBeConvertedToEncoding:NSASCIIStringEncoding]) { if ([substring canBeConvertedToEncoding:NSASCIIStringEncoding]) {
asciiLen += 2; asciiLen += 2;
} else { } else {
asciiLen += [substring lengthOfBytesUsingEncoding:NSUTF16StringEncoding]; asciiLen += [substring lengthOfBytesUsingEncoding:NSUTF16StringEncoding];
} }
if (asciiLen <= asciiMaxLen) { if (asciiLen <= asciiMaxLen) {
subStringRangeLen = substringRange.location + substringRange.length; subStringRangeLen = substringRange.location + substringRange.length;
} else { } else {
*stop = YES; *stop = YES;
} }
}]; }];
return [text substringWithRange:NSMakeRange(0, subStringRangeLen)]; return [text substringWithRange:NSMakeRange(0, subStringRangeLen)];
} }
@end @end

View File

@ -32,7 +32,7 @@ export class Input extends View {
@Property @Property
hintText?: string hintText?: string
@Property @Property
inputType?: InputType inputType?: InputType
@ -74,12 +74,12 @@ export class Input extends View {
} }
} }
export enum InputType{ export enum InputType {
Default = 0, Default = 0,
Number = 1, Number = 1,
NumberSigned = 2, Decimal = 2,
Alphabet = 3, Alphabet = 3,