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,
},
import { Dimensions } from 'react-native';
width: ${(Dimensions.get('window').width)}px;
import React from 'react'
import { View } from 'react-native'
export default function index() {
const onLayout=(event)=> {
const {x, y, height, width} = event.nativeEvent.layout;
}
return (
<View onLayout={onLayout}>
<OtherComponent />
</View>
)
}
header : {
height : 100,
backgroundColor: "favorite color",
alignSelf: "stretch",
}
import React from 'react';
import { View } from 'react-native';
const Dimensions = () => {
return (
<View>
<View style={{
width: 50, height: 50, backgroundColor: 'powderblue'
}} />
<View style={{
width: 100, height: 100, backgroundColor: 'skyblue'
}} />
<View style={{
width: 150, height: 150, backgroundColor: 'steelblue'
}} />
</View>
);
};
export default Dimensions;
import React from 'react';
import { View } from 'react-native';
const PercentageDimensionsBasics = () => {
// Try removing the `height: '100%'` on the parent View.
// The parent will not have dimensions, so the children can't expand.
return (
<View style={{ height: '100%' }}>
<View style={{
height: '33%', backgroundColor: 'red'
}} />
<View style={{
width: '66%', height: '35%', backgroundColor: 'blue'
}} />
<View style={{
width: '20%', height: '50%', backgroundColor: 'yellow'
}} />
</View>
);
};
export default PercentageDimensionsBasics;
line1:{
alignSelf: 'stretch',
}
flex:1,