4

I was trying to implement the Input from React Native Elements, which is the blue one. I want to make the Input have full width within the red view. So I did

width: '100%', marginHorizontal: 0, padding: 0, and alignItems: 'stretch' independently.

But none of them didn't work. What is the problem? This is the screenshot of the screen

https://i.sstatic.net/NDhuC.png

And this is the corresponding code

    <View style = {styles.campusInputView}>
      <Input
        containerStyle = {styles.campusInputContainer}
        inputStyle = {styles.campusInput}
        placeholder = 'KAIST'
        editable = {false}
      />
    </View>

with the style

  campusInputView: {
    borderWidth: 1,
    borderColor: 'red',
    position: 'absolute',
    top: height * 100 / 640,
    left: width * 45 / 360,
    width: width * 270 / 360,
  },
  campusInputContainer: {
    borderWidth: 1,
    borderColor: 'green',
    alignItems: 'stretch',
  },
  campusInput: {
    borderWidth: 1,
    borderColor: 'blue',
    flex: 1,
    fontFamily: 'NanumSquareB',
    fontSize: 20,
    paddingVertical: 0,
  },
0

3 Answers 3

12

Overwriting paddingHorizontal of containerStyle as 0 makes the input full width. Overwriting only padding as 0 is not enough.

import { Input } from 'react-native-elements'

<Input
  containerStyle = {{ paddingHorizontal: 0 }}
  // other settings
/>
Sign up to request clarification or add additional context in comments.

2 Comments

Wow. This must be accepted answer... I don't know why when I overwrite padding it does not work but when I tried paddingHorizontal it works perfectly!!
I agree, this should be an accepted answer
1

You should add paddingHorizontal: 0 to campusInputContainer

campusInputContainer: {
  borderWidth: 1,
  borderColor: 'green',
  alignItems: 'stretch',
  paddingHorizontal: 0
},

Comments

-1

The width you want is 100%. And I set the color of the border to red.

import React, { Component } from 'react';
import { Text, View, StyleSheet, FlatList } from 'react-native';
import { Input } from 'react-native-elements';



export default class App extends Component {

  render() {
    return (
     <View style = {styles.campusInputView}>
      <Input
        containerStyle = {styles.campusInputContainer}
        inputStyle = {styles.campusInput}
        placeholder = 'KAIST'
        editable = {false}
      />
    </View>
    );
  }
}

const styles = StyleSheet.create({
  campusInputView: {
    flex:1,
    justifyContent:"center",
    alignItems:"center"
  },
  campusInputContainer: {
    borderWidth: 1,
    borderColor: 'red',
    alignItems: 'stretch',
  },
  campusInput: {
    flex: 1,
    fontFamily: 'NanumSquareB',
    fontSize: 20,
    paddingVertical: 0,
  },
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.