I want to have all children filling the available space, and overlapping one another, so only the last child is visible.
<View style={???}>
<View style={???} /> // Not visible (if bg color set on next child)
<View style={???} />
</View>
I've tried various combinations of flex
, position
, alignSelf: stretch
, etc., and can't find a winning combo.
I think you want something like this:
component/index.js:
component/style.js:
So,
View
withroot
style will fill all space of its parent since it hasflex: 1
. And it hasposition: relative
, so the children with absolute positioning will act accordingly.View
s withchild1
andchild2
both have absolute positioning (StyleSheet.absoluteFillObject
is a shortcut for{position: 'absolute', top: 0, right: 0, bottom: 0, left: 0}
docs here).child1
andchild2
will overlap andchild2
will be on top ofchild1
since it is rendered later.