You can get the application window's width and height using the following code: const windowWidth = Dimensions. get('window').
In react-native, to set the dynamic width and height to a component, we use built-in interface Dimensions. it takes the dimension of a given component and then sets the width and height to its equivalent.
Simply add alignSelf: "stretch"
to your item's stylesheet.
line1: {
backgroundColor: '#FDD7E4',
alignSelf: 'stretch',
textAlign: 'center',
},
You should use Dimensions
First, define Dimensions.
import { Dimensions } from "react-native";
var width = Dimensions.get('window').width; //full width
var height = Dimensions.get('window').height; //full height
then, change line1
style like below:
line1: {
backgroundColor: '#FDD7E4',
width: width,
},
Editted:
In order to flex only the center text, a different approach can be taken - Unflex the other views.
alignItems : 'center'
from containeralignSelf:'center'
to the textviews that you don't want to flexYou can wrap the Text component in a View component and give the View a flex of 1.
The flex will give :
100% width if the flexDirection:'row'
in styles.container
100% height if the flexDirection:'column'
in styles.container
Here you go:
Just change the line1 style as per below:
line1: {
backgroundColor: '#FDD7E4',
width:'100%',
alignSelf:'center'
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With