React-Native:TextInput大小自动增加,而与numberOfLines属性无关

问题描述 投票:0回答:2

我有一个TextInput,如下所示,

 <TextInput
     style={{borderWidth: 1, borderColor: "#dedede", width: '90%',  marginTop: 20, borderRadius: 1}}
     placeholder={'Tell us more about our service'}
     multiline = {true}
     numberOfLines = {10}
     value={this.state.customerFeedback}
     onChangeText={customerFeedback => this.setState({ customerFeedback })}
     underlineColorAndroid="transparent"
 />

因为我输入了numberOfLines = {10},所以如果我键入10行以上,则必须在TextInput区域内滚动文本。但就我而言,TextInput的大小逐渐增加,如下图所示,

enter image description here

[如果我们查看TextInput,则有10行以上。

[有人可以让我知道如何根据TextInput道具限制numberOfLines区域吗?谢谢。

react-native textinput
2个回答
0
投票

您唯一缺少的是textInput中样式的maxHeight属性,我已添加maxHeight:50

<TextInput
     style={{borderWidth: 1, borderColor: "#dedede", width: '90%',  marginTop: 20, borderRadius: 1,maxHeight:50}}
     placeholder={'Tell us more about our service'}
     multiline = {true}
     numberOfLines = {10}
     value={this.state.customerFeedback}
     onChangeText={customerFeedback => this.setState({ customerFeedback })}
     underlineColorAndroid="transparent"
 />

尝试一次,并检查博览会小吃expo-snack

希望有帮助。如有疑问,请随时


0
投票

我看到了您的代码,一件事是您缺少样式的另一个属性maxHeight。我现在将其添加到您的代码中,现在您可以将该代码复制并粘贴到您的项目中。

{/*maxHeight:200 */}
<TextInput
 style={{borderWidth: 1, borderColor: "#dedede", width: '90%',  marginTop: 20, borderRadius: 1,maxHeight:200}}
 placeholder={'Tell us more about our service'}
 multiline = {true}
 numberOfLines = {10}
 value={this.state.customerFeedback}
 onChangeText={customerFeedback => this.setState({ customerFeedback })}
 underlineColorAndroid="transparent"
/>

我希望这会有所帮助:)

© www.soinside.com 2019 - 2024. All rights reserved.