Reputation: 650
I don't have problem layouting in react-native right now, just want to know the reason of the default width concept
This script below is almost the same
<View
style = {{
flex: 1
}}
>
//The view below has default width "100%"
<View
style = {{
backgroundColor: "red",
height: 60
}}
/>
</View>
<View
style = {{
alignItems: "flex-start", //Same render from left, using alignItems makes inside content having no default width
flex: 1
}}
>
//The view below has no width
<View
style = {{
backgroundColor: "red",
height: 60
}}
/>
</View>
Should it have the same width behavior?
Upvotes: 0
Views: 291
Reputation: 11930
View
as analogy if div
in html
display=block
by defaultdisplay=block
is width=100%
by defaultWhen you use alignItems
, it's not display=block
anymore, it's display=flex
, hence width is not 100%
To make width=100%
with alignItems
, you have to use alignItems='stretch'
. Or give flex=1
to child
Although View
doesn't have display=block
property, it's just default behavior
So problem is not in react-native, problem is in your understandings of flexbox
Upvotes: 1