weex ? <textare>標(biāo)簽擴(kuò)展
實(shí)現(xiàn)WEEX ?<textarea>標(biāo)簽輸入框自適應(yīng)高度
首先貼上我的weex代碼:
通過(guò)weex標(biāo)簽增加屬性autoHeight唱较,來(lái)判斷是否需要自適應(yīng)高度,然后在iOS? component里面取擴(kuò)展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自帶的輸入時(shí)間進(jìn)行傳值
if (_autoHeight) {
//默認(rèn)高度weex 65 ~ 200?
CGFloat height = textView.contentSize.height;
[self fireEvent:@"input" params:@{@"value":[textView text], @"height" : [NSNumber numberWithFloat: height]} domChanges:@{@"attrs":@{@"value":[textView text]}}];多加了一個(gè)參數(shù)height,在weex ?<textarea>標(biāo)簽中綁定的input方法可取值
if (!(textView.contentSize.height > (200 * ScreenWidth/750.0))) { 轉(zhuǎn)換成weex頁(yè)面的高度計(jì)算
[textView scrollRangeToVisible:NSMakeRange(0, 0)]; 此方法是換行時(shí)出現(xiàn)UITextContainView上下跳動(dòng)的bug
}
}else{
[self fireEvent:@"input" params:@{@"value":[textView text]} domChanges:@{@"attrs":@{@"value":[textView text]}}];
}
}
}
站位文字更新問(wèn)題扣囊, 當(dāng)textarea標(biāo)簽位置發(fā)生該表時(shí)吉嫩,weex回去更新這些信息其掂,其中就有重置站位文字脖隶,修改如下在- (void)updateStyles:(NSDictionary *)styles和- (void)updateAttributes:(NSDictionary *)attributes中進(jìn)行判斷
if (!_autoHeight) {
[self setPlaceholderAttributedString];
}
OVER! 有問(wèn)題可以@我 扁耐!