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
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,
},
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
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,
},
Share
Improve this question
edited Aug 13, 2019 at 13:48
Kareem Dabbeet
3,9943 gold badges18 silver badges35 bronze badges
asked Aug 13, 2019 at 13:36
TonyWildTonyWild
411 gold badge1 silver badge2 bronze badges
0
3 Answers
Reset to default 12Overwriting 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
/>
You should add paddingHorizontal: 0
to campusInputContainer
campusInputContainer: {
borderWidth: 1,
borderColor: 'green',
alignItems: 'stretch',
paddingHorizontal: 0
},
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,
},
});