14

I'm using a multi line TextInput in my react-native application and been stuck on this for a while. I can not get the text to be vertically aligned on IOS devices.

using textAlign='center' puts the text on IOS vertically centered... but it becomes an unwrapped never ending line.

adding multiline={true} negates the vertically aligned text in IOS and puts it at the top of the input.

<TextInput
    style={{ 
        width: wp('80%'), 
        height: hp('25%'), 
        borderWidth: 1, 
        borderRadius: 10,   
        fontSize: RF(3), 
    }}
    textAlign={'center'}
    multiline={true}
    onChangeText={entry => this.setState({entry})}
    value={this.state.entry}
/>

I would like the behavior to be like android in that it shows the placeholder text vertically and horizontally centered and when user inputs more text it starts creating multi lines if needed but always vertically and horizontally centered.

Please see image with android version on left and IOS on right.

Android on left, IOS on right

Jacob MacInnis
  • 140
  • 1
  • 6

4 Answers4

0

try adding textAlignVertical={"center"} to textInput's props

Aayush Anand
  • 254
  • 2
  • 10
0

Add the attribute paddingTop to your TextInput in your XML file.

Ole Pannier
  • 3,208
  • 9
  • 22
  • 33
0

Have you tried wrapping the TextInput in a View?

<View style={{ alignItems: 'center', justifyContent: 'center' }}>
    <TextInput
        style={{ 
            width: wp('80%'), 
            height: hp('25%'), 
            borderWidth: 1, 
            borderRadius: 10,   
            fontSize: RF(3), 
        }}
        textAlign={'center'}
        multiline={true}
        onChangeText={entry => this.setState({entry})}
        value={this.state.entry}
    />
</View>
instanceof
  • 1,404
  • 23
  • 30
0

textAlignVertical is android only docs

enter image description here if the image above is the desired behaviour, align verticaly on center using multiline=true this is how I managed that:

  1. wrap text input with view and set a min and max height in this view
  2. in the same view set flex and justify-center
  3. remove the paddings inside the textinput
  4. set multiline true to the textinput
<View className="flex-1 min-h-[44px] max-h-[130px] px-6 justify-center">
  <TextInput
    multiline={true}
    className="px-0 py-0"
  />
</View>
Hernani Fernandes
  • 1,016
  • 1
  • 7
  • 4