React Native高度自增长的TextInput组件

来源:互联网 发布:2017通货膨胀 知乎 编辑:程序博客网 时间:2024/05/19 16:50

React Native高度自增长的TextInput组件:

直接上代码:
   this.state = {
           comment:'',   //文本输入框内容     
           placeholder: '说点什么吧~' ,  //提示内容
           height: 40,  //文本输入框初始高度
        }; 
   <TextInput 
          ref={"INPUT"}   
          underlineColorAndroid={'transparent'}
          autoFocus={false}
          placeholder={this.state.placeholder}      //提示内容
          multiline={true}
          onChange={
(event)={this.setState({
                                                  comment:event.nativeEvent.text,
                                                  height:event.nativeEvent.contentSize.height
                                              }); 
                                            }
                              }
         style={[{height:this.state.height}]}
         value={this.state.comment}
     />