My component is extremely simple, I have a <View>
component with a flex:1
property.
I have another View
inside of that parent View
with a property of flex: .5
, from my understanding – it should take up 50% of the parent View
‘s height. But it doesn’t take up anything, it’s gone as if there is no element there. height: "50%"
works though.
3
Answers
because of the other view with flex: 1 take the entire space of parent,
flex: 1 means
width: 100% or height: 100%
of the parent (depends on the flex direction).Change to
flex: .5
for both Views and you will see them in the half and half of parent.If your code is like the following, it should be working.
Just be aware the component above will affected by its parent View as well. Please check all the flex in parent views.
Also, it is good to provide any of the code in the question to make it easier for debugging.
As per your program you have used only View component inside another View component. also you have added style {flex:1} to parent view and {flex: 0.5} style to child.
Problem : your problem is child view is not taking 50% of the parent using {flex: 0.5}.
Solution : if you want to access 50% of the parent using {flex: 0.5} then you have to add any component like Text component inside of child View etc..
ex: