To set text alignment in react native we have to use textAlign style prop. One more thing the textAlign is used to set text align in horizontal format. We will learn about each text align property one by one in below given example.
I had the same issue, but the above notes didn't solve it. There's an android-only style property textAlignVertical
that fixes this issue on multiline inputs.
i.e. textAlignVertical: 'top'
TextInput has default padding, override it by setting:
paddingTop: 0,
paddingBottom: 0
Github Issue
I have found the solution that in Android, TextInput style textAlignVertical: 'top'
works. but in ios, TextInput prop multiline={true}
works.
The Above Answers either give the for iOS or android, which can be quite misleading so this fixes it for both of the platfoms.
<TextInput
style={{
flex: 1,
width: "100%",
height: 150,
color: "#FFF",
textAlignVertical: "top", // android fix for centering it at the top-left corner
}}
multiline={true} // ios fix for centering it at the top-left corner
numberOfLines={10}
/>
For Android -
style={{
//...
flex:1,
textAlignVertical: "top", // android fix for centering it at the top-left corner
//...
}}
For iOS, add
multiline={true}
to the <TextInput/>
component
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With