TextInput
是一个允许用户输入文本的基础组件。它有一个名为onChangeText
的属性,此属性接受一个函数,而此函数会在文本变化时被调用。另外还有一个名为onSubmitEditing
的属性,会在文本被提交后(用户按下软键盘上的提交键)调用。
class TestTextInput extends Component{
constructor(props) {
super(props);
this.state = {text2: ''};
}
render() {
return (
<View style={{padding: 10}}>
<TextInput
style={{height: 40}}
placeholder="Type here to translate!"
onChangeText={(text2) => this.setState({text2})}
/>
<Text style={{padding: 10, fontSize: 42}}>
{this.state.text2.split(' ').map((word) => word && '