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:10 UTC
[2/8] incubator-weex git commit: + [ios] fix iOS textarea bug
+ [ios] fix iOS textarea bug
Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/7c1b0a5a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/7c1b0a5a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/7c1b0a5a
Branch: refs/heads/0.11-dev
Commit: 7c1b0a5a2044bac5d516761f1847dee3657453e2
Parents: 293db90
Author: kfeagle <su...@163.com>
Authored: Fri Mar 3 13:50:49 2017 +0800
Committer: kfeagle <su...@163.com>
Committed: Fri Mar 3 13:50:49 2017 +0800
----------------------------------------------------------------------
.../WeexSDK/Sources/Component/WXEditComponent.h | 1 +
.../WeexSDK/Sources/Component/WXEditComponent.m | 17 ++++++++
.../Sources/Component/WXTextAreaComponent.m | 42 ++++++++++++++++++++
3 files changed, 60 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/7c1b0a5a/ios/sdk/WeexSDK/Sources/Component/WXEditComponent.h
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Component/WXEditComponent.h b/ios/sdk/WeexSDK/Sources/Component/WXEditComponent.h
index dcc74e6..fa33193 100644
--- a/ios/sdk/WeexSDK/Sources/Component/WXEditComponent.h
+++ b/ios/sdk/WeexSDK/Sources/Component/WXEditComponent.h
@@ -18,4 +18,5 @@
@property (nonatomic, strong) NSString *placeholderString;
@property (nonatomic, strong) UILabel *placeHolderLabel;
+@property (nonatomic, readonly) NSUInteger rows;
@end
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/7c1b0a5a/ios/sdk/WeexSDK/Sources/Component/WXEditComponent.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Component/WXEditComponent.m b/ios/sdk/WeexSDK/Sources/Component/WXEditComponent.m
index c75d7d9..4464b67 100644
--- a/ios/sdk/WeexSDK/Sources/Component/WXEditComponent.m
+++ b/ios/sdk/WeexSDK/Sources/Component/WXEditComponent.m
@@ -28,6 +28,8 @@
@property(nonatomic) UIReturnKeyType returnKeyType;
@property (nonatomic) BOOL disabled;
@property (nonatomic, copy) NSString *inputType;
+@property (nonatomic) NSUInteger rows;
+
//style
@property (nonatomic) WXPixelType fontSize;
@property (nonatomic) WXTextStyle fontStyle;
@@ -84,6 +86,11 @@ WX_EXPORT_METHOD(@selector(getSelectionRange:))
if (attributes[@"returnKeyType"]) {
_returnKeyType = [WXConvert UIReturnKeyType:attributes[@"returnKeyType"]];
}
+ if (attributes[@"rows"]) {
+ _rows = [attributes[@"rows"] integerValue];
+ } else {
+ _rows = 2;
+ }
// handle styles
if (styles[@"color"]) {
@@ -114,6 +121,11 @@ WX_EXPORT_METHOD(@selector(getSelectionRange:))
return self;
}
+-(NSUInteger )rows
+{
+ return _rows;
+}
+
#pragma mark - lifeCircle
- (void)viewDidLoad
@@ -342,6 +354,11 @@ WX_EXPORT_METHOD(@selector(getSelectionRange:))
_returnKeyType = [WXConvert UIReturnKeyType:attributes[@"returnKeyType"]];
[self setReturnKeyType:_returnKeyType];
}
+ if (attributes[@"rows"]) {
+ _rows = [attributes[@"rows"] integerValue];
+ } else {
+ _rows = 2;
+ }
}
#pragma mark - upate styles
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/7c1b0a5a/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 0530c2c..8b6900b 100644
--- a/ios/sdk/WeexSDK/Sources/Component/WXTextAreaComponent.m
+++ b/ios/sdk/WeexSDK/Sources/Component/WXTextAreaComponent.m
@@ -7,6 +7,7 @@
*/
#import "WXTextAreaComponent.h"
+#import "WXUtility.h"
#define CorrectX 4 //textview fill text 4 pixel from left. so placeholderlabel have 4 pixel too
typedef UITextView WXTextAreaView;
@@ -32,14 +33,54 @@ typedef UITextView WXTextAreaView;
[_textView addSubview:self.placeHolderLabel];
}
_textView.delegate = self;
+ [_textView setNeedsDisplay];
+ [_textView setClipsToBounds:YES];
[super viewDidLoad];
}
+- (void)viewWillUnload
+{
+ _textView = nil;
+}
+
- (UIView *)loadView
{
_textView = [[WXTextAreaView alloc] init];
return _textView;
}
+
+#pragma mark measure frame
+- (CGSize (^)(CGSize))measureBlock
+{
+ __weak typeof(self) weakSelf = self;
+ return ^CGSize (CGSize constrainedSize) {
+
+ CGSize computedSize = [[[NSString alloc] init]sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:[UIFont systemFontSize]]}];
+ computedSize.height = computedSize.height * self.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]);
+ }
+
+ if (!isnan(weakSelf.cssNode->style.maxDimensions[CSS_WIDTH])) {
+ computedSize.width = MIN(computedSize.width, weakSelf.cssNode->style.maxDimensions[CSS_WIDTH]);
+ }
+
+ if (!isnan(weakSelf.cssNode->style.minDimensions[CSS_HEIGHT])) {
+ computedSize.height = MAX(computedSize.height, weakSelf.cssNode->style.minDimensions[CSS_HEIGHT]);
+ }
+
+ if (!isnan(weakSelf.cssNode->style.maxDimensions[CSS_HEIGHT])) {
+ computedSize.height = MIN(computedSize.height, weakSelf.cssNode->style.maxDimensions[CSS_HEIGHT]);
+ }
+
+ return (CGSize) {
+ WXCeilPixelValue(computedSize.width),
+ WXCeilPixelValue(computedSize.height)
+ };
+ };
+}
+
#pragma mark -Overwrite method
-(NSString *)text
{
@@ -48,6 +89,7 @@ typedef UITextView WXTextAreaView;
- (void)setText:(NSString *)text
{
+
_textView.text = text;
if ([text length] >0) {
self.placeHolderLabel.text = @"";