Weex textarea标签自动换行扩展iOS

weex   <textare>标签扩展

实现WEEX  <textarea>标签输入框自适应高度

首先贴上我的weex代码:


weex-tmplate


style


methods-inout

通过weex标签增加属性autoHeight,来判断是否需要自适应高度,然后在iOS  component里面取扩展WXEditComponent,

增加属性@property (nonatomic, assign)BOOL autoHeight;

初始化方法里面增加

_autoHeight = NO;

if (styles[@"autoHeight"]) {

_autoHeight = [WXConvert BOOL:styles[@"autoHeight"]];

}

textView代理方法修改

- (void)textViewDidChange:(UITextView *)textView

{

if(textView.text && [textView.text length] > 0) {

self.placeHolderLabel.text = @"";

}else{

[self setPlaceholderAttributedString];

}

if (_inputEvent) {  此处利用weex自带的输入时间进行传值

if (_autoHeight) {

//默认高度weex 65 ~ 200 

CGFloat height = textView.contentSize.height;

[self fireEvent:@"input" params:@{@"value":[textView text], @"height" : [NSNumber numberWithFloat: height]} domChanges:@{@"attrs":@{@"value":[textView text]}}];多加了一个参数height,在weex  <textarea>标签中绑定的input方法可取值

if (!(textView.contentSize.height > (200 * ScreenWidth/750.0))) { 转换成weex页面的高度计算

[textView scrollRangeToVisible:NSMakeRange(0, 0)]; 此方法是换行时出现UITextContainView上下跳动的bug

}

}else{

[self fireEvent:@"input" params:@{@"value":[textView text]} domChanges:@{@"attrs":@{@"value":[textView text]}}];

}

}

}

站位文字更新问题, 当textarea标签位置发生该表时,weex回去更新这些信息,其中就有重置站位文字,修改如下在- (void)updateStyles:(NSDictionary *)styles和- (void)updateAttributes:(NSDictionary *)attributes中进行判断

if (!_autoHeight) {

[self setPlaceholderAttributedString];

}


OVER! 有问题可以@我 !

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容