Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is an alternative of textarea in react-native?

Tags:

react-native

Is there any built in text area component for react-native? I have tried to implement these ones:

https://github.com/buildo/react-autosize-textarea

https://github.com/andreypopp/react-textarea-autosize

but getting an error "Expected a component class got object object".

like image 546
imran shoukat Avatar asked Jan 16 '17 14:01

imran shoukat


People also ask

What is TextInput in React native?

TextInput is a Core Component that allows the user to enter text. It has an onChangeText prop that takes a function to be called every time the text changed, and an onSubmitEditing prop that takes a function to be called when the text is submitted.

How do I use onSubmitEditing React native?

onSubmitEditing is triggered when you click the text input submit button (keyboard button). onChangeText is triggered when you type any symbol in the text input. In your example, you will achieve what you need in both cases. Save this answer.

How do you create an input box in React native?

TextInput basicsconst styles = StyleSheet. create({ input: { borderColor: "gray", width: "100%", borderWidth: 1, borderRadius: 10, padding: 10, }, }); In the piece of code above, we styled the text box's border and gave it some padding.


2 Answers

Yes there is. It's called TextInput, the normal TextInput Component supports multiple lines.

Just assign following properties to your TextInput Component

multiline = {true} numberOfLines = {4} 

At the end you should have this:

<TextInput     multiline={true}     numberOfLines={4}     onChangeText={(text) => this.setState({text})}     value={this.state.text}/> 

Source https://facebook.github.io/react-native/docs/textinput

like image 159
funkysoul Avatar answered Oct 28 '22 11:10

funkysoul


If you want to see your TextInput component like a textarea, you will need to add this

<TextInput     multiline={true}     numberOfLines={10}     style={{ height:200, textAlignVertical: 'top',}}/> 
like image 21
Marvin Soto Avatar answered Oct 28 '22 12:10

Marvin Soto