I have a parent element with 2 absolutely positioned children inside. I want one of the children’s overflow to be visible and the other’s overflow to be hidden. Like so:
Adding overflow: 'hidden
to the parent hides the overflow of both the coin image and the ‘most popular’ sash but I want the coin image overflow to be visible.
container: {
width: 155,
height: 145,
backgroundColor: Colours.white,
borderRadius: 10,
borderColor: Colours.borderTwo,
borderWidth: 1,
alignItems: 'center',
justifyContent: 'flex-end',
margin: 10,
marginBottom: 25,
paddingBottom: 10,
overflow: 'hidden',
},
mostPopularSash: {
position: 'absolute',
top: 2,
right: -30,
backgroundColor: Colours.yellow,
width: 100,
height: 40,
alignItems: 'center',
justifyContent: 'center',
transform: [{rotate: '40deg'}],
},
imageContainer: {
position: 'absolute',
top: -22,
width: 52,
height: 52,
borderRadius: 100,
backgroundColor: Colours.white,
borderColor: Colours.pageColour,
borderWidth: 1,
justifyContent: 'center',
alignItems: 'center',
shadowColor: '#171717',
shadowOffset: {width: 0, height: 3},
shadowOpacity: 0.2,
shadowRadius: 2,
elevation: 5,
},
image: {
width: 40,
height: 40,
},
I’ve tried adding zIndex: 2
to the image container and then zIndex: 1
to the parents parent but it didn’t work..
Can’t find much online to solve this problem as most queries related to ‘overflow’ are requesting the opposite effect.
Any help would be much appreciated!
2
Answers
Manage to get the desired effect by wrapping the
container
that usesoverflow: 'hidden'
inside an outer container and then moving theimageContainer
out of thecontainer
and into the outer container giving itzIndex: 1
and keeping it absolutely positioned as well as giving italignSelf: 'center'
Like so:
Credit to this answer: https://stackoverflow.com/a/67140055/13740590
In iOS you can play with the zIndex
You can create a prop or a state that tells you which one is active.
For instance,
In customcomp, you can set the parent style such as
Make sure you have assign the zIndex to the container view