React Native multi line TextInput, text is centered

Red picture Red · Jun 22, 2018 · Viewed 37k times · Source

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

Answer

Subhendu Kundu picture Subhendu Kundu · Feb 14, 2019

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