2017-01-16 81 views

回答

22

是的。它被稱爲TextInput,正常的TextInput組件支持多行。

只需指定下列屬性的TextInput組件

multiline = {true} 
numberOfLines = {4} 

在最後你應該有這樣的:

<TextInput 
    multiline={true} 
    numberOfLines={4} 
    onChangeText={(text) => this.setState({text})} 
    value={this.state.text}/> 
2

我使用這個組件: https://www.npmjs.com/package/react-native-autogrow-textinput

它擴展自動上文字的增長。我創建了自動增長-的TextInput我自己的可重用組件作爲它的一部分,該組件內部看起來像這樣:

<AutoGrowingTextInput 
    minHeight={40} 
    maxHeight={maxHeight} // this is a flexible value that I set in my 
    component, where I use this reusable component, same below, unless 
    specified the other 
    onChangeText={onChangeText} 
    placeholder={placeholder} 
    placeholderTextColor='#C7C7CD' 
    style={inputStyle} 
    value={value} 
/> 
0

如果您正在使用才反應過來,本地組件的選項TextInput

至於「 funkysoul」解釋說:

只需指定下列屬性的TextInput組件

multiline = {true}
numberOfLines = {4}

如果你想看到這個組件作爲經典textarea(比嵌入式文本輸入更大),通常你會需要添加height樣式屬性。請看下面的例子:

<TextInput 
    multiline={true} 
    numberOfLines={10} 
    style={{ height:200, backgroundColor:'red'}} 
/> 

我加入的backgroundColor爲更好地理解height作用。請不要在您的項目中使用它;)

相關問題