I only have 1 image that needs a zIndex
to show it in front. It works on Android but it doesn't show up in IOS devices. Not sure why.
Here is the picture for Android:
Here is the picture for IOS:
As you can see, the user image doesn't appear in IOS.
Code is like this:
<View>
<Image
source={require("./images/user-img.png")}
style={{width:95,height:95,marginTop:10,marginLeft:135,position:'absolute',zIndex:1}}
/>
<ImageBackground
source={require("./images/bg-img.png")}
style={{ width: "100%", height: "100%"}}>
<View>
//extra code here
</View>
</ImageBackground>
</View>
Anyone know the reason?
To use z-index in React Native, we can use the zIndex style. to add 2 View s that has different zIndex values. The component with the higher zIndex value is laid over the component with the lower zIndex value. So the green square goes on top of the red square.
Introduction of React Native zIndex. To specify the stack order of an element, zIndex is used. The element which has a greater stack order is positioned in front of the element which has a low stack order. Z-index always works on the elements which are positioned as absolute, sticky, fixed and relative.
The zIndex is used to specify the stack order of an element in react native applications. The elements can be placed in front of the other elements by giving them the higher value of the zIndex . If we want to display an element between 2 elements, we can assign a larger zIndex value.
Please add zindex to parent view. In iOS, the zIndex doesn't work for nested parentView. You need to make the parentView has high zIndex, and then target View again.
<View style={{zIndex: 10}}>
<Image
source={require("./images/user-img.png")}
style={{width:95,height:95,marginTop:10,marginLeft:135,position:'absolute',zIndex:20}}
/>
<ImageBackground
source={require("./images/bg-img.png")}
style={{ width: "100%", height: "100%"}}>
<View>
//extra code here
</View>
</ImageBackground>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With