是否有任何內置的文本區域組件用於反應原生?我試圖實現這些的:什麼是textarea在react-native中的替代方案?
https://github.com/buildo/react-autosize-textarea
https://github.com/andreypopp/react-textarea-autosize
,但得到「預期組件類有對象的對象」的錯誤。
是否有任何內置的文本區域組件用於反應原生?我試圖實現這些的:什麼是textarea在react-native中的替代方案?
https://github.com/buildo/react-autosize-textarea
https://github.com/andreypopp/react-textarea-autosize
,但得到「預期組件類有對象的對象」的錯誤。
是的。它被稱爲TextInput,正常的TextInput組件支持多行。
只需指定下列屬性的TextInput組件
multiline = {true}
numberOfLines = {4}
在最後你應該有這樣的:
<TextInput
multiline={true}
numberOfLines={4}
onChangeText={(text) => this.setState({text})}
value={this.state.text}/>
我使用這個組件: 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}
/>
如果您正在使用才反應過來,本地組件的選項TextInput
至於「 funkysoul」解釋說:
只需指定下列屬性的TextInput組件
multiline = {true}
numberOfLines = {4}
如果你想看到這個組件作爲經典textarea
(比嵌入式文本輸入更大),通常你會需要添加height
樣式屬性。請看下面的例子:
<TextInput
multiline={true}
numberOfLines={10}
style={{ height:200, backgroundColor:'red'}}
/>
我加入的backgroundColor爲更好地理解height
作用。請不要在您的項目中使用它;)