Monday, 1 April 2019

Reduce height and vertical padding for a react-native-paper TextInput

I have the following code:

import React, { Component } from 'react';
import { View, StyleSheet } from 'react-native';
import { Button, TextInput } from 'react-native-paper';

export default class Header extends Component {

  state = {
    text: '',
  };

  render() {
    return (
      <View style={styles.container}>
        <TextInput value={this.state.text} style={styles.input} />
        <Button mode="contained" style={styles.button}>Add Todo</Button>
      </View>
    );
  }

}

const styles = StyleSheet.create({
  container: {
    flexDirection: 'row',
    justifyContent: 'center',
    alignItems: 'center',
    alignSelf: 'stretch',
    backgroundColor: '#c1deff',
  },
  input: {
    flex: 1,
  },
  button: {
    flex: 0,
  },
});

which outputs the following screen:

enter image description here

My goal is to reduce the height for the TextInput. It also looks like it has some vertical padding. Is it possible to decrease that as well? I'm just trying to save space on the screen and in my opinion is taking lot of it area.

EDIT 01

I tried with the following style:

input: {
  flex: 1,
  height: 40,
  borderColor: 'gray',
  borderWidth: 1,
}

but didn't work, because I got the following result:

enter image description here

which as you can see, doesn't look good (obvious).

Thanks!



from Reduce height and vertical padding for a react-native-paper TextInput

No comments:

Post a Comment