Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native multi line TextInput, text is centered

Tags:

So when using, text input with multiline=true, I have this issue where the text is vertically centered instead of being pushed to the top.

This issue happens on both ios and android, except android has another issue where, when multiple lines are entered, they get letterboxed to the height of 1 line.

I'd like to point out, I have tried adding textAlignVertical: 'top' to the style of the textinput

Code: (I have this as a seperate copmonent as I use it in forms with form text but all parameters are passed something)

    <TextInput             style={styles.input}             value={value}             autoComplete={autoComplete}             autoCapitalize={autoCapitalize}             placeholder={placeholder}             secureTextEntry={secureTextEntry}             keyboardType={keyboardType}             returnKeyType={returnKeyType}             autoFocus={autoFocus}             onChangeText={onChangeText}             onSubmitEditing={onSubmitEditing}             multiline={multiline || false}             ref={(r) => { inputRef && inputRef(r); }}     /> 

styles:

input: {     paddingRight: 10,     lineHeight: 23,     flex: 2,     textAlignVertical: 'top' }, 

ios screenshot

android screenshot

like image 630
Red Avatar asked Jun 22 '18 09:06

Red


People also ask

How do you expand TextInput in react native?

Use minHeight, maxHeight instead, and if multiline is enabled, the TextInput will grow till reaching the maxHeight, then will be scrollable. no calculation nor inner state needs to ba maintained. Same thing apply for minWidth, maxWidth if you need to expand widly.

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.


2 Answers

If anyone facing the same issue, try textAlignVertical: "top" This works. For more info try https://github.com/facebook/react-native/issues/13897

like image 68
Subhendu Kundu Avatar answered Sep 23 '22 01:09

Subhendu Kundu


i tried this for you please let me know if its correct

 <TextInput              style={styles.input}              value={this.state.value}              onChangeText={text=>this.setState({value:text})}              multiline={true}              underlineColorAndroid='transparent'      />

style as

  input: {      width:200,      borderBottomColor:'red',      borderBottomWidth:1,  },

and expo link may be help you click here

like image 23
chetan godiya Avatar answered Sep 27 '22 01:09

chetan godiya