Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't override react-native's TextInput default padding

I have the following TextInput:

  _renderTextInput() {
    return (
      <TextInput
        onChangeText={TextInput => this.setState({TextInput})}
        style={{flex: 1, backgroundColor: "maroon", paddingVertical: 0}}
        autoFocus={true}
        multiline={true}
        underlineColorAndroid="transparent"
        returnKeyType="go"
      />
    )
  }

  render() {
    return(
      <View style={{flex: 1, backgroundColor: "#E0E0E0", paddingVertical: 0}}>
        {this._renderTextInput()}
      </View>
    )
  }

What I am trying to achieve is a full-screen distraction-free zone for the user to type his post.

I know for sure that it's a padding issue but whatever I try I simply can not override it. I tried padding:0 paddingTop:0 paddingVertical: 0 nothing seems to work...

Preview:

enter image description here

like image 503
Ray Avatar asked Mar 15 '17 14:03

Ray


2 Answers

After a long day of endless g-o-o-g-l-i-n-g, I found out what's causing the unwanted padding. It looks like by default, TextInput has the Text vertically centered hence why everything is exactly in the middle. To override it, just add:

textAlignVertical: 'top' to the TextInput's style and you're done. :)

@matt-aft 's comment about changing the style of the text helped to solve this.

like image 142
Ray Avatar answered Nov 20 '22 19:11

Ray


Flex wont work here because you have other components also using flex so the screen is getting divided up. Using the device's height and width should work, or using a modal with a test input should also work.

const {height, width} = Dimensions.get('window');

style={{ height, width, backgroundColor: "maroon", paddingVertical: 0}}
like image 2
Matt Aft Avatar answered Nov 20 '22 19:11

Matt Aft