React Native Text Input
React Native Text Input
TextInput is the fundamental component to input text. It has several props which
configure the different features, such as onChangeText that takes a function and call it
whenever the text changed. The onSubmitEditing prop takes a function, which is called
when the text submitted.
There are several things, which can be performed with text input, such as validating the
text inside while user types.
render() {
return (
<View style={{padding: 10}}>
<TextInput
style={{height: 40,backgroundColor: 'azure', fontSize: 20}}
placeholder="Type here to translate!"
onChangeText={(text) => this.setState({text})}
/>
<Text style={{padding: 100, fontSize: 50}}>
{this.state.text.split(' ').map((word) => word && '🍕').join(' ')}
</Text>*
</View>
);
}
}
Output
TextInput properties
allowFontScaling autoCapitalize autoCorrect
The method .focus() and .blur() are exposed from the native element. These methods
focus or blur the TextInput programmatically.
Multiline TextInput
The multiline props provide facility to input multiple lines of text. Some props
of TextInput are only compatible with multiline, for example, multiline={true/false}.
The property borderButtomColor will not work if multiline = false.
render() {
return (
<View style={{
backgroundColor: this.state.text,
borderBottomColor: '#000000',
borderBottomWidth: 1,
}}
>
<UselessTextInput
multiline = {true}
numberOfLines = {10}
onChangeText={(text) => this.setState({text})}
value={this.state.text}
style={{fontSize: 20}}
/>
</View>
);
}
}
Output