You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by GitBox <gi...@apache.org> on 2018/11/06 07:43:16 UTC

[GitHub] cxfeng1 closed pull request #1608: [WEEX-639][iOS] fix input component can not limit words number correctly

cxfeng1 closed pull request #1608: [WEEX-639][iOS] fix input component can not limit words number correctly
URL: https://github.com/apache/incubator-weex/pull/1608
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/ios/sdk/WeexSDK/Sources/Component/WXEditComponent.mm b/ios/sdk/WeexSDK/Sources/Component/WXEditComponent.mm
index d93b19c75b..2b848c85a3 100644
--- a/ios/sdk/WeexSDK/Sources/Component/WXEditComponent.mm
+++ b/ios/sdk/WeexSDK/Sources/Component/WXEditComponent.mm
@@ -38,7 +38,7 @@ @interface WXEditComponent()
 @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 @@ - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRang
             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 @@ - (void)textFiledEditChanged:(NSNotification *)notifi
         } 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 @@ - (void)textFiledEditChanged:(NSNotification *)notifi
         // 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


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services