You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by cx...@apache.org on 2018/11/06 07:43:19 UTC
[incubator-weex] branch master updated: [WEEX-639][iOS] fix input
component can not limit words number correctly (#1608)
This is an automated email from the ASF dual-hosted git repository.
cxfeng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-weex.git
The following commit(s) were added to refs/heads/master by this push:
new 04eee5c [WEEX-639][iOS] fix input component can not limit words number correctly (#1608)
04eee5c is described below
commit 04eee5c851e352e0c268939c9db0b12e6dcc2da6
Author: Douma Fang <do...@gmail.com>
AuthorDate: Tue Nov 6 15:43:15 2018 +0800
[WEEX-639][iOS] fix input component can not limit words number correctly (#1608)
---
.../WeexSDK/Sources/Component/WXEditComponent.mm | 36 ++++++++++++----------
1 file changed, 19 insertions(+), 17 deletions(-)
diff --git a/ios/sdk/WeexSDK/Sources/Component/WXEditComponent.mm b/ios/sdk/WeexSDK/Sources/Component/WXEditComponent.mm
index 0df57d8..ec45bba 100644
--- a/ios/sdk/WeexSDK/Sources/Component/WXEditComponent.mm
+++ b/ios/sdk/WeexSDK/Sources/Component/WXEditComponent.mm
@@ -38,7 +38,7 @@
@property (nonatomic) NSNumber *maxLength;
@property (nonatomic) NSString * value;
@property (nonatomic) BOOL autofocus;
-@property(nonatomic) UIReturnKeyType returnKeyType;
+@property (nonatomic) UIReturnKeyType returnKeyType;
@property (nonatomic) BOOL disabled;
@property (nonatomic, copy) NSString *inputType;
@property (nonatomic) NSUInteger rows;
@@ -600,21 +600,6 @@ WX_EXPORT_METHOD(@selector(setTextFormatter:))
return NO;
}
}
-
- if (_maxLength) {
- NSUInteger oldLength = [textField.text length];
- NSUInteger replacementLength = [string length];
- NSUInteger rangeLength = range.length;
-
- NSUInteger newLength = oldLength - rangeLength + replacementLength;
- if (newLength <= oldLength) {
- // deleting, we should allow delete
- return YES;
- }
-
- return newLength <= [_maxLength integerValue] ;
- }
-
return YES;
}
@@ -669,7 +654,6 @@ WX_EXPORT_METHOD(@selector(setTextFormatter:))
} else {
textField.text = [newString copy];
UITextPosition * newPosition = [textField positionFromPosition:textField.beginningOfDocument offset:cursorPosition+adjust];
-
textField.selectedTextRange = [textField textRangeFromPosition:newPosition toPosition:newPosition];
}
@@ -678,6 +662,24 @@ WX_EXPORT_METHOD(@selector(setTextFormatter:))
// bind each other , the key must be attrs
[self fireEvent:@"input" params:@{@"value":[textField text]} domChanges:@{@"attrs":@{@"value":[textField text]}}];
}
+
+ if (_maxLength) {
+ NSString *toBeString = textField.text;
+ NSString *language = [[UIApplication sharedApplication] textInputMode].primaryLanguage;
+ if ([language isEqualToString:@"zh-Hans"]) {
+ UITextRange *selectedRange = [textField markedTextRange];
+ UITextPosition *position = [textField positionFromPosition:selectedRange.start offset:0];
+ if (!position) {
+ if (toBeString.length > _maxLength.integerValue) {
+ textField.text = [toBeString substringToIndex:_maxLength.integerValue];
+ }
+ }
+ } else {
+ if (toBeString.length > _maxLength.integerValue) {
+ textField.text = [toBeString substringToIndex:_maxLength.integerValue];
+ }
+ }
+ }
}
- (void)setViewMovedUp:(BOOL)movedUp