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 2017/03/06 09:36:12 UTC

[4/8] incubator-weex git commit: * [ios] fix bug : textarea cannot update rows

* [ios] fix bug : textarea cannot update rows


Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/c206a2f2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/c206a2f2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/c206a2f2

Branch: refs/heads/0.11-dev
Commit: c206a2f2a3acf71b5ba504d89b994423809fb6cf
Parents: c030aef
Author: kfeagle <su...@163.com>
Authored: Sat Mar 4 14:44:03 2017 +0800
Committer: kfeagle <su...@163.com>
Committed: Sat Mar 4 14:44:03 2017 +0800

----------------------------------------------------------------------
 .../Sources/Component/WXTextAreaComponent.m       | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/c206a2f2/ios/sdk/WeexSDK/Sources/Component/WXTextAreaComponent.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Component/WXTextAreaComponent.m b/ios/sdk/WeexSDK/Sources/Component/WXTextAreaComponent.m
index 20e237b..5cd8281 100644
--- a/ios/sdk/WeexSDK/Sources/Component/WXTextAreaComponent.m
+++ b/ios/sdk/WeexSDK/Sources/Component/WXTextAreaComponent.m
@@ -8,13 +8,16 @@
 
 #import "WXTextAreaComponent.h"
 #import "WXUtility.h"
+#import "WXComponent+Layout.h"
 
 #define CorrectX 4 //textview fill text 4 pixel from left. so placeholderlabel have 4 pixel too
+#define CorrectY 8 // textview fill text 8 pixel from top
 typedef UITextView WXTextAreaView;
 
 @interface WXTextAreaComponent()
 
 @property (nonatomic, strong) WXTextAreaView *textView;
+@property (nonatomic) NSUInteger rows;
 
 @end
 
@@ -56,7 +59,7 @@ typedef UITextView WXTextAreaView;
     return ^CGSize (CGSize constrainedSize) {
         
         CGSize computedSize = [[[NSString alloc] init]sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:[UIFont systemFontSize]]}];
-        computedSize.height = computedSize.height * self.rows;
+        computedSize.height = computedSize.height * _rows;
         //TODO:more elegant way to use max and min constrained size
         if (!isnan(weakSelf.cssNode->style.minDimensions[CSS_WIDTH])) {
             computedSize.width = MAX(computedSize.width, weakSelf.cssNode->style.minDimensions[CSS_WIDTH]);
@@ -191,6 +194,19 @@ typedef UITextView WXTextAreaView;
     [_textView setFont:font];
 }
 
+-(void)setRows:(NSUInteger)rows
+{
+    _rows = rows;
+    //update frame by rows
+    CGSize computedSize = [[[NSString alloc] init]sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:_textView.font.pointSize]}];
+    computedSize.height = computedSize.height * _rows;
+    CGRect frame = _textView.frame;
+    frame.size.height = _rows?computedSize.height + (CorrectY + CorrectY/2):0;
+    _textView.frame = frame;
+    
+    [self setNeedsLayout];
+}
+
 #pragma mark -Private Method
 - (void)_updateTextContentInset
 {