【发布时间】:2020-05-08 15:03:19
【问题描述】:
版本 “反应”:“16.11.0”, "react-native": "0.62.2",
https://reactnative.dev/docs/textinput#numberoflines
如果你查看 React Native 文档,这个功能是可用的。
这是我的代码
但是,不起作用
如何限制行数?
【问题讨论】:
标签: react-native
版本 “反应”:“16.11.0”, "react-native": "0.62.2",
https://reactnative.dev/docs/textinput#numberoflines
如果你查看 React Native 文档,这个功能是可用的。
这是我的代码
但是,不起作用
如何限制行数?
【问题讨论】:
标签: react-native
也许该属性没有设置最大行数,但这里有一个替代方法
// set the max lines
const MAX_LINES = 3
// method to handle the text change
onTextFieldChange = (text) => {
if ( text.split(/\r\n|\r|\n/).length <= MAX_LINES )
{
this.setState({text});
}
}
// on your textInput
<TextInput
// properties...
onTextChange={this.onTextInputChange}
/>
【讨论】: